CMS 3D CMS Logo

Functions
generate2023Geometry Namespace Reference

Functions

def generateGeom (detectorTuple, options)
 

Function Documentation

def generate2023Geometry.generateGeom (   detectorTuple,
  options 
)

Definition at line 11 of file generate2023Geometry.py.

References electrons_cff.bool, join(), relativeConstraints.keys, python.rootplot.root2matplotlib.replace(), and str.

11 def generateGeom(detectorTuple, options):
12  doTest = bool(options.doTest)
13 
14  detectorVersion = "D"+str(options.detectorVersionManual)
15  # reverse dict search if overall D# specified
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)]
20  else:
21  print "Unknown detector "+detectorVersion
22  sys.exit(1)
23  elif detectorTuple in detectorVersionDict.keys():
24  detectorVersion = detectorVersionDict[detectorTuple]
25  else:
26  if not doTest: print "Detector "+str(detectorTuple)+" not found in dictionary, using "+("default" if options.detectorVersionManual==detectorVersionDefault else "provided")+" version number "+str(detectorVersion)
27 
28  # check for deprecation
29  if detectorVersion in deprecatedDets:
30  print "Error: "+detectorVersion+" is deprecated and cannot be used."
31  sys.exit(1)
32  for subdet in detectorTuple:
33  if subdet in deprecatedSubdets:
34  print "Error: "+subdet+" is deprecated and cannot be used."
35  sys.exit(1)
36 
37  # create output files
38  xmlName = "cmsExtendedGeometry2023"+detectorVersion+"XML_cfi.py"
39  simName = "GeometryExtended2023"+detectorVersion+"_cff.py"
40  recoName = "GeometryExtended2023"+detectorVersion+"Reco_cff.py"
41 
42  # check directories
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")
48  if doTest:
49  if not os.path.isdir(xmlDir):
50  xmlDir = os.path.join(CMSSWRELBASE,"src","Geometry","CMSCommonData","python")
51  else:
52  mvCommands = ""
53  if not os.path.isdir(xmlDir):
54  mvCommands += "mv "+xmlName+" "+xmlDir+"/\n"
55  else:
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"
60  else:
61  simName = os.path.join(simrecoDir,simName)
62  recoName = os.path.join(simrecoDir,recoName)
63  if len(mvCommands)>0:
64  print "Warning: some geometry packages not checked out.\nOnce they are available, please execute the following commands manually:\n"+mvCommands
65 
66  # open files
67  xmlFile = open(xmlName,'w')
68  simFile = open(simName,'w')
69  recoFile = open(recoName,'w')
70 
71  # common preamble
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"
75 
76  # create XML config
77  xmlFile.write(preamble)
78  # extra preamble
79  xmlFile.write("XMLIdealGeometryESSource = cms.ESSource(\"XMLIdealGeometryESSource\","+"\n")
80  xmlFile.write(" geomXMLFiles = cms.vstring("+"\n")
81  for section in range(1,maxsections+1):
82  # midamble
83  if section==2:
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")
88  # postamble
89  xmlFile.write(" ),"+"\n"+" rootNodeName = cms.string('cms:OCMS')"+"\n"+")"+"\n")
90  xmlFile.close()
91 
92  # create sim config
93  simFile.write(preamble)
94  # always need XML
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")
99  simFile.close()
100 
101  # create reco config
102  recoFile.write(preamble)
103  # always need sim
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")
109  recoFile.close()
110 
111  from Configuration.StandardSequences.GeometryConf import GeometryConf
112  if not doTest: # todo: include these in unit test somehow
113  # specify Era customizations
114  # must be checked manually in:
115  # Configuration/StandardSequences/python/Eras.py
116  # Configuration/Eras/python/
117  # Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py (workflow definitions)
118  eraLine = ""
119  eraLineItems = []
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:"
125  print eraLine
126 
127  # specify GeometryConf
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',"
131 
132  errorList = []
133 
134  if doTest:
135  # tests for Configuration/Geometry
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");
140  # test for Configuration/StandardSequences
141  if not 'Extended2023'+detectorVersion in GeometryConf.keys():
142  errorList.append('Extended2023'+detectorVersion+" missing from GeometryConf")
143  # test for Geometry/CMSCommonData
144  if not filecmp.cmp(xmlName,os.path.join(xmlDir,xmlName)):
145  errorList.append(xmlName+" differs");
146  return errorList
147 
def replace(string, replacements)
def generateGeom(detectorTuple, options)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
#define str(s)