CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
alignment.Alignment Class Reference
Inheritance diagram for alignment.Alignment:

Public Member Functions

def __init__ (self, name, config, runGeomComp="1")
 
def getConditions (self)
 
def getRepMap (self)
 
def restrictTo (self, restriction)
 

Public Attributes

 color
 
 conditions
 
 globaltag
 
 mode
 
 name
 
 runGeomComp
 
 style
 
 title
 

Static Public Attributes

dictionary condShorts
 

Private Member Functions

def __getConditions (self, theConfig, theSection)
 
def __shorthandExists (self, theRcdName, theShorthand)
 
def __testDbExist (self, dbpath, tagname)
 

Detailed Description

Definition at line 10 of file alignment.py.

Constructor & Destructor Documentation

◆ __init__()

def alignment.Alignment.__init__ (   self,
  name,
  config,
  runGeomComp = "1" 
)

Definition at line 35 of file alignment.py.

35  def __init__(self, name, config, runGeomComp = "1"):
36  section = "alignment:%s"%name
37  if not config.has_section( section ):
38  raise AllInOneError("section %s not found. Please define the "
39  "alignment!"%section)
40  config.checkInput(section,
41  knownSimpleOptions = ['globaltag', 'style', 'color', 'title', 'mp', 'mp_alignments', 'mp_deformations', 'mp_APEs', 'hp', 'hp_alignments', 'hp_deformations', 'sm', 'sm_alignments', 'sm_deformations'],
42  knownKeywords = ['condition'])
43  self.name = clean_name(name)
44  if config.exists(section,"title"):
45  self.title = config.get(section,"title")
46  else:
47  self.title = self.name
48  if (int(runGeomComp) != 1):
49  self.name += "_run" + runGeomComp
50  self.title += " run " + runGeomComp
51  if "|" in self.title or "," in self.title or '"' in self.title:
52  msg = "The characters '|', '\"', and ',' cannot be used in the alignment title!"
53  raise AllInOneError(msg)
54  self.runGeomComp = runGeomComp
55  self.globaltag = config.get( section, "globaltag" )
56  self.conditions = self.__getConditions( config, section )
57 
58  self.color = config.get(section,"color")
59  self.style = config.get(section,"style")
60 
61  self.color = str(parsecolor(self.color))
62  self.style = str(parsestyle(self.style))
63 
def parsestyle(style)
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)
def parsecolor(color)
#define str(s)

Member Function Documentation

◆ __getConditions()

def alignment.Alignment.__getConditions (   self,
  theConfig,
  theSection 
)
private

Definition at line 79 of file alignment.py.

References alignment.Alignment.__shorthandExists(), alignment.Alignment.__testDbExist(), nano_mu_local_reco_cff.bool, alignment.Alignment.condShorts, helperFunctions.getTagsMap(), watchdog.group, createfilelist.int, join(), relativeConstraints.keys, SiStripPI.max, submitPVValidationJobs.split(), and nano_mu_digi_cff.strip.

