6 from helperFunctions
import replaceByMap, parsecolor, parsestyle
7 from TkAlExceptions
import AllInOneError
11 "TrackerAlignmentErrorExtendedRcd": {
13 "connectString":(
"frontier://FrontierProd" 15 "tagName":
"TrackerIdealGeometryErrorsExtended210_mc",
19 "connectString":(
"frontier://FrontierProd" 21 "tagName":
"TrackerAlignmentErrorsExtended_Upgrade2017_design_v0",
25 "TrackerSurfaceDeformationRcd": {
27 "connectString":(
"frontier://FrontierProd" 29 "tagName":
"TrackerSurfaceDeformations_zero",
34 def __init__(self, name, config, runGeomComp = "1"):
35 section =
"alignment:%s"%name
36 if not config.has_section( section ):
37 raise AllInOneError(
"section %s not found. Please define the " 39 config.checkInput(section,
40 knownSimpleOptions = [
'globaltag',
'style',
'color',
'title',
'mp',
'mp_alignments',
'mp_deformations',
'hp',
'sm'],
41 knownKeywords = [
'condition'])
43 if config.exists(section,
"title"):
44 self.
title = config.get(section,
"title")
47 if (
int(runGeomComp) != 1):
48 self.
name +=
"_run" + runGeomComp
49 self.
title +=
" run " + runGeomComp
51 msg =
"The characters '|', '\"', and ',' cannot be used in the alignment title!" 57 self.
color = config.get(section,
"color")
58 self.
style = config.get(section,
"style")
64 """Method which checks, if `theShorthand` is a valid shorthand for the 68 - `theRcdName`: String which specifies the database record. 69 - `theShorthand`: String which specifies the shorthand to check. 80 for option
in theConfig.options( theSection ):
81 if option
in (
"mp",
"mp_alignments",
"mp_deformations"):
82 condPars = theConfig.get(theSection, option).
split(
",")
83 condPars = [_.strip()
for _
in condPars]
84 if len(condPars) == 1:
87 elif len(condPars) == 2:
88 number, jobm = condPars
90 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally jobm index)".
format(option))
95 elif option ==
"mp_alignments":
99 elif option ==
"mp_deformations":
106 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/{}{}/".
format(option, number)
107 if not os.path.exists(folder):
109 folder = os.path.join(folder,
"jobData")
112 for filename
in os.listdir(folder):
113 if re.match(
"jobm([0-9]*)", filename)
and os.path.isdir(os.path.join(folder, filename)):
114 jobmfolders.add(filename)
115 if len(jobmfolders) == 0:
117 elif len(jobmfolders) == 1:
118 folder = os.path.join(folder, jobmfolders.pop())
121 "Multiple jobm or jobm(number) folders in {}\n".
format(folder)
122 +
", ".
join(jobmfolders) +
"\n" 123 +
"Please specify 0 for jobm, or a number for one of the others." 126 folder = os.path.join(folder,
"jobm")
127 if os.path.exists(folder +
"0"):
128 raise AllInOneError(
"Not set up to handle a folder named jobm0")
130 folder = os.path.join(folder,
"jobm{}".
format(jobm))
132 dbfile = os.path.join(folder,
"alignments_MP.db")
133 if not os.path.exists(dbfile):
134 raise AllInOneError(
"No file {}. Maybe your alignment folder is corrupted, or maybe you specified the wrong jobm?".
format(dbfile))
137 conditions.append({
"rcdName":
"TrackerAlignmentRcd",
138 "connectString":
"sqlite_file:"+dbfile,
139 "tagName":
"Alignments",
142 conditions.append({
"rcdName":
"TrackerSurfaceDeformationRcd",
143 "connectString":
"sqlite_file:"+dbfile,
144 "tagName":
"Deformations",
147 elif option
in (
"hp",
"sm"):
148 condPars = theConfig.get(theSection, option).
split(
",")
149 condPars = [_.strip()
for _
in condPars]
150 if len(condPars) == 1:
153 elif len(condPars) == 2:
154 number, iteration = condPars
156 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally iteration)".
format(option))
157 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy/alignments/{}{}".
format(option, number)
158 if not os.path.exists(folder):
160 if iteration
is None:
161 for filename
in os.listdir(folder):
162 match = re.match(
"alignments_iter([0-9]*).db", filename)
164 if iteration
is None or int(match.group(1)) > iteration:
165 iteration =
int(match.group(1))
166 if iteration
is None:
168 dbfile = os.path.join(folder,
"alignments_iter{}.db".
format(iteration))
169 if not os.path.exists(dbfile):
171 conditions.append({
"rcdName":
"TrackerAlignmentRcd",
172 "connectString":
"sqlite_file:"+dbfile,
173 "tagName":
"Alignments",
176 elif option.startswith(
"condition " ):
177 rcdName = option.split(
"condition " )[1]
178 condPars = theConfig.get( theSection, option ).
split(
"," )
179 if len(condPars) == 1:
180 if len(condPars[0])==0:
181 msg = (
"In section [%s]: '%s' is used with too few " 182 "arguments. A connect_string and a tag are " 183 "required!"%(theSection, option))
186 shorthand = condPars[0]
188 self.
condShorts[rcdName][shorthand][
"connectString"],
189 self.
condShorts[rcdName][shorthand][
"tagName"],
190 self.
condShorts[rcdName][shorthand][
"labelName"]]
191 elif rcdName ==
"TrackerAlignmentErrorExtendedRcd" and condPars[0] ==
"zeroAPE":
192 raise AllInOneError(
"Please specify either zeroAPE_phase0 or zeroAPE_phase1")
196 msg = (
"In section [%s]: '%s' is used with '%s', " 197 "which is an unknown shorthand for '%s'. Either " 198 "provide at least a connect_string and a tag or " 199 "use a known shorthand.\n" 200 %(theSection, option, condPars[0], rcdName))
202 msg +=
"Known shorthands for '%s':\n"%(rcdName)
204 knownShorts = [(
"\t"+key+
": " 205 +theShorts[key][
"connectString"]+
"," 206 +theShorts[key][
"tagName"]+
"," 207 +theShorts[key][
"labelName"]) \
208 for key
in theShorts]
209 msg+=
"\n".
join(knownShorts)
211 msg += (
"There are no known shorthands for '%s'." 214 if len( condPars ) == 2:
215 condPars.append(
"" )
216 if len(condPars) > 3:
217 msg = (
"In section [%s]: '%s' is used with too many " 218 "arguments. A maximum of 3 arguments is allowed." 219 %(theSection, option))
221 conditions.append({
"rcdName": rcdName.strip(),
222 "connectString": condPars[0].
strip(),
223 "tagName": condPars[1].
strip(),
224 "labelName": condPars[2].
strip()})
226 rcdnames = collections.Counter(condition[
"rcdName"]
for condition
in conditions)
227 if rcdnames
and max(rcdnames.values()) >= 2:
228 raise AllInOneError(
"Some conditions are specified multiple times (possibly through mp or hp options)!\n" 229 +
", ".
join(rcdname
for rcdname, count
in rcdnames.iteritems()
if count >= 2))
237 if not dbpath.startswith(
"sqlite_file:"):
238 print "WARNING: could not check existence for",dbpath
240 if not os.path.exists( dbpath.split(
"sqlite_file:")[1] ):
241 raise "could not find file: '%s'"%dbpath.split(
"sqlite_file:")[1]
245 if not restriction ==
None:
246 for mode
in self.
mode:
247 if mode
in restriction:
248 result.append( mode )
263 """This function creates the configuration snippet to override 264 global tag conditions. 267 loadCond = (
"\nimport CalibTracker.Configuration." 268 "Common.PoolDBESSource_cfi\n")
270 if not cond[
"labelName"] ==
"":
271 temp = configTemplates.conditionsTemplate.replace(
272 "tag = cms.string('.oO[tagName]Oo.')",
273 (
"tag = cms.string('.oO[tagName]Oo.')," 274 "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
276 temp = configTemplates.conditionsTemplate
def __getConditions(self, theConfig, theSection)
def restrictTo(self, restriction)
def __testDbExist(self, dbpath)
def __shorthandExists(self, theRcdName, theShorthand)
def replaceByMap(target, the_map)
— Helpers —############################
static std::string join(char **cmd)
def __init__(self, name, config, runGeomComp="1")