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