79  def __getConditions( self, theConfig, theSection ):
80  conditions = []
81  for option in theConfig.options( theSection ):
82  if option in ("mp", "mp_alignments", "mp_deformations", "mp_APEs", "hp", "hp_alignments", "hp_deformations", "sm", "sm_alignments", "sm_deformations"):
83  matches = [re.match(_, option) for _ in ("^(..)$", "^(..)_alignments$", "^(..)_deformations$", "^(..)_APEs$")]
84  assert sum(bool(_) for _ in matches) == 1, option
85  condPars = theConfig.get(theSection, option).split(",")
86  condPars = [_.strip() for _ in condPars]
87  if matches[0]:
88  alignments = True
89  deformations = True
90  APEs = {"hp": False, "mp": True}[option]
91  elif matches[1]:
92  alignments = True
93  deformations = False
94  APEs = False
95  option = matches[1].group(1)
96  elif matches[2]:
97  alignments = False
98  deformations = True
99  APEs = False
100  option = matches[2].group(1)
101  elif matches[3]:
102  alignments = False
103  deformations = False
104  APEs = True
105  option = matches[3].group(1)
106  else:
107  assert False
108 
109  if option == "mp":
110  if len(condPars) == 1:
111  number, = condPars
112  jobm = None
113  elif len(condPars) == 2:
114  number, jobm = condPars
115  else:
116  raise AllInOneError("Up to 2 arguments accepted for {} (job number, and optionally jobm index)".format(option))
117 
118  folder = "/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/{}{}/".format(option, number)
119  if not os.path.exists(folder):
120  raise AllInOneError(folder+" does not exist.")
121  folder = os.path.join(folder, "jobData")
122  jobmfolders = set()
123  if jobm is None:
124  for filename in os.listdir(folder):
125  if re.match("jobm([0-9]*)", filename) and os.path.isdir(os.path.join(folder, filename)):
126  jobmfolders.add(filename)
127  if len(jobmfolders) == 0:
128  raise AllInOneError("No jobm or jobm(number) folder in {}".format(folder))
129  elif len(jobmfolders) == 1:
130  folder = os.path.join(folder, jobmfolders.pop())
131  else:
132  raise AllInOneError(
133  "Multiple jobm or jobm(number) folders in {}\n".format(folder)
134  + ", ".join(jobmfolders) + "\n"
135  + "Please specify 0 for jobm, or a number for one of the others."
136  )
137  elif jobm == "0":
138  folder = os.path.join(folder, "jobm")
139  if os.path.exists(folder + "0"):
140  raise AllInOneError("Not set up to handle a folder named jobm0")
141  else:
142  folder = os.path.join(folder, "jobm{}".format(jobm))
143 
144  dbfile = os.path.join(folder, "alignments_MP.db")
145  if not os.path.exists(dbfile):
146  raise AllInOneError("No file {}. Maybe your alignment folder is corrupted, or maybe you specified the wrong jobm?".format(dbfile))
147 
148  elif option in ("hp", "sm"):
149  if len(condPars) == 1:
150  number, = condPars
151  iteration = None
152  elif len(condPars) == 2:
153  number, iteration = condPars
154  else:
155  raise AllInOneError("Up to 2 arguments accepted for {} (job number, and optionally iteration)".format(option))
156  folder = "/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy/alignments/{}{}".format(option, number)
157  if not os.path.exists(folder):
158  raise AllInOneError(folder+" does not exist.")
159  if iteration is None:
160  for filename in os.listdir(folder):
161  match = re.match("alignments_iter([0-9]*).db", filename)
162  if match:
163  if iteration is None or int(match.group(1)) > iteration:
164  iteration = int(match.group(1))
165  if iteration is None:
166  raise AllInOneError("No alignments in {}".format(folder))
167  dbfile = os.path.join(folder, "alignments_iter{}.db".format(iteration))
168  if not os.path.exists(dbfile):
169  raise AllInOneError("No file {}.".format(dbfile))
170 
171  if "Deformations" not in getTagsMap(dbfile).keys():
172  deformations = False #so that hp = XXXX works whether or not deformations were aligned
173  if not alignments: #then it's specified with hp_deformations, which is a mistake
174  raise AllInOneError("{}{} has no deformations".format(option, number))
175 
176  else:
177  assert False, option
178 
179  if alignments:
180  conditions.append({"rcdName": "TrackerAlignmentRcd",
181  "connectString": "sqlite_file:"+dbfile,
182  "tagName": "Alignments",
183  "labelName": ""})
184  if deformations:
185  conditions.append({"rcdName": "TrackerSurfaceDeformationRcd",
186  "connectString": "sqlite_file:"+dbfile,
187  "tagName": "Deformations",
188  "labelName": ""})
189  if APEs:
190  conditions.append({"rcdName": "TrackerAlignmentErrorExtendedRcd",
191  "connectString": "sqlite_file:"+dbfile,
192  "tagName": "AlignmentErrorsExtended",
193  "labelName": ""})
194 
195  elif option.startswith( "condition " ):
196  rcdName = option.split( "condition " )[1]
197  condPars = theConfig.get( theSection, option ).split( "," )
198  if len(condPars) == 1:
199  if len(condPars[0])==0:
200  msg = ("In section [%s]: '%s' is used with too few "
201  "arguments. A connect_string and a tag are "
202  "required!"%(theSection, option))
203  raise AllInOneError(msg)
204  elif self.__shorthandExists(rcdName, condPars[0]):
205  shorthand = condPars[0]
206  condPars = [
207  self.condShorts[rcdName][shorthand]["connectString"],
208  self.condShorts[rcdName][shorthand]["tagName"],
209  self.condShorts[rcdName][shorthand]["labelName"]]
210  elif rcdName == "TrackerAlignmentErrorExtendedRcd" and condPars[0] == "zeroAPE":
211  raise AllInOneError("Please specify either zeroAPE_phase0 or zeroAPE_phase1")
212  #can probably make zeroAPE an alias of zeroAPE_phase1 at some point,
213  #but not sure if now is the time
214  else:
215  msg = ("In section [%s]: '%s' is used with '%s', "
216  "which is an unknown shorthand for '%s'. Either "
217  "provide at least a connect_string and a tag or "
218  "use a known shorthand.\n"
219  %(theSection, option, condPars[0], rcdName))
220  if rcdName in self.condShorts:
221  msg += "Known shorthands for '%s':\n"%(rcdName)
222  theShorts = self.condShorts[rcdName]
223  knownShorts = [("\t"+key+": "
224  +theShorts[key]["connectString"]+","
225  +theShorts[key]["tagName"]+","
226  +theShorts[key]["labelName"]) \
227  for key in theShorts]
228  msg+="\n".join(knownShorts)
229  else:
230  msg += ("There are no known shorthands for '%s'."
231  %(rcdName))
232  raise AllInOneError(msg)
233  if len( condPars ) == 2:
234  condPars.append( "" )
235  if len(condPars) > 3:
236  msg = ("In section [%s]: '%s' is used with too many "
237  "arguments. A maximum of 3 arguments is allowed."
238  %(theSection, option))
239  raise AllInOneError(msg)
240  conditions.append({"rcdName": rcdName.strip(),
241  "connectString": condPars[0].strip(),
242  "tagName": condPars[1].strip(),
243  "labelName": condPars[2].strip()})
244 
245  rcdnames = collections.Counter(condition["rcdName"] for condition in conditions)
246  if rcdnames and max(rcdnames.values()) >= 2:
247  raise AllInOneError("Some conditions are specified multiple times (possibly through mp or hp options)!\n"
248  + ", ".join(rcdname for rcdname, count in rcdnames.items() if count >= 2))
249 
250  for condition in conditions:
251  self.__testDbExist(condition["connectString"], condition["tagName"])
252 
253  return conditions
254 
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ __shorthandExists()

