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 11 of file alignment.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 36 of file alignment.py.

36  def __init__(self, name, config, runGeomComp = "1"):
37  section = "alignment:%s"%name
38  if not config.has_section( section ):
39  raise AllInOneError("section %s not found. Please define the "
40  "alignment!"%section)
41  config.checkInput(section,
42  knownSimpleOptions = ['globaltag', 'style', 'color', 'title', 'mp', 'mp_alignments', 'mp_deformations', 'mp_APEs', 'hp', 'hp_alignments', 'hp_deformations', 'sm', 'sm_alignments', 'sm_deformations'],
43  knownKeywords = ['condition'])
44  self.name = clean_name(name)
45  if config.exists(section,"title"):
46  self.title = config.get(section,"title")
47  else:
48  self.title = self.name
49  if (int(runGeomComp) != 1):
50  self.name += "_run" + runGeomComp
51  self.title += " run " + runGeomComp
52  if "|" in self.title or "," in self.title or '"' in self.title:
53  msg = "The characters '|', '\"', and ',' cannot be used in the alignment title!"
54  raise AllInOneError(msg)
55  self.runGeomComp = runGeomComp
56  self.globaltag = config.get( section, "globaltag" )
57  self.conditions = self.__getConditions( config, section )
58 
59  self.color = config.get(section,"color")
60  self.style = config.get(section,"style")
61 
62  self.color = str(parsecolor(self.color))
63  self.style = str(parsestyle(self.style))
64 

Member Function Documentation

◆ __getConditions()

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

Definition at line 80 of file alignment.py.

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

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

◆ __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 65 of file alignment.py.

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

References alignment.Alignment.condShorts.

Referenced by alignment.Alignment.__getConditions().

◆ __testDbExist()

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

Definition at line 256 of file alignment.py.

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

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

Referenced by alignment.Alignment.__getConditions().

◆ getConditions()

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

Definition at line 282 of file alignment.py.

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

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

◆ getRepMap()

def alignment.Alignment.getRepMap (   self)

Definition at line 271 of file alignment.py.

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

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().

◆ restrictTo()

def alignment.Alignment.restrictTo (   self,
  restriction 
)

Definition at line 263 of file alignment.py.

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

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

Member Data Documentation

◆ color

alignment.Alignment.color

◆ conditions

alignment.Alignment.conditions

Definition at line 57 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 12 of file alignment.py.

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

◆ globaltag

alignment.Alignment.globaltag

◆ mode

alignment.Alignment.mode

Definition at line 269 of file alignment.py.

Referenced by alignment.Alignment.restrictTo().

◆ name

alignment.Alignment.name

Definition at line 44 of file alignment.py.

Referenced by ElectronMVAID.ElectronMVAID.__call__(), FWLite.ElectronMVAID.__call__(), dirstructure.Directory.__create_pie_image(), DisplayManager.DisplayManager.__del__(), dqm_interfaces.DirID.__eq__(), BeautifulSoup.Tag.__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__(), BeautifulSoup.Tag.__str__(), BeautifulSoup.SoupStrainer.__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(), BeautifulSoup.SoupStrainer.searchTag(), 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 55 of file alignment.py.

Referenced by alignment.Alignment.getRepMap().

◆ style

alignment.Alignment.style

◆ title

alignment.Alignment.title
electrons_cff.bool
bool
Definition: electrons_cff.py:393
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
helperFunctions.replaceByMap
def replaceByMap(target, the_map)
— Helpers —############################
Definition: helperFunctions.py:13
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
helperFunctions.clean_name
def clean_name(s)
Definition: helperFunctions.py:213
str
#define str(s)
Definition: TestProcessor.cc:51
helperFunctions.parsestyle
def parsestyle(style)
Definition: helperFunctions.py:136
helperFunctions.parsecolor
def parsecolor(color)
Definition: helperFunctions.py:109
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
helperFunctions.getTagsMap
def getTagsMap(db)
Definition: helperFunctions.py:201
format
watchdog.group
group
Definition: watchdog.py:82