1 from optparse
import OptionParser
2 import sys, os, operator
3 from pprint
import pprint
6 from dict2023Geometry
import *
9 detectorVersionDefault = 999
12 doTest = bool(options.doTest)
14 detectorVersion =
"D"+str(options.detectorVersionManual)
16 if options.v_detector>0:
17 detectorVersion =
"D"+str(options.v_detector)
18 if detectorVersion
in detectorVersionDict.values():
19 detectorTuple = detectorVersionDict.keys()[detectorVersionDict.values().
index(detectorVersion)]
21 print "Unknown detector "+detectorVersion
23 elif detectorTuple
in detectorVersionDict.keys():
24 detectorVersion = detectorVersionDict[detectorTuple]
26 if not doTest:
print "Detector "+str(detectorTuple)+
" not found in dictionary, using "+(
"default" if options.detectorVersionManual==detectorVersionDefault
else "provided")+
" version number "+str(detectorVersion)
29 if detectorVersion
in deprecatedDets:
30 print "Error: "+detectorVersion+
" is deprecated and cannot be used."
32 for subdet
in detectorTuple:
33 if subdet
in deprecatedSubdets:
34 print "Error: "+subdet+
" is deprecated and cannot be used."
38 xmlName =
"cmsExtendedGeometry2023"+detectorVersion+
"XML_cfi.py"
39 simName =
"GeometryExtended2023"+detectorVersion+
"_cff.py"
40 recoName =
"GeometryExtended2023"+detectorVersion+
"Reco_cff.py"
43 CMSSWBASE = os.getenv(
"CMSSW_BASE")
44 CMSSWRELBASE = os.getenv(
"CMSSW_RELEASE_BASE")
45 if CMSSWBASE
is None: CMSSWBASE =
""
46 xmlDir = os.path.join(CMSSWBASE,
"src",
"Geometry",
"CMSCommonData",
"python")
47 simrecoDir = os.path.join(CMSSWBASE,
"src",
"Configuration",
"Geometry",
"python")
49 if not os.path.isdir(xmlDir):
50 xmlDir = os.path.join(CMSSWRELBASE,
"src",
"Geometry",
"CMSCommonData",
"python")
53 if not os.path.isdir(xmlDir):
54 mvCommands +=
"mv "+xmlName+
" "+xmlDir+
"/\n"
56 xmlName = os.path.join(xmlDir,xmlName)
57 if not os.path.isdir(simrecoDir):
58 mvCommands +=
"mv "+simName+
" "+simrecoDir+
"/\n"
59 mvCommands +=
"mv "+recoName+
" "+simrecoDir+
"/\n"
61 simName = os.path.join(simrecoDir,simName)
62 recoName = os.path.join(simrecoDir,recoName)
64 print "Warning: some geometry packages not checked out.\nOnce they are available, please execute the following commands manually:\n"+mvCommands
67 xmlFile = open(xmlName,
'w')
68 simFile = open(simName,
'w')
69 recoFile = open(recoName,
'w')
72 preamble =
"import FWCore.ParameterSet.Config as cms"+
"\n"+
"\n"
73 preamble +=
"# This config was generated automatically using generate2023Geometry.py"+
"\n"
74 preamble +=
"# If you notice a mistake, please update the generating script, not just this config"+
"\n"+
"\n"
77 xmlFile.write(preamble)
79 xmlFile.write(
"XMLIdealGeometryESSource = cms.ESSource(\"XMLIdealGeometryESSource\","+
"\n")
80 xmlFile.write(
" geomXMLFiles = cms.vstring("+
"\n")
81 for section
in range(1,maxsections+1):
84 xmlFile.write(
" )+"+
"\n"+
" cms.vstring("+
"\n")
85 for iDict,aDict
in enumerate(allDicts):
86 if section
in aDict[detectorTuple[iDict]].
keys():
87 xmlFile.write(
'\n'.
join([
" '"+aLine+
"'," for aLine
in aDict[detectorTuple[iDict]][section] ])+
"\n")
89 xmlFile.write(
" ),"+
"\n"+
" rootNodeName = cms.string('cms:OCMS')"+
"\n"+
")"+
"\n")
93 simFile.write(preamble)
95 simFile.write(
"from Geometry.CMSCommonData."+os.path.basename(xmlName).
replace(
".py",
"")+
" import *"+
"\n")
96 for iDict,aDict
in enumerate(allDicts):
97 if "sim" in aDict[detectorTuple[iDict]].
keys():
98 simFile.write(
'\n'.
join([ aLine
for aLine
in aDict[detectorTuple[iDict]][
"sim"] ])+
"\n")
102 recoFile.write(preamble)
104 recoFile.write(
"from Configuration.Geometry."+os.path.basename(simName).
replace(
".py",
"")+
" import *"+
"\n\n")
105 for iDict,aDict
in enumerate(allDicts):
106 if "reco" in aDict[detectorTuple[iDict]].
keys():
107 recoFile.write(
"# "+aDict[
"name"]+
"\n")
108 recoFile.write(
'\n'.
join([ aLine
for aLine
in aDict[detectorTuple[iDict]][
"reco"] ])+
"\n\n")
111 from Configuration.StandardSequences.GeometryConf
import GeometryConf
120 for iDict,aDict
in enumerate(allDicts):
121 if "era" in aDict[detectorTuple[iDict]].
keys():
122 eraLineItems.append(aDict[detectorTuple[iDict]][
"era"])
123 eraLine +=
", ".
join([ eraLineItem
for eraLineItem
in eraLineItems ])
124 print "The Era for this detector should contain:"
128 if not 'Extended2023'+detectorVersion
in GeometryConf.keys():
129 print "Please add this line in Configuration/StandardSequences/python/GeometryConf.py:"
130 print " 'Extended2023"+detectorVersion+
"' : 'Extended2023"+detectorVersion+
",Extended2023"+detectorVersion+
"Reco',"
136 if not filecmp.cmp(simName,os.path.join(simrecoDir,simName)):
137 errorList.append(simName+
" differs");
138 if not filecmp.cmp(recoName,os.path.join(simrecoDir,recoName)):
139 errorList.append(recoName+
" differs");
141 if not 'Extended2023'+detectorVersion
in GeometryConf.keys():
142 errorList.append(
'Extended2023'+detectorVersion+
" missing from GeometryConf")
144 if not filecmp.cmp(xmlName,os.path.join(xmlDir,xmlName)):
145 errorList.append(xmlName+
" differs");
148 if __name__ ==
"__main__":
150 parser = OptionParser()
151 for aDict
in allDicts:
152 parser.add_option(
"-"+aDict[
"abbrev"],
"--"+aDict[
"name"],dest=
"v_"+aDict[
"name"],default=aDict[
"default"],help=
"version for "+aDict[
"name"]+
" (default = %default)")
153 parser.add_option(
"-V",
"--version",dest=
"detectorVersionManual",default=detectorVersionDefault,help=
"manual detector version number (default = %default)")
154 parser.add_option(
"-D",
"--detector",dest=
"v_detector",default=0,help=
"version for whole detector, ignored if 0, overrides subdet versions otherwise (default = %default)")
155 parser.add_option(
"-l",
"--list",dest=
"doList",default=
False,action=
"store_true",help=
"list known detector versions and exit (default = %default)")
156 parser.add_option(
"-t",
"--test",dest=
"doTest",default=
False,action=
"store_true",help=
"enable unit test mode (default = %default)")
157 (options, args) = parser.parse_args()
160 if options.doList
and not options.doTest:
161 pprint(sorted(detectorVersionDict.items(),key=operator.itemgetter(1)))
167 for detectorTuple
in detectorVersionDict:
169 errorList.extend(errorTmp)
171 print '\n'.
join([anError
for anError
in errorList])
176 detectorTuple = tuple([aDict[
"abbrev"]+str(getattr(options,
"v_"+aDict[
"name"]))
for aDict
in allDicts])
static std::string join(char **cmd)