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