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