Skip to content

Commit

Permalink
Merge pull request #26780 from Dr15Jones/enforceESInputTagLabels
Browse files Browse the repository at this point in the history
Enforce ESInputTag label separation
  • Loading branch information
cmsbuild committed May 21, 2019
2 parents a6b913f + 5a55b09 commit 9d1566e
Show file tree
Hide file tree
Showing 36 changed files with 104 additions and 76 deletions.
4 changes: 2 additions & 2 deletions DetectorDescription/DDCMS/plugins/DDCMSDetector.cc
Expand Up @@ -39,7 +39,7 @@ void
DDCMSDetector::analyze(const Event&, const EventSetup& iEventSetup)
{
ESTransientHandle<DDDetector> det;
iEventSetup.get<GeometryFileRcd>().get(m_tag.module(), det);
iEventSetup.get<GeometryFileRcd>().get(m_tag, det);

LogVerbatim("Geometry") << "Iterate over the detectors:\n";
LogVerbatim("Geometry").log([&](auto& log) {
Expand All @@ -51,7 +51,7 @@ DDCMSDetector::analyze(const Event&, const EventSetup& iEventSetup)
LogVerbatim("Geometry") << "..done!";

ESTransientHandle<DDVectorRegistry> registry;
iEventSetup.get<DDVectorRegistryRcd>().get(m_tag.module(), registry);
iEventSetup.get<DDVectorRegistryRcd>().get(m_tag, registry);

LogVerbatim("Geometry") << "DD Vector Registry size: " << registry->vectors.size();
LogVerbatim("Geometry").log([&](auto& log) {
Expand Down
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/plugins/DDTestDumpFile.cc
Expand Up @@ -45,7 +45,7 @@ DDTestDumpFile::analyze(const Event&, const EventSetup& iEventSetup)
{
LogVerbatim("Geometry") << "DDTestDumpFile::analyze: " << m_label;
ESTransientHandle<DDDetector> det;
iEventSetup.get<GeometryFileRcd>().get(m_label.module(), det);
iEventSetup.get<GeometryFileRcd>().get(m_label, det);

TGeoManager& geom = det->description()->manager();

Expand Down
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/plugins/DDTestDumpGeometry.cc
Expand Up @@ -40,7 +40,7 @@ DDTestDumpGeometry::analyze(const Event&, const EventSetup& iEventSetup)
{
LogVerbatim("Geometry") << "DDTestDumpGeometry::analyze: " << m_tag;
ESTransientHandle<DDDetector> det;
iEventSetup.get<GeometryFileRcd>().get(m_tag.module(), det);
iEventSetup.get<GeometryFileRcd>().get(m_tag, det);

TGeoManager const& geom = det->description()->manager();

Expand Down
4 changes: 2 additions & 2 deletions DetectorDescription/DDCMS/plugins/DDTestNavigateGeometry.cc
Expand Up @@ -49,7 +49,7 @@ DDTestNavigateGeometry::analyze(const Event&, const EventSetup& iEventSetup)

const DDVectorRegistryRcd& regRecord = iEventSetup.get<DDVectorRegistryRcd>();
ESTransientHandle<DDVectorRegistry> reg;
regRecord.get(m_tag.module(), reg);
regRecord.get(m_tag, reg);

LogVerbatim("Geometry").log([&reg](auto& log) {
for(const auto& p: reg->vectors) {
Expand All @@ -61,7 +61,7 @@ DDTestNavigateGeometry::analyze(const Event&, const EventSetup& iEventSetup)

const GeometryFileRcd& ddRecord = iEventSetup.get<GeometryFileRcd>();
ESTransientHandle<DDDetector> ddd;
ddRecord.get(m_tag.module(), ddd);
ddRecord.get(m_tag, ddd);

const dd4hep::Detector& detector = *ddd->description();

Expand Down
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/plugins/DDTestSpecPars.cc
Expand Up @@ -30,7 +30,7 @@ DDTestSpecPars::analyze(const Event&, const EventSetup& iEventSetup)
{
LogVerbatim("Geometry") << "DDTestSpecPars::analyze: " << m_tag;
ESTransientHandle<DDSpecParRegistry> registry;
iEventSetup.get<DDSpecParRegistryRcd>().get(m_tag.module(), registry);
iEventSetup.get<DDSpecParRegistryRcd>().get(m_tag, registry);

LogVerbatim("Geometry").log([&registry](auto& log) {
log << "DD SpecPar Registry size: " << registry->specpars.size();
Expand Down
4 changes: 2 additions & 2 deletions DetectorDescription/DDCMS/plugins/DDTestSpecParsFilter.cc
Expand Up @@ -35,9 +35,9 @@ DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup)
{
LogVerbatim("Geometry") << "DDTestSpecParsFilter::analyze: " << m_tag;
ESTransientHandle<DDSpecParRegistry> registry;
iEventSetup.get<DDSpecParRegistryRcd>().get(m_tag.module(), registry);
iEventSetup.get<DDSpecParRegistryRcd>().get(m_tag, registry);

LogVerbatim("Geometry") << "DDTestSpecParsFilter::analyze: " << m_tag.module()
LogVerbatim("Geometry") << "DDTestSpecParsFilter::analyze: " << m_tag
<< " for attribute " << m_attribute << " and value " << m_value;
LogVerbatim("Geometry") << "DD SpecPar Registry size: " << registry->specpars.size();

Expand Down
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/plugins/DDTestVectors.cc
Expand Up @@ -31,7 +31,7 @@ DDTestVectors::analyze( const Event&, const EventSetup& iEventSetup)
{
LogVerbatim("Geometry") << "DDTestVectors::analyze: " << m_tag;
ESTransientHandle<DDVectorRegistry> registry;
iEventSetup.get<DDVectorRegistryRcd>().get(m_tag.module(), registry);
iEventSetup.get<DDVectorRegistryRcd>().get(m_tag, registry);

LogVerbatim("Geometry").log([&registry](auto& log) {
log << "DD Vector Registry size: " << registry->vectors.size();
Expand Down
6 changes: 3 additions & 3 deletions DetectorDescription/DDCMS/test/python/dump.py
Expand Up @@ -17,15 +17,15 @@
)

process.test = cms.EDAnalyzer("DDCMSDetector",
DDDetector = cms.ESInputTag('CMS')
DDDetector = cms.ESInputTag('','CMS')
)

process.testVectors = cms.EDAnalyzer("DDTestVectors",
DDDetector = cms.ESInputTag('CMS')
DDDetector = cms.ESInputTag('','CMS')
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('CMS')
DDDetector = cms.ESInputTag('','CMS')
)

process.p = cms.Path(process.test+process.testVectors+process.testDump)
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/test/python/dumpMuonGeometry.py
Expand Up @@ -13,7 +13,7 @@
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('MUON')
DDDetector = cms.ESInputTag('','MUON')
)

process.p = cms.Path(process.testDump)
Expand Up @@ -13,7 +13,7 @@
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('TestAngular')
DDDetector = cms.ESInputTag('','TestAngular')
)

process.p = cms.Path(process.testDump)
Expand Up @@ -48,7 +48,7 @@
)

process.test = cms.EDAnalyzer("DDTestNavigateGeometry",
DDDetector = cms.ESInputTag('MUON'),
DDDetector = cms.ESInputTag('','MUON'),
detElementPath = cms.string(''),
placedVolumePath = cms.string('/world_volume_1/OCMS_1/CMSE_1/MUON_1')
)
Expand Down
Expand Up @@ -18,7 +18,7 @@
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('TestDDHGCalCell')
DDDetector = cms.ESInputTag('','TestDDHGCalCell')
)

process.p = cms.Path(process.testDump)
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/test/python/testDDSpecPars.py
Expand Up @@ -48,7 +48,7 @@
)

process.test = cms.EDAnalyzer("DDTestSpecPars",
DDDetector = cms.ESInputTag('MUON')
DDDetector = cms.ESInputTag('','MUON')
)

process.p = cms.Path(process.test)
Expand Up @@ -47,7 +47,7 @@
)

process.test = cms.EDAnalyzer("DDTestSpecParsFilter",
DDDetector = cms.ESInputTag('MUON'),
DDDetector = cms.ESInputTag('','MUON'),
attribute = cms.untracked.string('MuStructure'),
value = cms.untracked.string('MuonBarrelDT')
)
Expand Down
Expand Up @@ -48,7 +48,7 @@
)

process.test = cms.EDAnalyzer("DDTestSpecParsFilter",
DDDetector = cms.ESInputTag('MUON'),
DDDetector = cms.ESInputTag('','MUON'),
attribute = cms.untracked.string('CMSCutsRegion'),
value = cms.untracked.string('Muon')
)
Expand Down
Expand Up @@ -45,7 +45,7 @@
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('TestTIDAxialCable')
DDDetector = cms.ESInputTag('','TestTIDAxialCable')
)

process.p = cms.Path(process.testDump)
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/test/python/testDDVectors.py
Expand Up @@ -16,7 +16,7 @@
appendToDataLabel = cms.string('CMS'))

process.test = cms.EDAnalyzer("DDTestVectors",
DDDetector = cms.ESInputTag('CMS')
DDDetector = cms.ESInputTag('','CMS')
)

process.p = cms.Path(process.test)
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/test/python/testMFGeometry.py
Expand Up @@ -13,7 +13,7 @@
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('MagneticField')
DDDetector = cms.ESInputTag('','MagneticField')
)

process.p = cms.Path(process.testDump)
8 changes: 4 additions & 4 deletions DetectorDescription/DDCMS/test/python/testMuonGeometry.py
Expand Up @@ -24,25 +24,25 @@
)

process.test = cms.EDAnalyzer("DDCMSDetector",
DDDetector = cms.ESInputTag('CMS')
DDDetector = cms.ESInputTag('','CMS')
)

process.DDVectorRegistryESProducer2 = cms.ESProducer("DDVectorRegistryESProducer",
appendToDataLabel = cms.string('MagneticField')
)

process.test2 = cms.EDAnalyzer("DDCMSDetector",
DDDetector = cms.ESInputTag('MagneticField')
DDDetector = cms.ESInputTag('','MagneticField')
)

process.testVectors = cms.EDAnalyzer("DDTestVectors",
DDDetector = cms.ESInputTag('CMS')
DDDetector = cms.ESInputTag('','CMS')
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile")

process.testGeoIter = cms.EDAnalyzer("DDTestDumpGeometry",
DDDetector = cms.ESInputTag('CMS')
DDDetector = cms.ESInputTag('','CMS')
)

process.p = cms.Path(
Expand Down
Expand Up @@ -46,7 +46,7 @@
appendToDataLabel = cms.string('MUON'))

process.test = cms.EDAnalyzer("DDTestNavigateGeometry",
DDDetector = cms.ESInputTag('MUON'),
DDDetector = cms.ESInputTag('','MUON'),
detElementPath = cms.string('detElementPath'),
placedVolumePath = cms.string('placedVolPath')
)
Expand Down
6 changes: 3 additions & 3 deletions DetectorDescription/DDCMS/test/python/testShapes.py
Expand Up @@ -17,15 +17,15 @@
)

process.test = cms.EDAnalyzer("DDCMSDetector",
DDDetector = cms.ESInputTag('TestShapes')
DDDetector = cms.ESInputTag('','TestShapes')
)

process.testVectors = cms.EDAnalyzer("DDTestVectors",
DDDetector = cms.ESInputTag('TestShapes')
DDDetector = cms.ESInputTag('','TestShapes')
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('TestShapes')
DDDetector = cms.ESInputTag('','TestShapes')
)

process.p = cms.Path(process.test+process.testVectors+process.testDump)
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/test/python/testTGeoIterator.py
Expand Up @@ -43,7 +43,7 @@
appendToDataLabel = cms.string('CMS')
)
process.test = cms.EDAnalyzer("DDTestDumpGeometry",
DDDetector = cms.ESInputTag('CMS')
DDDetector = cms.ESInputTag('','CMS')
)

process.p = cms.Path(process.test)
46 changes: 24 additions & 22 deletions FWCore/ParameterSet/python/Types.py
Expand Up @@ -541,7 +541,7 @@ def insertInto(self, parameterSet, myname):
parameterSet.addInputTag(self.isTracked(), myname, self.cppTag(parameterSet))

class ESInputTag(_ParameterTypeBase):
def __init__(self,module='',data=''):
def __init__(self,module='',data= None):
super(ESInputTag,self).__init__()
self._setValues(module, data)
def getModuleLabel(self):
Expand All @@ -559,9 +559,7 @@ def setDataLabel(self,label):
self._isModified=True
dataLabel = property(getDataLabel,setDataLabel,"data label for the product")
def configValue(self, options=PrintOptions()):
result = self.__moduleLabel
if self.__data != "":
result += ':' + self.__data
result = self.__moduleLabel + ':' + self.__data
if result == "":
result = '\"\"'
return result;
Expand Down Expand Up @@ -601,18 +599,22 @@ def _valueFromString(string):
def setValue(self,v):
self._setValues(v)
self._isModified=True
def _setValues(self,moduleLabel='',dataLabel=''):
def _setValues(self,moduleLabel='',dataLabel=None):
self.__moduleLabel = moduleLabel
self.__data = dataLabel
if -1 != moduleLabel.find(":"):
# raise RuntimeError("the module label '"+str(moduleLabel)+"' contains a ':'. If you want to specify more than one label, please pass them as separate arguments.")
# tolerate it, at least for the translation phase
toks = moduleLabel.split(":")
self.__moduleLabel = toks[0]
if len(toks) > 1:
self.__data = toks[1]
if len(toks) > 2:
raise RuntimeError("an ESInputTag was passed the value'"+moduleLabel+"' which contains more than one ':'")
if dataLabel is None:
if moduleLabel:
if -1 == moduleLabel.find(":"):
raise RuntimeError("ESInputTag passed one string '"+str(moduleLabel)+"' which does not contain a ':'. Please add ':' to explicitly separate the module (1st) and data (2nd) label or use two strings.")
toks = moduleLabel.split(":")
self.__moduleLabel = toks[0]
if len(toks) > 1:
self.__data = toks[1]
if len(toks) > 2:
raise RuntimeError("an ESInputTag was passed the value'"+moduleLabel+"' which contains more than one ':'")
else:
self.__data = ''


# convert to the wrapper class for C++ ESInputTags
def cppTag(self, parameterSet):
Expand Down Expand Up @@ -1408,10 +1410,10 @@ def testESInputTag(self):
self.assertEqual(it.getModuleLabel(), "")
self.assertEqual(it.getDataLabel(), "data")
self.assertEqual(repr(it), "cms.ESInputTag(\"\",\"data\")")
vit = VESInputTag(ESInputTag("label1"), ESInputTag("label2"))
self.assertEqual(repr(vit), "cms.VESInputTag(cms.ESInputTag(\"label1\"), cms.ESInputTag(\"label2\"))")
vit = VESInputTag("label1", "label2:label3")
self.assertEqual(repr(vit), "cms.VESInputTag(\"label1\", \"label2:label3\")")
vit = VESInputTag(ESInputTag("label1:"), ESInputTag("label2:"))
self.assertEqual(repr(vit), 'cms.VESInputTag(cms.ESInputTag("label1",""), cms.ESInputTag("label2",""))')
vit = VESInputTag("label1:", "label2:label3")
self.assertEqual(repr(vit), "cms.VESInputTag(\"label1:\", \"label2:label3\")")

def testPSet(self):
p1 = PSet(anInt = int32(1), a = PSet(b = int32(1)))
Expand Down Expand Up @@ -1557,8 +1559,8 @@ def testVLuminosityBlockRange(self):

def testPSetConversion(self):
p = PSet(a = untracked.int32(7),
b = untracked.InputTag("b"),
c = untracked.ESInputTag("c"),
b = untracked.InputTag("b:"),
c = untracked.ESInputTag("c:"),
d = EventID(1,1,1),
e = LuminosityBlockID(1,1),
f = EventRange(1,1,1,8,8,8),
Expand All @@ -1571,8 +1573,8 @@ def testPSetConversion(self):
m = untracked.double(7.0),
n = FileInPath("xxx"),
o = untracked.vint32(7,8),
p = untracked.VInputTag(InputTag("b"),InputTag("c")),
q = untracked.VESInputTag(ESInputTag("c"),ESInputTag("d")),
p = untracked.VInputTag(InputTag("b:"),InputTag("c:")),
q = untracked.VESInputTag(ESInputTag("c:"),ESInputTag("d:")),
r = untracked.VEventID(EventID(1,1,1),EventID(2,2,2)),
s = untracked.VLuminosityBlockID(LuminosityBlockID(1,1),LuminosityBlockID(2,3)),
t = untracked.VEventRange(EventRange(1,1,1,8,8,8), EventRange(9,9,9,18,18,18)),
Expand Down
9 changes: 8 additions & 1 deletion FWCore/ParameterSet/src/types.cc
Expand Up @@ -627,12 +627,19 @@ bool edm::encode(std::string& to, std::vector<InputTag> const& from) {
// ----------------------------------------------------------------------

bool edm::decode(ESInputTag& to, std::string const& from) {
to = ESInputTag(from);
if (not from.empty() and std::string::npos == from.find(':')) {
to = ESInputTag(from, "");
} else {
to = ESInputTag(from);
}
return true;
} // decode to InputTag

bool edm::encode(std::string& to, ESInputTag const& from) {
to = from.encode();
if (not to.empty() and to.back() == ':') {
to.pop_back();
}
return true;
}

Expand Down
16 changes: 16 additions & 0 deletions FWCore/ParameterSet/test/ps_t.cppunit.cc
Expand Up @@ -291,6 +291,22 @@ void testps::idTest() {

CPPUNIT_ASSERT(a != b);
CPPUNIT_ASSERT(a.id() != b.id());

{
//Check that changes to ESInputTag do not affect ID
// as that would affect reading back stored PSets

edm::ParameterSet ps;
ps.addParameter<edm::ESInputTag>("default", edm::ESInputTag());
ps.addParameter<edm::ESInputTag>("moduleOnly", edm::ESInputTag("Prod", ""));
ps.addParameter<edm::ESInputTag>("dataOnly", edm::ESInputTag("", "data"));
ps.addParameter<edm::ESInputTag>("allLabels", edm::ESInputTag("Prod", "data"));
ps.registerIt();

std::string stringValue;
ps.id().toString(stringValue);
CPPUNIT_ASSERT(stringValue == "01642a9a7311dea2df2f9ee430855a99");
}
}

void testps::calculateIDTest() {
Expand Down

0 comments on commit 9d1566e

Please sign in to comment.