1 from __future__
import print_function
2 from optparse
import OptionParser
3 import sys, os, operator
4 from pprint
import pprint
10 detectorVersionDefault = 999
13 doTest =
bool(options.doTest)
15 detectorVersion =
"D"+
str(options.detectorVersionManual)
17 if options.v_detector>0:
18 detectorVersion =
"D"+
str(options.v_detector)
19 if detectorVersion
in detectorVersionDict.values():
20 detectorTuple = detectorVersionDict.keys()[detectorVersionDict.values().
index(detectorVersion)]
22 print(
"Unknown detector "+detectorVersion)
24 elif detectorTuple
in detectorVersionDict.keys():
25 detectorVersion = detectorVersionDict[detectorTuple]
27 if not doTest:
print(
"Detector "+
str(detectorTuple)+
" not found in dictionary, using "+(
"default" if options.detectorVersionManual==detectorVersionDefault
else "provided")+
" version number "+
str(detectorVersion))
30 if detectorVersion
in deprecatedDets:
31 print(
"Error: "+detectorVersion+
" is deprecated and cannot be used.")
33 for subdet
in detectorTuple:
34 if subdet
in deprecatedSubdets:
35 print(
"Error: "+subdet+
" is deprecated and cannot be used.")
39 xmlName =
"cmsExtendedGeometry2026"+detectorVersion+
"XML_cfi.py" 40 simName =
"GeometryExtended2026"+detectorVersion+
"_cff.py" 41 recoName =
"GeometryExtended2026"+detectorVersion+
"Reco_cff.py" 44 CMSSWBASE = os.getenv(
"CMSSW_BASE")
45 CMSSWRELBASE = os.getenv(
"CMSSW_RELEASE_BASE")
46 if CMSSWBASE
is None: CMSSWBASE =
"" 47 xmlDir = os.path.join(CMSSWBASE,
"src",
"Geometry",
"CMSCommonData",
"python")
48 simrecoDir = os.path.join(CMSSWBASE,
"src",
"Configuration",
"Geometry",
"python")
50 if not os.path.isdir(xmlDir):
51 xmlDir = os.path.join(CMSSWRELBASE,
"src",
"Geometry",
"CMSCommonData",
"python")
54 if not os.path.isdir(xmlDir):
55 mvCommands +=
"mv "+xmlName+
" "+xmlDir+
"/\n" 57 xmlName = os.path.join(xmlDir,xmlName)
58 if not os.path.isdir(simrecoDir):
59 mvCommands +=
"mv "+simName+
" "+simrecoDir+
"/\n" 60 mvCommands +=
"mv "+recoName+
" "+simrecoDir+
"/\n" 62 simName = os.path.join(simrecoDir,simName)
63 recoName = os.path.join(simrecoDir,recoName)
65 print(
"Warning: some geometry packages not checked out.\nOnce they are available, please execute the following commands manually:\n"+mvCommands)
68 xmlFile = open(xmlName,
'w')
69 simFile = open(simName,
'w')
70 recoFile = open(recoName,
'w')
73 preamble =
"import FWCore.ParameterSet.Config as cms"+
"\n"+
"\n" 74 preamble +=
"# This config was generated automatically using generate2026Geometry.py"+
"\n" 75 preamble +=
"# If you notice a mistake, please update the generating script, not just this config"+
"\n"+
"\n" 78 xmlFile.write(preamble)
80 xmlFile.write(
"XMLIdealGeometryESSource = cms.ESSource(\"XMLIdealGeometryESSource\","+
"\n")
81 xmlFile.write(
" geomXMLFiles = cms.vstring("+
"\n")
82 for section
in range(1,maxsections+1):
85 xmlFile.write(
" )+"+
"\n"+
" cms.vstring("+
"\n")
86 for iDict,aDict
in enumerate(allDicts):
87 if section
in aDict[detectorTuple[iDict]].
keys():
88 xmlFile.write(
'\n'.
join([
" '"+aLine+
"'," for aLine
in aDict[detectorTuple[iDict]][section] ])+
"\n")
90 xmlFile.write(
" ),"+
"\n"+
" rootNodeName = cms.string('cms:OCMS')"+
"\n"+
")"+
"\n")
94 simFile.write(preamble)
96 simFile.write(
"from Geometry.CMSCommonData."+os.path.basename(xmlName).
replace(
".py",
"")+
" import *"+
"\n")
97 for iDict,aDict
in enumerate(allDicts):
98 if "sim" in aDict[detectorTuple[iDict]].
keys():
99 simFile.write(
'\n'.
join([ aLine
for aLine
in aDict[detectorTuple[iDict]][
"sim"] ])+
"\n")
103 recoFile.write(preamble)
105 recoFile.write(
"from Configuration.Geometry."+os.path.basename(simName).
replace(
".py",
"")+
" import *"+
"\n\n")
106 for iDict,aDict
in enumerate(allDicts):
107 if "reco" in aDict[detectorTuple[iDict]].
keys():
108 recoFile.write(
"# "+aDict[
"name"]+
"\n")
109 recoFile.write(
'\n'.
join([ aLine
for aLine
in aDict[detectorTuple[iDict]][
"reco"] ])+
"\n\n")
112 from Configuration.StandardSequences.GeometryConf
import GeometryConf
121 for iDict,aDict
in enumerate(allDicts):
122 if "era" in aDict[detectorTuple[iDict]].
keys():
123 eraLineItems.append(aDict[detectorTuple[iDict]][
"era"])
124 eraLine +=
", ".
join([ eraLineItem
for eraLineItem
in eraLineItems ])
125 print(
"The Era for this detector should contain:")
129 if not 'Extended2026'+detectorVersion
in GeometryConf.keys():
130 print(
"Please add this line in Configuration/StandardSequences/python/GeometryConf.py:")
131 print(
" 'Extended2026"+detectorVersion+
"' : 'Extended2026"+detectorVersion+
",Extended2026"+detectorVersion+
"Reco',")
137 if not filecmp.cmp(simName,os.path.join(simrecoDir,simName)):
138 errorList.append(simName+
" differs");
139 if not filecmp.cmp(recoName,os.path.join(simrecoDir,recoName)):
140 errorList.append(recoName+
" differs");
142 if not 'Extended2026'+detectorVersion
in GeometryConf.keys():
143 errorList.append(
'Extended2026'+detectorVersion+
" missing from GeometryConf")
145 if not filecmp.cmp(xmlName,os.path.join(xmlDir,xmlName)):
146 errorList.append(xmlName+
" differs");
149 if __name__ ==
"__main__":
151 parser = OptionParser()
152 for aDict
in allDicts:
153 parser.add_option(
"-"+aDict[
"abbrev"],
"--"+aDict[
"name"],dest=
"v_"+aDict[
"name"],default=aDict[
"default"],help=
"version for "+aDict[
"name"]+
" (default = %default)")
154 parser.add_option(
"-V",
"--version",dest=
"detectorVersionManual",default=detectorVersionDefault,help=
"manual detector version number (default = %default)")
155 parser.add_option(
"-D",
"--detector",dest=
"v_detector",default=0,help=
"version for whole detector, ignored if 0, overrides subdet versions otherwise (default = %default)")
156 parser.add_option(
"-l",
"--list",dest=
"doList",default=
False,action=
"store_true",help=
"list known detector versions and exit (default = %default)")
157 parser.add_option(
"-t",
"--test",dest=
"doTest",default=
False,action=
"store_true",help=
"enable unit test mode (default = %default)")
158 (options, args) = parser.parse_args()
161 if options.doList
and not options.doTest:
162 pprint(sorted(detectorVersionDict.items(),key=operator.itemgetter(1)))
168 for detectorTuple
in detectorVersionDict:
170 errorList.extend(errorTmp)
172 print(
'\n'.
join([anError
for anError
in errorList]))
177 detectorTuple = tuple([aDict[
"abbrev"]+
str(getattr(options,
"v_"+aDict[
"name"]))
for aDict
in allDicts])
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
static std::string join(char **cmd)
def generateGeom(detectorTuple, options)