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

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', '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 __getConditions(self, theConfig, theSection)
Definition: alignment.py:79
def parsestyle(style)
def parsecolor(color)
#define str(s)
def __init__(self, name, config, runGeomComp="1")
Definition: alignment.py:35

Member Function Documentation

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

Definition at line 79 of file alignment.py.

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

Definition at line 242 of file alignment.py.

References helperFunctions.conddb().

Referenced by alignment.Alignment.__getConditions().

242  def __testDbExist(self, dbpath, tagname):
243  if dbpath.startswith("sqlite_file:"):
244  if not os.path.exists( dbpath.split("sqlite_file:")[1] ):
245  raise AllInOneError("could not find file: '%s'"%dbpath.split("sqlite_file:")[1])
246  elif "\n"+tagname not in conddb("--db", dbpath.split("sqlite_file:")[1], "listTags"):
247  raise AllInOneError("{} does not exist in {}".format(tagname, dbpath))
248 
def __testDbExist(self, dbpath, tagname)
Definition: alignment.py:242
def alignment.Alignment.getConditions (   self)
This function creates the configuration snippet to override
   global tag conditions.

Definition at line 268 of file alignment.py.

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

268  def getConditions(self):
269  """This function creates the configuration snippet to override
270  global tag conditions.
271  """
272  if len( self.conditions ):
273  loadCond = ("\nimport CalibTracker.Configuration."
274  "Common.PoolDBESSource_cfi\n")
275  for cond in self.conditions:
276  if not cond["labelName"] == "":
277  temp = configTemplates.conditionsTemplate.replace(
278  "tag = cms.string('.oO[tagName]Oo.')",
279  ("tag = cms.string('.oO[tagName]Oo.'),"
280  "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
281  else:
282  temp = configTemplates.conditionsTemplate
283  loadCond += replaceByMap( temp, cond )
284  else:
285  loadCond = ""
286  return loadCond
287 
def replaceByMap(target, the_map)
— Helpers —############################
def getConditions(self)
Definition: alignment.py:268
def alignment.Alignment.getRepMap (   self)

Definition at line 257 of file alignment.py.

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

Referenced by trackSplittingValidation.TrackSplittingValidation.appendToMerge(), primaryVertexValidation.PrimaryVertexValidation.appendToMerge(), offlineValidation.OfflineValidation.appendToMerge(), trackSplittingValidation.TrackSplittingValidation.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().

257  def getRepMap( self ):
258  result = {
259  "name": self.name,
260  "title": self.title,
261  "color": self.color,
262  "style": self.style,
263  "runGeomComp": self.runGeomComp,
264  "GlobalTag": self.globaltag
265  }
266  return result
267 
def getRepMap(self)
Definition: alignment.py:257
def alignment.Alignment.restrictTo (   self,
  restriction 
)

Definition at line 249 of file alignment.py.

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

249  def restrictTo( self, restriction ):
250  result = []
251  if not restriction == None:
252  for mode in self.mode:
253  if mode in restriction:
254  result.append( mode )
255  self.mode = result
256 
def restrictTo(self, restriction)
Definition: alignment.py:249

Member Data Documentation

alignment.Alignment.color
alignment.Alignment.conditions

Definition at line 56 of file alignment.py.

Referenced by alignment.Alignment.getConditions().

dictionary alignment.Alignment.condShorts
static
Initial value:
1 = {
2  "TrackerAlignmentErrorExtendedRcd": {
3  "zeroAPE_phase0": {
4  "connectString":("frontier://FrontierProd"
5  "/CMS_CONDITIONS"),
6  "tagName": "TrackerIdealGeometryErrorsExtended210_mc",
7  "labelName": ""
8  },
9  "zeroAPE_phase1": {
10  "connectString":("frontier://FrontierProd"
11  "/CMS_CONDITIONS"),
12  "tagName": "TrackerAlignmentErrorsExtended_Upgrade2017_design_v0",
13  "labelName": ""
14  },
15  },
16  "TrackerSurfaceDeformationRcd": {
17  "zeroDeformations": {
18  "connectString":("frontier://FrontierProd"
19  "/CMS_CONDITIONS"),
20  "tagName": "TrackerSurfaceDeformations_zero",
21  "labelName": ""
22  },
23  },
24  }

Definition at line 11 of file alignment.py.

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

alignment.Alignment.globaltag
alignment.Alignment.mode

Definition at line 255 of file alignment.py.

Referenced by alignment.Alignment.restrictTo().

alignment.Alignment.name

Definition at line 43 of file alignment.py.

Referenced by ElectronMVAID.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__(), core.autovars.NTupleObjectType.addSubObjects(), core.autovars.NTupleObjectType.addVariables(), core.autovars.NTupleObjectType.allVars(), 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(), primaryVertexValidation.PrimaryVertexValidation.getRepMap(), zMuMuValidation.ZMuMuValidation.getRepMap(), alignment.Alignment.getRepMap(), genericValidation.GenericValidationData.getRepMap(), crabFunctions.CrabTask.handleNoState(), VIDSelectorBase.VIDSelectorBase.initialize(), 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(), validateAlignments.ParallelMergeJob.runJob(), BeautifulSoup.SoupStrainer.searchTag(), python.rootplot.utilities.Hist.TGraph(), python.rootplot.utilities.Hist.TH1F(), crabFunctions.CrabTask.update(), crabFunctions.CrabTask.updateJobStats(), Vispa.Views.PropertyView.Property.valueChanged(), counter.Counter.write(), and average.Average.write().

alignment.Alignment.runGeomComp

Definition at line 54 of file alignment.py.

Referenced by alignment.Alignment.getRepMap().

alignment.Alignment.style