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)
 

Detailed Description

Definition at line 9 of file alignment.py.

Constructor & Destructor Documentation

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

Definition at line 34 of file alignment.py.

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

Member Function Documentation

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

Definition at line 78 of file alignment.py.

References alignment.Alignment.__shorthandExists(), alignment.Alignment.condShorts, createfilelist.int, join(), hpstanc_transforms.max, split, and digi_MixPreMix_cfi.strip.

78  def __getConditions( self, theConfig, theSection ):
79  conditions = []
80  for option in theConfig.options( theSection ):
81  if option in ("mp", "mp_alignments", "mp_deformations"):
82  condPars = theConfig.get(theSection, option).split(",")
83  condPars = [_.strip() for _ in condPars]
84  if len(condPars) == 1:
85  number, = condPars
86  jobm = None
87  elif len(condPars) == 2:
88  number, jobm = condPars
89  else:
90  raise AllInOneError("Up to 2 arguments accepted for {} (job number, and optionally jobm index)".format(option))
91 
92  if option == "mp":
93  alignments = True
94  deformations = True
95  elif option == "mp_alignments":
96  alignments = True
97  deformations = False
98  option = "mp"
99  elif option == "mp_deformations":
100  alignments = False
101  deformations = True
102  option = "mp"
103  else:
104  assert False
105 
106  folder = "/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/{}{}/".format(option, number)
107  if not os.path.exists(folder):
108  raise AllInOneError(folder+" does not exist.")
109  folder = os.path.join(folder, "jobData")
110  jobmfolders = set()
111  if jobm is None:
112  for filename in os.listdir(folder):
113  if re.match("jobm([0-9]*)", filename) and os.path.isdir(os.path.join(folder, filename)):
114  jobmfolders.add(filename)
115  if len(jobmfolders) == 0:
116  raise AllInOneError("No jobm or jobm(number) folder in {}".format(folder))
117  elif len(jobmfolders) == 1:
118  folder = os.path.join(folder, jobmfolders.pop())
119  else:
120  raise AllInOneError(
121  "Multiple jobm or jobm(number) folders in {}\n".format(folder)
122  + ", ".join(jobmfolders) + "\n"
123  + "Please specify 0 for jobm, or a number for one of the others."
124  )
125  elif jobm == "0":
126  folder = os.path.join(folder, "jobm")
127  if os.path.exists(folder + "0"):
128  raise AllInOneError("Not set up to handle a folder named jobm0")
129  else:
130  folder = os.path.join(folder, "jobm{}".format(jobm))
131 
132  dbfile = os.path.join(folder, "alignments_MP.db")
133  if not os.path.exists(dbfile):
134  raise AllInOneError("No file {}. Maybe your alignment folder is corrupted, or maybe you specified the wrong jobm?".format(dbfile))
135 
136  if alignments:
137  conditions.append({"rcdName": "TrackerAlignmentRcd",
138  "connectString": "sqlite_file:"+dbfile,
139  "tagName": "Alignments",
140  "labelName": ""})
141  if deformations:
142  conditions.append({"rcdName": "TrackerSurfaceDeformationRcd",
143  "connectString": "sqlite_file:"+dbfile,
144  "tagName": "Deformations",
145  "labelName": ""})
146 
147  elif option in ("hp", "sm"):
148  condPars = theConfig.get(theSection, option).split(",")
149  condPars = [_.strip() for _ in condPars]
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  conditions.append({"rcdName": "TrackerAlignmentRcd",
172  "connectString": "sqlite_file:"+dbfile,
173  "tagName": "Alignments",
174  "labelName": ""})
175 
176  elif option.startswith( "condition " ):
177  rcdName = option.split( "condition " )[1]
178  condPars = theConfig.get( theSection, option ).split( "," )
179  if len(condPars) == 1:
180  if len(condPars[0])==0:
181  msg = ("In section [%s]: '%s' is used with too few "
182  "arguments. A connect_string and a tag are "
183  "required!"%(theSection, option))
184  raise AllInOneError(msg)
185  elif self.__shorthandExists(rcdName, condPars[0]):
186  shorthand = condPars[0]
187  condPars = [
188  self.condShorts[rcdName][shorthand]["connectString"],
189  self.condShorts[rcdName][shorthand]["tagName"],
190  self.condShorts[rcdName][shorthand]["labelName"]]
191  elif rcdName == "TrackerAlignmentErrorExtendedRcd" and condPars[0] == "zeroAPE":
192  raise AllInOneError("Please specify either zeroAPE_phase0 or zeroAPE_phase1")
193  #can probably make zeroAPE an alias of zeroAPE_phase1 at some point,
194  #but not sure if now is the time
195  else:
196  msg = ("In section [%s]: '%s' is used with '%s', "
197  "which is an unknown shorthand for '%s'. Either "
198  "provide at least a connect_string and a tag or "
199  "use a known shorthand.\n"
200  %(theSection, option, condPars[0], rcdName))
201  if rcdName in self.condShorts:
202  msg += "Known shorthands for '%s':\n"%(rcdName)
203  theShorts = self.condShorts[rcdName]
204  knownShorts = [("\t"+key+": "
205  +theShorts[key]["connectString"]+","
206  +theShorts[key]["tagName"]+","
207  +theShorts[key]["labelName"]) \
208  for key in theShorts]
209  msg+="\n".join(knownShorts)
210  else:
211  msg += ("There are no known shorthands for '%s'."
212  %(rcdName))
213  raise AllInOneError(msg)
214  if len( condPars ) == 2:
215  condPars.append( "" )
216  if len(condPars) > 3:
217  msg = ("In section [%s]: '%s' is used with too many "
218  "arguments. A maximum of 3 arguments is allowed."
219  %(theSection, option))
220  raise AllInOneError(msg)
221  conditions.append({"rcdName": rcdName.strip(),
222  "connectString": condPars[0].strip(),
223  "tagName": condPars[1].strip(),
224  "labelName": condPars[2].strip()})
225 
226  rcdnames = collections.Counter(condition["rcdName"] for condition in conditions)
227  if rcdnames and max(rcdnames.values()) >= 2:
228  raise AllInOneError("Some conditions are specified multiple times (possibly through mp or hp options)!\n"
229  + ", ".join(rcdname for rcdname, count in rcdnames.iteritems() if count >= 2))
230 
231 
232  return conditions
233 
dictionary condShorts
Definition: alignment.py:10
def __getConditions(self, theConfig, theSection)
Definition: alignment.py:78
def __shorthandExists(self, theRcdName, theShorthand)
Definition: alignment.py:63
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 63 of file alignment.py.

