def generateGeom(self, detectorTuple, args): detectorVersion = self.detectorPrefix + str(args.detectorVersionManual) # reverse dict search if overall D# specified if args.v_detector != self.detectorVersionNull: detectorVersion = self.detectorPrefix + str(args.v_detector) if detectorVersion in self.detectorVersionDict.values(): detectorTuple = list(self.detectorVersionDict.keys())[list( self.detectorVersionDict.values()).index(detectorVersion)] else: print("Unknown detector " + detectorVersion) sys.exit(1) elif detectorTuple in self.detectorVersionDict.keys(): detectorVersion = self.detectorVersionDict[detectorTuple] else: if not args.doTest: print("Detector " + str(detectorTuple) + " not found in dictionary, using " + ("default" if args.detectorVersionManual == self.detectorVersionDefault else "provided") + " version number " + str(detectorVersion)) # check for deprecation if self.deprecatedDets is not None and detectorVersion in self.deprecatedDets: print("Error: " + detectorVersion + " is deprecated and cannot be used.") sys.exit(1) if self.deprecatedSubdets is not None: for subdet in detectorTuple: if subdet in self.deprecatedSubdets: print("Error: " + subdet + " is deprecated and cannot be used.") sys.exit(1) # create output files xmlName = "cmsExtendedGeometry" + self.detectorYear + detectorVersion + "XML_cfi.py" xmlDD4hepName = "cmsExtendedGeometry" + self.detectorYear + detectorVersion + ".xml" simName = "GeometryExtended" + self.detectorYear + detectorVersion + "_cff.py" simDD4hepName = "GeometryDD4hepExtended" + self.detectorYear + detectorVersion + "_cff.py" recoName = "GeometryExtended" + self.detectorYear + detectorVersion + "Reco_cff.py" recoDD4hepName = "GeometryDD4hepExtended" + self.detectorYear + detectorVersion + "Reco_cff.py" # check directories CMSSWBASE = os.getenv("CMSSW_BASE") CMSSWRELBASE = os.getenv("CMSSW_RELEASE_BASE") if CMSSWBASE is None: CMSSWBASE = "" xmlDir = os.path.join(CMSSWBASE, "src", "Geometry", "CMSCommonData", "python") xmlDD4hepDir = os.path.join(CMSSWBASE, "src", "Geometry", "CMSCommonData", "data", "dd4hep") simrecoDir = os.path.join(CMSSWBASE, "src", "Configuration", "Geometry", "python") simrecoDD4hepDir = os.path.join(CMSSWBASE, "src", "Configuration", "Geometry", "python") if args.doTest: if not os.path.isdir(xmlDir): xmlDir = os.path.join(CMSSWRELBASE, "src", "Geometry", "CMSCommonData", "python") xmlDD4hepDir = os.path.join(CMSSWRELBASE, "src", "Geometry", "CMSCommonData", "data", "dd4hep") else: mvCommands = "" if not os.path.isdir(xmlDir): mvCommands += "mv " + xmlName + " " + xmlDir + "/\n" else: xmlName = os.path.join(xmlDir, xmlName) if not os.path.isdir(xmlDD4hepDir): mvCommands += "mv " + xmlDD4hepName + " " + xmlDD4hepDir + "/\n" else: xmlDD4hepName = os.path.join(xmlDD4hepDir, xmlDD4hepName) if not os.path.isdir(simrecoDir): mvCommands += "mv " + simName + " " + simrecoDir + "/\n" mvCommands += "mv " + recoName + " " + simrecoDir + "/\n" else: simName = os.path.join(simrecoDir, simName) recoName = os.path.join(simrecoDir, recoName) if not os.path.isdir(simrecoDD4hepDir): mvCommands += "mv " + simDD4hepName + " " + simrecoDD4hepDir + "/\n" mvCommands += "mv " + recoDD4hepName + " " + simrecoDD4hepDir + "/\n" else: simDD4hepName = os.path.join(simrecoDD4hepDir, simDD4hepName) recoDD4hepName = os.path.join(simrecoDD4hepDir, recoDD4hepName) if len(mvCommands) > 0: print( "Warning: some geometry packages not checked out.\nOnce they are available, please execute the following commands manually:\n" + mvCommands) # open files xmlFile = open(xmlName, 'w') xmlDD4hepFile = open(xmlDD4hepName, 'w') simFile = open(simName, 'w') simDD4hepFile = open(simDD4hepName, 'w') recoFile = open(recoName, 'w') recoDD4hepFile = open(recoDD4hepName, 'w') # common preamble preamble = "import FWCore.ParameterSet.Config as cms" + "\n" + "\n" preamble += "# This config was generated automatically using " + self.scriptName + "\n" preamble += "# If you notice a mistake, please update the generating script, not just this config" + "\n" + "\n" # create XML config xmlFile.write(preamble) # extra preamble xmlFile.write( "XMLIdealGeometryESSource = cms.ESSource(\"XMLIdealGeometryESSource\"," + "\n") xmlFile.write(" geomXMLFiles = cms.vstring(" + "\n") for section in range(1, self.maxSections + 1): # midamble if section == 2: xmlFile.write(" )+" + "\n" + " cms.vstring(" + "\n") for iDict, aDict in enumerate(self.allDicts): if section in aDict[detectorTuple[iDict]].keys(): xmlFile.write('\n'.join([ " '" + aLine + "'," for aLine in aDict[detectorTuple[iDict]][section] ]) + "\n") # postamble xmlFile.write(" )," + "\n" + " rootNodeName = cms.string('cms:OCMS')" + "\n" + ")" + "\n") xmlFile.close() # create DD4hep XML config xmlDD4hepFile.write("<?xml version=\"1.0\"?>\n" + "<DDDefinition>\n" + " <open_geometry/>\n" + " <close_geometry/>\n" + "\n" + " <IncludeSection>\n") for section in range(1, self.maxSections + 1): # midamble for iDict, aDict in enumerate(self.allDicts): if section in aDict[detectorTuple[iDict]].keys(): xmlDD4hepFile.write('\n'.join([ " <Include ref='" + aLine + "'/>" for aLine in aDict[detectorTuple[iDict]][section] ]) + "\n") # postamble xmlDD4hepFile.write(" </IncludeSection>\n" + "</DDDefinition>" + "\n") xmlDD4hepFile.close() # create sim config simFile.write(preamble) # always need XML simFile.write("from Geometry.CMSCommonData." + os.path.basename(xmlName).replace(".py", "") + " import *" + "\n") for iDict, aDict in enumerate(self.allDicts): if "sim" in aDict[detectorTuple[iDict]].keys(): simFile.write('\n'.join( [aLine for aLine in aDict[detectorTuple[iDict]]["sim"]]) + "\n") simFile.close() # create simDD4hep config simDD4hepFile.write(preamble) # always need XML simDD4hepFile.write("from Configuration.Geometry.GeometryDD4hep_cff" + " import *" + "\n") simDD4hepFile.write( "DDDetectorESProducer.confGeomXMLFiles = cms.FileInPath(\"Geometry/CMSCommonData/data/dd4hep/" + os.path.basename(xmlDD4hepName) + "\")\n\n") for iDict, aDict in enumerate(self.allDicts): if "sim" in aDict[detectorTuple[iDict]].keys(): simDD4hepFile.write('\n'.join( [aLine for aLine in aDict[detectorTuple[iDict]]["sim"]]) + "\n") simDD4hepFile.close() # create reco config recoFile.write(preamble) # always need sim recoFile.write("from Configuration.Geometry." + os.path.basename(simName).replace(".py", "") + " import *" + "\n\n") for iDict, aDict in enumerate(self.allDicts): if "reco" in aDict[detectorTuple[iDict]].keys(): recoFile.write("# " + aDict["name"] + "\n") recoFile.write('\n'.join( [aLine for aLine in aDict[detectorTuple[iDict]]["reco"]]) + "\n\n") recoFile.close() # create recoDD4hep config recoDD4hepFile.write(preamble) # always need sim recoDD4hepFile.write( "from Configuration.Geometry." + os.path.basename(simDD4hepName).replace(".py", "") + " import *" + "\n\n") for iDict, aDict in enumerate(self.allDicts): if "reco" in aDict[detectorTuple[iDict]].keys(): recoDD4hepFile.write("# " + aDict["name"] + "\n") recoDD4hepFile.write('\n'.join( [aLine for aLine in aDict[detectorTuple[iDict]]["reco"]]) + "\n\n") recoDD4hepFile.close() from Configuration.StandardSequences.GeometryConf import GeometryConf if not args.doTest: # todo: include these in unit test somehow # specify Era customizations # must be checked manually in: # Configuration/StandardSequences/python/Eras.py # Configuration/Eras/python/ # Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py (workflow definitions) eraLine = "" eraLineItems = [] for iDict, aDict in enumerate(self.allDicts): if "era" in aDict[detectorTuple[iDict]].keys(): eraLineItems.append(aDict[detectorTuple[iDict]]["era"]) eraLine += ", ".join([eraLineItem for eraLineItem in eraLineItems]) print("The Era for this detector should contain:") print(eraLine) # specify GeometryConf if not 'Extended' + self.detectorYear + detectorVersion in GeometryConf.keys( ): print( "Please add this line in Configuration/StandardSequences/python/GeometryConf.py:" ) print(" 'Extended" + self.detectorYear + detectorVersion + "' : 'Extended" + self.detectorYear + detectorVersion + ",Extended" + self.detectorYear + detectorVersion + "Reco',") errorList = [] if args.doTest: # tests for Configuration/Geometry simFile = os.path.join(simrecoDir, simName) if not os.path.isfile(simFile): errorList.append(simName + " missing") elif not filecmp.cmp(simName, simFile): errorList.append(simName + " differs") simDD4hepFile = os.path.join(simrecoDD4hepDir, simDD4hepName) if not os.path.isfile(simDD4hepFile): errorList.append(simDD4hepName + " missing") elif not filecmp.cmp(simDD4hepName, simDD4hepFile): errorList.append(simDD4hepName + " differs") recoFile = os.path.join(simrecoDir, recoName) if not os.path.isfile(recoFile): errorList.append(recoName + " missing") elif not filecmp.cmp(recoName, recoFile): errorList.append(recoName + " differs") recoDD4hepFile = os.path.join(simrecoDD4hepDir, recoDD4hepName) if not os.path.isfile(recoDD4hepFile): errorList.append(recoDD4hepName + " missing") elif not filecmp.cmp(recoDD4hepName, recoDD4hepFile): errorList.append(recoDD4hepName + " differs") # test for Configuration/StandardSequences if not 'Extended' + self.detectorYear + detectorVersion in GeometryConf.keys( ): errorList.append('Extended' + self.detectorYear + detectorVersion + " missing from GeometryConf") # test for Geometry/CMSCommonData xmlFile = os.path.join(xmlDir, xmlName) if not os.path.isfile(xmlFile): errorList.append(xmlName + " missing") elif not filecmp.cmp(xmlName, xmlFile): errorList.append(xmlName + " differs") # test for dd4hep xml xmlDD4hepFile = os.path.join(xmlDD4hepDir, xmlDD4hepName) if not os.path.exists(xmlDD4hepFile): errorList.append(xmlDD4hepName + " differs") elif not filecmp.cmp(xmlDD4hepName, xmlDD4hepFile): errorList.append(xmlDD4hepName + " differs") return errorList
def generateGeom(detectorTuple, options): doTest = bool(options.doTest) detectorVersion = "D" + str(options.detectorVersionManual) # reverse dict search if overall D# specified if options.v_detector > 0: detectorVersion = "D" + str(options.v_detector) if detectorVersion in detectorVersionDict.values(): detectorTuple = detectorVersionDict.keys()[ detectorVersionDict.values().index(detectorVersion)] else: print "Unknown detector " + detectorVersion sys.exit(1) elif detectorTuple in detectorVersionDict.keys(): detectorVersion = detectorVersionDict[detectorTuple] else: if not doTest: print "Detector " + str( detectorTuple) + " not found in dictionary, using " + ( "default" if options.detectorVersionManual == detectorVersionDefault else "provided") + " version number " + str(detectorVersion) # check for deprecation if detectorVersion in deprecatedDets: print "Error: " + detectorVersion + " is deprecated and cannot be used." sys.exit(1) for subdet in detectorTuple: if subdet in deprecatedSubdets: print "Error: " + subdet + " is deprecated and cannot be used." sys.exit(1) # create output files xmlName = "cmsExtendedGeometry2023" + detectorVersion + "XML_cfi.py" simName = "GeometryExtended2023" + detectorVersion + "_cff.py" recoName = "GeometryExtended2023" + detectorVersion + "Reco_cff.py" # check directories CMSSWBASE = os.getenv("CMSSW_BASE") CMSSWRELBASE = os.getenv("CMSSW_RELEASE_BASE") if CMSSWBASE is None: CMSSWBASE = "" xmlDir = os.path.join(CMSSWBASE, "src", "Geometry", "CMSCommonData", "python") simrecoDir = os.path.join(CMSSWBASE, "src", "Configuration", "Geometry", "python") if doTest: if not os.path.isdir(xmlDir): xmlDir = os.path.join(CMSSWRELBASE, "src", "Geometry", "CMSCommonData", "python") else: mvCommands = "" if not os.path.isdir(xmlDir): mvCommands += "mv " + xmlName + " " + xmlDir + "/\n" else: xmlName = os.path.join(xmlDir, xmlName) if not os.path.isdir(simrecoDir): mvCommands += "mv " + simName + " " + simrecoDir + "/\n" mvCommands += "mv " + recoName + " " + simrecoDir + "/\n" else: simName = os.path.join(simrecoDir, simName) recoName = os.path.join(simrecoDir, recoName) if len(mvCommands) > 0: print "Warning: some geometry packages not checked out.\nOnce they are available, please execute the following commands manually:\n" + mvCommands # open files xmlFile = open(xmlName, 'w') simFile = open(simName, 'w') recoFile = open(recoName, 'w') # common preamble preamble = "import FWCore.ParameterSet.Config as cms" + "\n" + "\n" preamble += "# This config was generated automatically using generate2023Geometry.py" + "\n" preamble += "# If you notice a mistake, please update the generating script, not just this config" + "\n" + "\n" # create XML config xmlFile.write(preamble) # extra preamble xmlFile.write( "XMLIdealGeometryESSource = cms.ESSource(\"XMLIdealGeometryESSource\"," + "\n") xmlFile.write(" geomXMLFiles = cms.vstring(" + "\n") for section in range(1, maxsections + 1): # midamble if section == 2: xmlFile.write(" )+" + "\n" + " cms.vstring(" + "\n") for iDict, aDict in enumerate(allDicts): if section in aDict[detectorTuple[iDict]].keys(): xmlFile.write('\n'.join([ " '" + aLine + "'," for aLine in aDict[detectorTuple[iDict]][section] ]) + "\n") # postamble xmlFile.write(" )," + "\n" + " rootNodeName = cms.string('cms:OCMS')" + "\n" + ")" + "\n") xmlFile.close() # create sim config simFile.write(preamble) # always need XML simFile.write("from Geometry.CMSCommonData." + os.path.basename(xmlName).replace(".py", "") + " import *" + "\n") for iDict, aDict in enumerate(allDicts): if "sim" in aDict[detectorTuple[iDict]].keys(): simFile.write('\n'.join( [aLine for aLine in aDict[detectorTuple[iDict]]["sim"]]) + "\n") simFile.close() # create reco config recoFile.write(preamble) # always need sim recoFile.write("from Configuration.Geometry." + os.path.basename(simName).replace(".py", "") + " import *" + "\n\n") for iDict, aDict in enumerate(allDicts): if "reco" in aDict[detectorTuple[iDict]].keys(): recoFile.write("# " + aDict["name"] + "\n") recoFile.write('\n'.join( [aLine for aLine in aDict[detectorTuple[iDict]]["reco"]]) + "\n\n") recoFile.close() from Configuration.StandardSequences.GeometryConf import GeometryConf if not doTest: # todo: include these in unit test somehow # specify Era customizations # must be checked manually in: # Configuration/StandardSequences/python/Eras.py # Configuration/Eras/python/ # Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py (workflow definitions) eraLine = "" eraLineItems = [] for iDict, aDict in enumerate(allDicts): if "era" in aDict[detectorTuple[iDict]].keys(): eraLineItems.append(aDict[detectorTuple[iDict]]["era"]) eraLine += ", ".join([eraLineItem for eraLineItem in eraLineItems]) print "The Era for this detector should contain:" print eraLine # specify GeometryConf if not 'Extended2023' + detectorVersion in GeometryConf.keys(): print "Please add this line in Configuration/StandardSequences/python/GeometryConf.py:" print " 'Extended2023" + detectorVersion + "' : 'Extended2023" + detectorVersion + ",Extended2023" + detectorVersion + "Reco'," errorList = [] if doTest: # tests for Configuration/Geometry if not filecmp.cmp(simName, os.path.join(simrecoDir, simName)): errorList.append(simName + " differs") if not filecmp.cmp(recoName, os.path.join(simrecoDir, recoName)): errorList.append(recoName + " differs") # test for Configuration/StandardSequences if not 'Extended2023' + detectorVersion in GeometryConf.keys(): errorList.append('Extended2023' + detectorVersion + " missing from GeometryConf") # test for Geometry/CMSCommonData if not filecmp.cmp(xmlName, os.path.join(xmlDir, xmlName)): errorList.append(xmlName + " differs") return errorList
def generateGeom(detectorTuple, options): doTest = bool(options.doTest) detectorVersion = "D"+str(options.detectorVersionManual) # reverse dict search if overall D# specified if options.v_detector>0: detectorVersion = "D"+str(options.v_detector) if detectorVersion in detectorVersionDict.values(): detectorTuple = detectorVersionDict.keys()[detectorVersionDict.values().index(detectorVersion)] else: print("Unknown detector "+detectorVersion) sys.exit(1) elif detectorTuple in detectorVersionDict.keys(): detectorVersion = detectorVersionDict[detectorTuple] else: if not doTest: print("Detector "+str(detectorTuple)+" not found in dictionary, using "+("default" if options.detectorVersionManual==detectorVersionDefault else "provided")+" version number "+str(detectorVersion)) # check for deprecation if detectorVersion in deprecatedDets: print("Error: "+detectorVersion+" is deprecated and cannot be used.") sys.exit(1) for subdet in detectorTuple: if subdet in deprecatedSubdets: print("Error: "+subdet+" is deprecated and cannot be used.") sys.exit(1) # create output files xmlName = "cmsExtendedGeometry2023"+detectorVersion+"XML_cfi.py" simName = "GeometryExtended2023"+detectorVersion+"_cff.py" recoName = "GeometryExtended2023"+detectorVersion+"Reco_cff.py" # check directories CMSSWBASE = os.getenv("CMSSW_BASE") CMSSWRELBASE = os.getenv("CMSSW_RELEASE_BASE") if CMSSWBASE is None: CMSSWBASE = "" xmlDir = os.path.join(CMSSWBASE,"src","Geometry","CMSCommonData","python") simrecoDir = os.path.join(CMSSWBASE,"src","Configuration","Geometry","python") if doTest: if not os.path.isdir(xmlDir): xmlDir = os.path.join(CMSSWRELBASE,"src","Geometry","CMSCommonData","python") else: mvCommands = "" if not os.path.isdir(xmlDir): mvCommands += "mv "+xmlName+" "+xmlDir+"/\n" else: xmlName = os.path.join(xmlDir,xmlName) if not os.path.isdir(simrecoDir): mvCommands += "mv "+simName+" "+simrecoDir+"/\n" mvCommands += "mv "+recoName+" "+simrecoDir+"/\n" else: simName = os.path.join(simrecoDir,simName) recoName = os.path.join(simrecoDir,recoName) if len(mvCommands)>0: print("Warning: some geometry packages not checked out.\nOnce they are available, please execute the following commands manually:\n"+mvCommands) # open files xmlFile = open(xmlName,'w') simFile = open(simName,'w') recoFile = open(recoName,'w') # common preamble preamble = "import FWCore.ParameterSet.Config as cms"+"\n"+"\n" preamble += "# This config was generated automatically using generate2023Geometry.py"+"\n" preamble += "# If you notice a mistake, please update the generating script, not just this config"+"\n"+"\n" # create XML config xmlFile.write(preamble) # extra preamble xmlFile.write("XMLIdealGeometryESSource = cms.ESSource(\"XMLIdealGeometryESSource\","+"\n") xmlFile.write(" geomXMLFiles = cms.vstring("+"\n") for section in range(1,maxsections+1): # midamble if section==2: xmlFile.write(" )+"+"\n"+" cms.vstring("+"\n") for iDict,aDict in enumerate(allDicts): if section in aDict[detectorTuple[iDict]].keys(): xmlFile.write('\n'.join([ " '"+aLine+"'," for aLine in aDict[detectorTuple[iDict]][section] ])+"\n") # postamble xmlFile.write(" ),"+"\n"+" rootNodeName = cms.string('cms:OCMS')"+"\n"+")"+"\n") xmlFile.close() # create sim config simFile.write(preamble) # always need XML simFile.write("from Geometry.CMSCommonData."+os.path.basename(xmlName).replace(".py","")+" import *"+"\n") for iDict,aDict in enumerate(allDicts): if "sim" in aDict[detectorTuple[iDict]].keys(): simFile.write('\n'.join([ aLine for aLine in aDict[detectorTuple[iDict]]["sim"] ])+"\n") simFile.close() # create reco config recoFile.write(preamble) # always need sim recoFile.write("from Configuration.Geometry."+os.path.basename(simName).replace(".py","")+" import *"+"\n\n") for iDict,aDict in enumerate(allDicts): if "reco" in aDict[detectorTuple[iDict]].keys(): recoFile.write("# "+aDict["name"]+"\n") recoFile.write('\n'.join([ aLine for aLine in aDict[detectorTuple[iDict]]["reco"] ])+"\n\n") recoFile.close() from Configuration.StandardSequences.GeometryConf import GeometryConf if not doTest: # todo: include these in unit test somehow # specify Era customizations # must be checked manually in: # Configuration/StandardSequences/python/Eras.py # Configuration/Eras/python/ # Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py (workflow definitions) eraLine = "" eraLineItems = [] for iDict,aDict in enumerate(allDicts): if "era" in aDict[detectorTuple[iDict]].keys(): eraLineItems.append(aDict[detectorTuple[iDict]]["era"]) eraLine += ", ".join([ eraLineItem for eraLineItem in eraLineItems ]) print("The Era for this detector should contain:") print(eraLine) # specify GeometryConf if not 'Extended2023'+detectorVersion in GeometryConf.keys(): print("Please add this line in Configuration/StandardSequences/python/GeometryConf.py:") print(" 'Extended2023"+detectorVersion+"' : 'Extended2023"+detectorVersion+",Extended2023"+detectorVersion+"Reco',") errorList = [] if doTest: # tests for Configuration/Geometry if not filecmp.cmp(simName,os.path.join(simrecoDir,simName)): errorList.append(simName+" differs"); if not filecmp.cmp(recoName,os.path.join(simrecoDir,recoName)): errorList.append(recoName+" differs"); # test for Configuration/StandardSequences if not 'Extended2023'+detectorVersion in GeometryConf.keys(): errorList.append('Extended2023'+detectorVersion+" missing from GeometryConf") # test for Geometry/CMSCommonData if not filecmp.cmp(xmlName,os.path.join(xmlDir,xmlName)): errorList.append(xmlName+" differs"); return errorList
os.path.basename(simName).replace(".py", "") + " import *" + "\n\n") for iDict, aDict in enumerate(allDicts): if "reco" in aDict[detectorTuple[iDict]].keys(): recoFile.write("# " + aDict["name"] + "\n") recoFile.write( '\n'.join([aLine for aLine in aDict[detectorTuple[iDict]]["reco"]]) + "\n\n") recoFile.close() # specify Era customizations # must be checked manually in: # Configuration/StandardSequences/python/Eras.py # Configuration/Eras/python/ # Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py (workflow definitions) eraLine = "" eraLineItems = [] for iDict, aDict in enumerate(allDicts): if "era" in aDict[detectorTuple[iDict]].keys(): eraLineItems.append(aDict[detectorTuple[iDict]]["era"]) eraLine += ", ".join([eraLineItem for eraLineItem in eraLineItems]) print "The Era for this detector should contain:" print eraLine # specify GeometryConf from Configuration.StandardSequences.GeometryConf import GeometryConf if not 'Extended2023' + detectorVersion in GeometryConf.keys(): print "Please add this line in Configuration/StandardSequences/python/GeometryConf.py:" print " 'Extended2023" + detectorVersion + "' : 'Extended2023" + detectorVersion + ",Extended2023" + detectorVersion + "Reco',"