CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
alignment.py
Go to the documentation of this file.
1 import os
2 import configTemplates
3 from helperFunctions import replaceByMap
4 from TkAlExceptions import AllInOneError
5 
6 class Alignment:
7  def __init__(self, name, config, runGeomComp = "1"):
8  self.condShorts = {
9  "TrackerAlignmentErrorExtendedRcd": {
10  "zeroAPE": {
11  "connectString":("frontier://FrontierProd"
12  "/CMS_CONDITIONS"),
13  "tagName": "TrackerIdealGeometryErrorsExtended210_mc",
14  "labelName": ""
15  }
16  },
17  "TrackerSurfaceDeformationRcd": {
18  "zeroDeformations": {
19  "connectString":("frontier://FrontierProd"
20  "/CMS_CONDITIONS"),
21  "tagName": "TrackerSurfaceDeformations_zero",
22  "labelName": ""
23  }
24  },
25  }
26  section = "alignment:%s"%name
27  if not config.has_section( section ):
28  raise AllInOneError("section %s not found. Please define the "
29  "alignment!"%section)
30  config.checkInput(section,
31  knownSimpleOptions = ['globaltag', 'style', 'color', 'title'],
32  knownKeywords = ['condition'])
33  self.name = name
34  if config.exists(section,"title"):
35  self.title = config.get(section,"title")
36  else:
37  self.title = self.name
38  if (int(runGeomComp) != 1):
39  self.name += "_run" + runGeomComp
40  self.title += " run " + runGeomComp
41  if "|" in self.title or "," in self.title or '"' in self.title:
42  msg = "The characters '|', '\"', and ',' cannot be used in the alignment title!"
43  raise AllInOneError(msg)
44  self.runGeomComp = runGeomComp
45  self.globaltag = config.get( section, "globaltag" )
46  self.conditions = self.__getConditions( config, section )
47  self.color = config.get(section,"color")
48  self.style = config.get(section,"style")
49 
50 
51  def __shorthandExists(self, theRcdName, theShorthand):
52  """Method which checks, if `theShorthand` is a valid shorthand for the
53  given `theRcdName`.
54 
55  Arguments:
56  - `theRcdName`: String which specifies the database record.
57  - `theShorthand`: String which specifies the shorthand to check.
58  """
59 
60  if (theRcdName in self.condShorts) and \
61  (theShorthand in self.condShorts[theRcdName]):
62  return True
63  else:
64  return False
65 
66 
67  def __getConditions( self, theConfig, theSection ):
68  conditions = []
69  for option in theConfig.options( theSection ):
70  if option.startswith( "condition " ):
71  rcdName = option.split( "condition " )[1]
72  condPars = theConfig.get( theSection, option ).split( "," )
73  if len(condPars) == 1:
74  if len(condPars[0])==0:
75  msg = ("In section [%s]: '%s' is used with too few "
76  "arguments. A connect_string and a tag are "
77  "required!"%(theSection, option))
78  raise AllInOneError(msg)
79  elif self.__shorthandExists(rcdName, condPars[0]):
80  shorthand = condPars[0]
81  condPars = [
82  self.condShorts[rcdName][shorthand]["connectString"],
83  self.condShorts[rcdName][shorthand]["tagName"],
84  self.condShorts[rcdName][shorthand]["labelName"]]
85  else:
86  msg = ("In section [%s]: '%s' is used with '%s', "
87  "which is an unknown shorthand for '%s'. Either "
88  "provide at least a connect_string and a tag or "
89  "use a known shorthand.\n"
90  %(theSection, option, condPars[0], rcdName))
91  if rcdName in self.condShorts:
92  msg += "Known shorthands for '%s':\n"%(rcdName)
93  theShorts = self.condShorts[rcdName]
94  knownShorts = [("\t"+key+": "
95  +theShorts[key]["connectString"]+","
96  +theShorts[key]["tagName"]+","
97  +theShorts[key]["labelName"]) \
98  for key in theShorts]
99  msg+="\n".join(knownShorts)
100  else:
101  msg += ("There are no known shorthands for '%s'."
102  %(rcdName))
103  raise AllInOneError(msg)
104  if len( condPars ) == 2:
105  condPars.append( "" )
106  if len(condPars) > 3:
107  msg = ("In section [%s]: '%s' is used with too many "
108  "arguments. A maximum of 3 arguments is allowed."
109  %(theSection, option))
110  raise AllInOneError(msg)
111  conditions.append({"rcdName": rcdName.strip(),
112  "connectString": condPars[0].strip(),
113  "tagName": condPars[1].strip(),
114  "labelName": condPars[2].strip()})
115  return conditions
116 
117  def __testDbExist(self, dbpath):
118  #FIXME delete return to end train debuging
119  return
120  if not dbpath.startswith("sqlite_file:"):
121  print "WARNING: could not check existence for",dbpath
122  else:
123  if not os.path.exists( dbpath.split("sqlite_file:")[1] ):
124  raise "could not find file: '%s'"%dbpath.split("sqlite_file:")[1]
125 
126  def restrictTo( self, restriction ):
127  result = []
128  if not restriction == None:
129  for mode in self.mode:
130  if mode in restriction:
131  result.append( mode )
132  self.mode = result
133 
134  def getRepMap( self ):
135  result = {
136  "name": self.name,
137  "title": self.title,
138  "color": self.color,
139  "style": self.style,
140  "runGeomComp": self.runGeomComp,
141  "GlobalTag": self.globaltag
142  }
143  return result
144 
145  def getConditions(self):
146  """This function creates the configuration snippet to override
147  global tag conditions.
148  """
149  if len( self.conditions ):
150  loadCond = ("\nimport CalibTracker.Configuration."
151  "Common.PoolDBESSource_cfi\n")
152  for cond in self.conditions:
153  if not cond["labelName"] == "":
154  temp = configTemplates.conditionsTemplate.replace(
155  "tag = cms.string('.oO[tagName]Oo.')",
156  ("tag = cms.string('.oO[tagName]Oo.'),"
157  "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
158  else:
159  temp = configTemplates.conditionsTemplate
160  loadCond += replaceByMap( temp, cond )
161  else:
162  loadCond = ""
163  return loadCond
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def replaceByMap
— Helpers —############################
double split
Definition: MVATrainer.cc:139