References alignment.Alignment.condShorts.

Referenced by alignment.Alignment.__getConditions().

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

Definition at line 234 of file alignment.py.

234  def __testDbExist(self, dbpath):
235  #FIXME delete return to end train debuging
236  return
237  if not dbpath.startswith("sqlite_file:"):
238  print "WARNING: could not check existence for",dbpath
239  else:
240  if not os.path.exists( dbpath.split("sqlite_file:")[1] ):
241  raise "could not find file: '%s'"%dbpath.split("sqlite_file:")[1]
242 
def __testDbExist(self, dbpath)
Definition: alignment.py:234
def alignment.Alignment.getConditions (   self)
This function creates the configuration snippet to override
   global tag conditions.

Definition at line 262 of file alignment.py.

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

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

Definition at line 251 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().

251  def getRepMap( self ):
252  result = {
253  "name": self.name,
254  "title": self.title,
255  "color": self.color,
256  "style": self.style,
257  "runGeomComp": self.runGeomComp,
258  "GlobalTag": self.globaltag
259  }
260  return result
261 
def getRepMap(self)
Definition: alignment.py:251
def alignment.Alignment.restrictTo (   self,
  restriction 
)

Definition at line 243 of file alignment.py.

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

243  def restrictTo( self, restriction ):
244  result = []
245  if not restriction == None:
246  for mode in self.mode:
247  if mode in restriction:
248  result.append( mode )
249  self.mode = result
250 
def restrictTo(self, restriction)
Definition: alignment.py:243

Member Data Documentation

alignment.Alignment.color
alignment.Alignment.conditions

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

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

alignment.Alignment.globaltag
alignment.Alignment.mode

Definition at line 249 of file alignment.py.

Referenced by alignment.Alignment.restrictTo().

alignment.Alignment.name

Definition at line 42 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(), 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(), 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(), production_tasks.MonitorJobs.run(), BeautifulSoup.SoupStrainer.searchTag(), python.rootplot.utilities.Hist.TGraph(), python.rootplot.utilities.Hist.TH1F(), Vispa.Views.PropertyView.Property.valueChanged(), counter.Counter.write(), and average.Average.write().

alignment.Alignment.runGeomComp

Definition at line 53 of file alignment.py.

Referenced by alignment.Alignment.getRepMap().

alignment.Alignment.style