test
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 configTemplates
2 from helperFunctions import replaceByMap, parsecolor, parsestyle
3 import os
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 
48  self.color = config.get(section,"color")
49  self.style = config.get(section,"style")
50 
51  self.color = str(parsecolor(self.color))
52  self.style = str(parsestyle(self.style))
53 
54  def __shorthandExists(self, theRcdName, theShorthand):
55  """Method which checks, if `theShorthand` is a valid shorthand for the
56  given `theRcdName`.
57 
58  Arguments:
59  - `theRcdName`: String which specifies the database record.
60  - `theShorthand`: String which specifies the shorthand to check.
61  """
62 
63  if (theRcdName in self.condShorts) and \
64  (theShorthand in self.condShorts[theRcdName]):
65  return True
66  else:
67  return False
68 
69 
70  def __getConditions( self, theConfig, theSection ):
71  conditions = []
72  for option in theConfig.options( theSection ):
73  if option.startswith( "condition " ):
74  rcdName = option.split( "condition " )[1]
75  condPars = theConfig.get( theSection, option ).split( "," )
76  if len(condPars) == 1:
77  if len(condPars[0])==0:
78  msg = ("In section [%s]: '%s' is used with too few "
79  "arguments. A connect_string and a tag are "
80  "required!"%(theSection, option))
81  raise AllInOneError(msg)
82  elif self.__shorthandExists(rcdName, condPars[0]):
83  shorthand = condPars[0]
84  condPars = [
85  self.condShorts[rcdName][shorthand]["connectString"],
86  self.condShorts[rcdName][shorthand]["tagName"],
87  self.condShorts[rcdName][shorthand]["labelName"]]
88  else:
89  msg = ("In section [%s]: '%s' is used with '%s', "
90  "which is an unknown shorthand for '%s'. Either "
91  "provide at least a connect_string and a tag or "
92  "use a known shorthand.\n"
93  %(theSection, option, condPars[0], rcdName))
94  if rcdName in self.condShorts:
95  msg += "Known shorthands for '%s':\n"%(rcdName)
96  theShorts = self.condShorts[rcdName]
97  knownShorts = [("\t"+key+": "
98  +theShorts[key]["connectString"]+","
99  +theShorts[key]["tagName"]+","
100  +theShorts[key]["labelName"]) \
101  for key in theShorts]
102  msg+="\n".join(knownShorts)
103  else:
104  msg += ("There are no known shorthands for '%s'."
105  %(rcdName))
106  raise AllInOneError(msg)
107  if len( condPars ) == 2:
108  condPars.append( "" )
109  if len(condPars) > 3:
110  msg = ("In section [%s]: '%s' is used with too many "
111  "arguments. A maximum of 3 arguments is allowed."
112  %(theSection, option))
113  raise AllInOneError(msg)
114  conditions.append({"rcdName": rcdName.strip(),
115  "connectString": condPars[0].strip(),
116  "tagName": condPars[1].strip(),
117  "labelName": condPars[2].strip()})
118  return conditions
119 
120  def __testDbExist(self, dbpath):
121  #FIXME delete return to end train debuging
122  return
123  if not dbpath.startswith("sqlite_file:"):
124  print "WARNING: could not check existence for",dbpath
125  else:
126  if not os.path.exists( dbpath.split("sqlite_file:")[1] ):
127  raise "could not find file: '%s'"%dbpath.split("sqlite_file:")[1]
128 
129  def restrictTo( self, restriction ):
130  result = []
131  if not restriction == None:
132  for mode in self.mode:
133  if mode in restriction:
134  result.append( mode )
135  self.mode = result
136 
137  def getRepMap( self ):
138  result = {
139  "name": self.name,
140  "title": self.title,
141  "color": self.color,
142  "style": self.style,
143  "runGeomComp": self.runGeomComp,
144  "GlobalTag": self.globaltag
145  }
146  return result
147 
148  def getConditions(self):
149  """This function creates the configuration snippet to override
150  global tag conditions.
151  """
152  if len( self.conditions ):
153  loadCond = ("\nimport CalibTracker.Configuration."
154  "Common.PoolDBESSource_cfi\n")
155  for cond in self.conditions:
156  if not cond["labelName"] == "":
157  temp = configTemplates.conditionsTemplate.replace(
158  "tag = cms.string('.oO[tagName]Oo.')",
159  ("tag = cms.string('.oO[tagName]Oo.'),"
160  "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
161  else:
162  temp = configTemplates.conditionsTemplate
163  loadCond += replaceByMap( temp, cond )
164  else:
165  loadCond = ""
166  return loadCond
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def replaceByMap
— Helpers —############################
double split
Definition: MVATrainer.cc:139