def alignment.Alignment.__shorthandExists (   self,
  theRcdName,
  theShorthand 
)
private
Method which checks, if `theShorthand` is a valid shorthand for the
given `theRcdName`.

Arguments:
- `theRcdName`: String which specifies the database record.
- `theShorthand`: String which specifies the shorthand to check.

Definition at line 64 of file alignment.py.

References alignment.Alignment.condShorts.

Referenced by alignment.Alignment.__getConditions().

64  def __shorthandExists(self, theRcdName, theShorthand):
65  """Method which checks, if `theShorthand` is a valid shorthand for the
66  given `theRcdName`.
67 
68  Arguments:
69  - `theRcdName`: String which specifies the database record.
70  - `theShorthand`: String which specifies the shorthand to check.
71  """
72 
73  if (theRcdName in self.condShorts) and \
74  (theShorthand in self.condShorts[theRcdName]):
75  return True
76  else:
77  return False
78 

◆ __testDbExist()

def alignment.Alignment.__testDbExist (   self,
  dbpath,
  tagname 
)
private

Definition at line 255 of file alignment.py.

References helperFunctions.getTagsMap(), and contentValuesCheck.values.

Referenced by alignment.Alignment.__getConditions().

255  def __testDbExist(self, dbpath, tagname):
256  if dbpath.startswith("sqlite_file:"):
257  if not os.path.exists( dbpath.split("sqlite_file:")[1] ):
258  raise AllInOneError("could not find file: '%s'"%dbpath.split("sqlite_file:")[1])
259  elif tagname not in getTagsMap(dbpath).values():
260  raise AllInOneError("{} does not exist in {}".format(tagname, dbpath))
261 

◆ getConditions()

def alignment.Alignment.getConditions (   self)
This function creates the configuration snippet to override
   global tag conditions.

Definition at line 281 of file alignment.py.

References alignment.Alignment.conditions, and helperFunctions.replaceByMap().

