29 def generateGeom(self, detectorTuple, args):
30 detectorVersion = self.detectorPrefix+
str(args.detectorVersionManual)
33 detectorVersion = self.detectorPrefix+
str(args.v_detector)
34 if detectorVersion
in self.detectorVersionDict.
values():
35 detectorTuple = self.detectorVersionDict.
keys()[self.detectorVersionDict.
values().
index(detectorVersion)]
37 print(
"Unknown detector "+detectorVersion)
39 elif detectorTuple
in self.detectorVersionDict.
keys():
40 detectorVersion = self.detectorVersionDict[detectorTuple]
42 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))
45 if self.deprecatedDets
is not None and detectorVersion
in self.deprecatedDets:
46 print(
"Error: "+detectorVersion+
" is deprecated and cannot be used.")
48 if self.deprecatedSubdets
is not None:
49 for subdet
in detectorTuple:
50 if subdet
in self.deprecatedSubdets:
51 print(
"Error: "+subdet+
" is deprecated and cannot be used.")
55 xmlName =
"cmsExtendedGeometry"+self.detectorYear+detectorVersion+
"XML_cfi.py"
56 xmlDD4hepName =
"cmsExtendedGeometry"+self.detectorYear+detectorVersion+
".xml"
57 simName =
"GeometryExtended"+self.detectorYear+detectorVersion+
"_cff.py"
58 simDD4hepName =
"GeometryDD4hepExtended"+self.detectorYear+detectorVersion+
"_cff.py"
59 recoName =
"GeometryExtended"+self.detectorYear+detectorVersion+
"Reco_cff.py"
60 recoDD4hepName =
"GeometryDD4hepExtended"+self.detectorYear+detectorVersion+
"Reco_cff.py"
63 CMSSWBASE = os.getenv(
"CMSSW_BASE")
64 CMSSWRELBASE = os.getenv(
"CMSSW_RELEASE_BASE")
65 if CMSSWBASE
is None: CMSSWBASE =
""
66 xmlDir = os.path.join(CMSSWBASE,
"src",
"Geometry",
"CMSCommonData",
"python")
67 xmlDD4hepDir = os.path.join(CMSSWBASE,
"src",
"Geometry",
"CMSCommonData",
"data",
"dd4hep")
68 simrecoDir = os.path.join(CMSSWBASE,
"src",
"Configuration",
"Geometry",
"python")
69 simrecoDD4hepDir = os.path.join(CMSSWBASE,
"src",
"Configuration",
"Geometry",
"python")
71 if not os.path.isdir(xmlDir):
72 xmlDir = os.path.join(CMSSWRELBASE,
"src",
"Geometry",
"CMSCommonData",
"python")
73 xmlDD4hepDir = os.path.join(CMSSWRELBASE,
"src",
"Geometry",
"CMSCommonData",
"data",
"dd4hep")
76 if not os.path.isdir(xmlDir):
77 mvCommands +=
"mv "+xmlName+
" "+xmlDir+
"/\n"
79 xmlName = os.path.join(xmlDir,xmlName)
80 if not os.path.isdir(xmlDD4hepDir):
81 mvCommands +=
"mv "+xmlDD4hepName+
" "+xmlDD4hepDir+
"/\n"
83 xmlDD4hepName = os.path.join(xmlDD4hepDir,xmlDD4hepName)
84 if not os.path.isdir(simrecoDir):
85 mvCommands +=
"mv "+simName+
" "+simrecoDir+
"/\n"
86 mvCommands +=
"mv "+recoName+
" "+simrecoDir+
"/\n"
88 simName = os.path.join(simrecoDir,simName)
89 recoName = os.path.join(simrecoDir,recoName)
90 if not os.path.isdir(simrecoDD4hepDir):
91 mvCommands +=
"mv "+simDD4hepName+
" "+simrecoDD4hepDir+
"/\n"
92 mvCommands +=
"mv "+recoDD4hepName+
" "+simrecoDD4hepDir+
"/\n"
94 simDD4hepName = os.path.join(simrecoDD4hepDir,simDD4hepName)
95 recoDD4hepName = os.path.join(simrecoDD4hepDir,recoDD4hepName)
97 print(
"Warning: some geometry packages not checked out.\nOnce they are available, please execute the following commands manually:\n"+mvCommands)
100 xmlFile = open(xmlName,
'w')
101 xmlDD4hepFile = open(xmlDD4hepName,
'w')
102 simFile = open(simName,
'w')
103 simDD4hepFile = open(simDD4hepName,
'w')
104 recoFile = open(recoName,
'w')
105 recoDD4hepFile = open(recoDD4hepName,
'w')
108 preamble =
"import FWCore.ParameterSet.Config as cms"+
"\n"+
"\n"
109 preamble +=
"# This config was generated automatically using "+self.scriptName+
"\n"
110 preamble +=
"# If you notice a mistake, please update the generating script, not just this config"+
"\n"+
"\n"
113 xmlFile.write(preamble)
115 xmlFile.write(
"XMLIdealGeometryESSource = cms.ESSource(\"XMLIdealGeometryESSource\","+
"\n")
116 xmlFile.write(
" geomXMLFiles = cms.vstring("+
"\n")
117 for section
in range(1,self.maxSections+1):
120 xmlFile.write(
" )+"+
"\n"+
" cms.vstring("+
"\n")
121 for iDict,aDict
in enumerate(self.allDicts):
122 if section
in aDict[detectorTuple[iDict]].
keys():
123 xmlFile.write(
'\n'.
join([
" '"+aLine+
"'," for aLine
in aDict[detectorTuple[iDict]][section] ])+
"\n")
125 xmlFile.write(
" ),"+
"\n"+
" rootNodeName = cms.string('cms:OCMS')"+
"\n"+
")"+
"\n")
129 xmlDD4hepFile.write(
"<?xml version=\"1.0\"?>\n"+
131 " <open_geometry/>\n"+
132 " <close_geometry/>\n"+
134 " <IncludeSection>\n")
135 for section
in range(1,self.maxSections+1):
137 for iDict,aDict
in enumerate(self.allDicts):
138 if section
in aDict[detectorTuple[iDict]].
keys():
139 xmlDD4hepFile.write(
'\n'.
join([
" <Include ref='"+aLine+
"'/>" for aLine
in aDict[detectorTuple[iDict]][section] ])+
"\n")
141 xmlDD4hepFile.write(
" </IncludeSection>\n"+
142 "</DDDefinition>"+
"\n")
143 xmlDD4hepFile.close()
146 simFile.write(preamble)
148 simFile.write(
"from Geometry.CMSCommonData."+os.path.basename(xmlName).
replace(
".py",
"")+
" import *"+
"\n")
149 for iDict,aDict
in enumerate(self.allDicts):
150 if "sim" in aDict[detectorTuple[iDict]].
keys():
151 simFile.write(
'\n'.
join([ aLine
for aLine
in aDict[detectorTuple[iDict]][
"sim"] ])+
"\n")
155 simDD4hepFile.write(preamble)
157 simDD4hepFile.write(
"from Configuration.Geometry.GeometryDD4hep_cff"+
" import *"+
"\n")
158 simDD4hepFile.write(
"DDDetectorESProducer.confGeomXMLFiles = cms.FileInPath(\"Geometry/CMSCommonData/data/dd4hep/"+os.path.basename(xmlDD4hepName)+
"\")\n\n")
159 for iDict,aDict
in enumerate(self.allDicts):
160 if "sim" in aDict[detectorTuple[iDict]].
keys():
161 simDD4hepFile.write(
'\n'.
join([ aLine
for aLine
in aDict[detectorTuple[iDict]][
"sim"] ])+
"\n")
162 simDD4hepFile.close()
165 recoFile.write(preamble)
167 recoFile.write(
"from Configuration.Geometry."+os.path.basename(simName).
replace(
".py",
"")+
" import *"+
"\n\n")
168 for iDict,aDict
in enumerate(self.allDicts):
169 if "reco" in aDict[detectorTuple[iDict]].
keys():
170 recoFile.write(
"# "+aDict[
"name"]+
"\n")
171 recoFile.write(
'\n'.
join([ aLine
for aLine
in aDict[detectorTuple[iDict]][
"reco"] ])+
"\n\n")
175 recoDD4hepFile.write(preamble)
177 recoDD4hepFile.write(
"from Configuration.Geometry."+os.path.basename(simDD4hepName).
replace(
".py",
"")+
" import *"+
"\n\n")
178 for iDict,aDict
in enumerate(self.allDicts):
179 if "reco" in aDict[detectorTuple[iDict]].
keys():
180 recoDD4hepFile.write(
"# "+aDict[
"name"]+
"\n")
181 recoDD4hepFile.write(
'\n'.
join([ aLine
for aLine
in aDict[detectorTuple[iDict]][
"reco"] ])+
"\n\n")
182 recoDD4hepFile.close()
184 from Configuration.StandardSequences.GeometryConf
import GeometryConf
193 for iDict,aDict
in enumerate(self.allDicts):
194 if "era" in aDict[detectorTuple[iDict]].
keys():
195 eraLineItems.append(aDict[detectorTuple[iDict]][
"era"])
196 eraLine +=
", ".
join([ eraLineItem
for eraLineItem
in eraLineItems ])
197 print(
"The Era for this detector should contain:")
201 if not 'Extended'+self.detectorYear+detectorVersion
in GeometryConf.keys():
202 print(
"Please add this line in Configuration/StandardSequences/python/GeometryConf.py:")
203 print(
" 'Extended"+self.detectorYear+detectorVersion+
"' : 'Extended"+self.detectorYear+detectorVersion+
",Extended"+self.detectorYear+detectorVersion+
"Reco',")
209 simFile = os.path.join(simrecoDir,simName)
210 if not os.path.isfile(simFile):
211 errorList.append(simName+
" missing")
212 elif not filecmp.cmp(simName,simFile):
213 errorList.append(simName+
" differs")
214 simDD4hepFile = os.path.join(simrecoDD4hepDir,simDD4hepName)
215 if not os.path.isfile(simDD4hepFile):
216 errorList.append(simDD4hepName+
" missing")
217 elif not filecmp.cmp(simDD4hepName,simDD4hepFile):
218 errorList.append(simDD4hepName+
" differs")
219 recoFile = os.path.join(simrecoDir,recoName)
220 if not os.path.isfile(recoFile):
221 errorList.append(recoName+
" missing")
222 elif not filecmp.cmp(recoName,recoFile):
223 errorList.append(recoName+
" differs")
224 recoDD4hepFile = os.path.join(simrecoDD4hepDir,recoDD4hepName)
225 if not os.path.isfile(recoDD4hepFile):
226 errorList.append(recoDD4hepName+
" missing")
227 elif not filecmp.cmp(recoDD4hepName,recoDD4hepFile):
228 errorList.append(recoDD4hepName+
" differs")
230 if not 'Extended'+self.detectorYear+detectorVersion
in GeometryConf.keys():
231 errorList.append(
'Extended'+self.detectorYear+detectorVersion+
" missing from GeometryConf")
233 xmlFile = os.path.join(xmlDir,xmlName)
234 if not os.path.isfile(xmlFile):
235 errorList.append(xmlName+
" missing")
236 elif not filecmp.cmp(xmlName,xmlFile):
237 errorList.append(xmlName+
" differs")
239 xmlDD4hepFile = os.path.join(xmlDD4hepDir,xmlDD4hepName)
240 if not os.path.exists(xmlDD4hepFile):
241 errorList.append(xmlDD4hepName+
" differs")
242 elif not filecmp.cmp(xmlDD4hepName,xmlDD4hepFile):
243 errorList.append(xmlDD4hepName+
" differs")