281  def getConditions(self):
282  """This function creates the configuration snippet to override
283  global tag conditions.
284  """
285  if len( self.conditions ):
286  loadCond = ("\nimport CalibTracker.Configuration."
287  "Common.PoolDBESSource_cfi\n")
288  for cond in self.conditions:
289  if not cond["labelName"] == "":
290  temp = configTemplates.conditionsTemplate.replace(
291  "tag = cms.string('.oO[tagName]Oo.')",
292  ("tag = cms.string('.oO[tagName]Oo.'),"
293  "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
294  else:
295  temp = configTemplates.conditionsTemplate
296  loadCond += replaceByMap( temp, cond )
297  else:
298  loadCond = ""
299  return loadCond
300 
def replaceByMap(target, the_map)
— Helpers —############################

◆ getRepMap()

def alignment.Alignment.getRepMap (   self)

Definition at line 270 of file alignment.py.

References alignment.Alignment.color, alignment.Alignment.globaltag, AlignableObjectId::entry.name, alignment.Alignment.name, TrackerSectorStruct.name, MuonGeometrySanityCheckPoint.name, classes.MonitorData.name, classes.OutputData.name, geometry.Structure.name, plotscripts.SawTeethFunction.name, alignment.Alignment.runGeomComp, alignment.Alignment.style, classes.PlotData.title, alignment.Alignment.title, and Geometry.title.

Referenced by overlapValidation.OverlapValidation.appendToMerge(), trackSplittingValidation.TrackSplittingValidation.appendToMerge(), primaryVertexResolution.PrimaryVertexResolution.appendToMerge(), primaryVertexValidation.PrimaryVertexValidation.appendToMerge(), offlineValidation.OfflineValidation.appendToMerge(), overlapValidation.OverlapValidation.appendToPlots(), trackSplittingValidation.TrackSplittingValidation.appendToPlots(), primaryVertexResolution.PrimaryVertexResolution.appendToPlots(), primaryVertexValidation.PrimaryVertexValidation.appendToPlots(), zMuMuValidation.ZMuMuValidation.appendToPlots(), geometryComparison.GeometryComparison.createConfiguration(), genericValidation.GenericValidationData.createConfiguration(), genericValidation.GenericValidationData.createCrabCfg(), geometryComparison.GeometryComparison.createScript(), genericValidation.GenericValidationData.createScript(), genericValidation.ParallelValidation.doMerge(), zMuMuValidation.ZMuMuValidation.filesToCompare(), genericValidation.GenericValidationData.filesToCompare(), and plottingOptions.PlottingOptionsTrackSplitting.validsubdets().

270  def getRepMap( self ):
271  result = {
272  "name": self.name,
273  "title": self.title,
274  "color": self.color,
275  "style": self.style,
276  "runGeomComp": self.runGeomComp,
277  "GlobalTag": self.globaltag
278  }
279  return result
280 

◆ restrictTo()

def alignment.Alignment.restrictTo (   self,
  restriction 
)

Definition at line 262 of file alignment.py.

References alignment.Alignment.mode, GeneralPurposeTrackAnalyzer.mode, DMRChecker.mode, and svgfig.Poly.mode.

262  def restrictTo( self, restriction ):
263  result = []
264  if not restriction == None:
265  for mode in self.mode:
266  if mode in restriction:
267  result.append( mode )
268  self.mode = result
269 

Member Data Documentation

◆ color

alignment.Alignment.color

◆ conditions

alignment.Alignment.conditions

Definition at line 56 of file alignment.py.

Referenced by alignment.Alignment.getConditions().

◆ condShorts

dictionary alignment.Alignment.condShorts
static
Initial value:
= {
"TrackerAlignmentErrorExtendedRcd": {
"zeroAPE_phase0": {
"connectString":("frontier://FrontierProd"
"/CMS_CONDITIONS"),
"tagName": "TrackerIdealGeometryErrorsExtended210_mc",
"labelName": ""
},
"zeroAPE_phase1": {
"connectString":("frontier://FrontierProd"
"/CMS_CONDITIONS"),
"tagName": "TrackerAlignmentErrorsExtended_Upgrade2017_design_v0",
"labelName": ""
},
},
"TrackerSurfaceDeformationRcd": {
"zeroDeformations": {
"connectString":("frontier://FrontierProd"
"/CMS_CONDITIONS"),
"tagName": "TrackerSurfaceDeformations_zero",
"labelName": ""
},
},
}

Definition at line 11 of file alignment.py.

Referenced by alignment.Alignment.__getConditions(), and alignment.Alignment.__shorthandExists().

◆ globaltag

alignment.Alignment.globaltag

◆ mode

alignment.Alignment.mode

Definition at line 268 of file alignment.py.

Referenced by alignment.Alignment.restrictTo().

◆ name

alignment.Alignment.name

Definition at line 43 of file alignment.py.

Referenced by ElectronMVAID.ElectronMVAID.__call__(), FWLite.ElectronMVAID.__call__(), dirstructure.Directory.__create_pie_image(), DisplayManager.DisplayManager.__del__(), dqm_interfaces.DirID.__eq__(), dirstructure.Directory.__get_full_path(), dirstructure.Comparison.__get_img_name(), dataset.Dataset.__getDataType(), dataset.Dataset.__getFileInfoList(), dirstructure.Comparison.__make_image(), core.autovars.NTupleVariable.__repr__(), core.autovars.NTupleObjectType.__repr__(), core.autovars.NTupleObject.__repr__(), core.autovars.NTupleCollection.__repr__(), dirstructure.Directory.__repr__(), dqm_interfaces.DirID.__repr__(), dirstructure.Comparison.__repr__(), config.Service.__setattr__(), config.CFG.__str__(), counter.Counter.__str__(), average.Average.__str__(), FWLite.WorkingPoints._reformat_cut_definitions(), core.autovars.NTupleObjectType.addSubObjects(), core.autovars.NTupleObjectType.addVariables(), core.autovars.NTupleObjectType.allVars(), dataset.CMSDataset.buildListOfFiles(), dataset.LocalDataset.buildListOfFiles(), dataset.CMSDataset.buildListOfFilesDBS(), dirstructure.Directory.calcStats(), genericValidation.GenericValidationData.cfgName(), crabFunctions.CrabTask.crabConfig(), crabFunctions.CrabTask.crabFolder(), genericValidation.GenericValidationData.createCrabCfg(), geometryComparison.GeometryComparison.createScript(), genericValidation.GenericValidationData.createScript(), validation.Sample.digest(), python.rootplot.utilities.Hist.divide(), python.rootplot.utilities.Hist.divide_wilson(), DisplayManager.DisplayManager.Draw(), TreeCrawler.Package.dump(), core.autovars.NTupleVariable.fillBranch(), core.autovars.NTupleObject.fillBranches(), core.autovars.NTupleCollection.fillBranchesScalar(), core.autovars.NTupleCollection.fillBranchesVector(), core.autovars.NTupleCollection.get_cpp_declaration(), core.autovars.NTupleCollection.get_cpp_wrapper_class(), core.autovars.NTupleCollection.get_py_wrapper_class(), utils.StatisticalTest.get_status(), production_tasks.Task.getname(), dataset.CMSDataset.getPrimaryDatasetEntries(), dataset.PrivateDataset.getPrimaryDatasetEntries(), primaryVertexResolution.PrimaryVertexResolution.getRepMap(), primaryVertexValidation.PrimaryVertexValidation.getRepMap(), zMuMuValidation.ZMuMuValidation.getRepMap(), alignment.Alignment.getRepMap(), genericValidation.GenericValidationData.getRepMap(), crabFunctions.CrabTask.handleNoState(), VIDSelectorBase.VIDSelectorBase.initialize(), crabFunctions.CrabTask.isData(), personalPlayback.Applet.log(), core.autovars.NTupleVariable.makeBranch(), core.autovars.NTupleObject.makeBranches(), core.autovars.NTupleCollection.makeBranchesScalar(), core.autovars.NTupleCollection.makeBranchesVector(), dirstructure.Directory.print_report(), dataset.BaseDataset.printInfo(), dataset.Dataset.printInfo(), crabFunctions.CrabTask.resubmit_failed(), production_tasks.MonitorJobs.run(), python.rootplot.utilities.Hist.TGraph(), python.rootplot.utilities.Hist.TH1F(), crabFunctions.CrabTask.update(), crabFunctions.CrabTask.updateJobStats(), counter.Counter.write(), and average.Average.write().

◆ runGeomComp

alignment.Alignment.runGeomComp

Definition at line 54 of file alignment.py.

Referenced by alignment.Alignment.getRepMap().

◆ style

alignment.Alignment.style

◆ title