6 from helperFunctions
import conddb, parsecolor, parsestyle, replaceByMap, clean_name
7 from TkAlExceptions
import AllInOneError
12 "TrackerAlignmentErrorExtendedRcd": {
14 "connectString":(
"frontier://FrontierProd" 16 "tagName":
"TrackerIdealGeometryErrorsExtended210_mc",
20 "connectString":(
"frontier://FrontierProd" 22 "tagName":
"TrackerAlignmentErrorsExtended_Upgrade2017_design_v0",
26 "TrackerSurfaceDeformationRcd": {
28 "connectString":(
"frontier://FrontierProd" 30 "tagName":
"TrackerSurfaceDeformations_zero",
35 def __init__(self, name, config, runGeomComp = "1"):
36 section =
"alignment:%s"%name
37 if not config.has_section( section ):
38 raise AllInOneError(
"section %s not found. Please define the " 40 config.checkInput(section,
41 knownSimpleOptions = [
'globaltag',
'style',
'color',
'title',
'mp',
'mp_alignments',
'mp_deformations',
'hp',
'hp_alignments',
'hp_deformations',
'sm',
'sm_alignments',
'sm_deformations'],
42 knownKeywords = [
'condition'])
44 if config.exists(section,
"title"):
45 self.
title = config.get(section,
"title")
48 if (
int(runGeomComp) != 1):
49 self.
name +=
"_run" + runGeomComp
50 self.
title +=
" run " + runGeomComp
52 msg =
"The characters '|', '\"', and ',' cannot be used in the alignment title!" 58 self.
color = config.get(section,
"color")
59 self.
style = config.get(section,
"style")
65 """Method which checks, if `theShorthand` is a valid shorthand for the 69 - `theRcdName`: String which specifies the database record. 70 - `theShorthand`: String which specifies the shorthand to check. 81 for option
in theConfig.options( theSection ):
82 if option
in (
"mp",
"mp_alignments",
"mp_deformations",
"hp",
"hp_alignments",
"hp_deformations",
"sm",
"sm_alignments",
"sm_deformations"):
83 matches = [re.match(_, option)
for _
in (
"^(..)$",
"^(..)_alignments$",
"^(..)_deformations$")]
84 assert sum(
bool(_)
for _
in matches) == 1, option
85 condPars = theConfig.get(theSection, option).
split(
",")
86 condPars = [_.strip()
for _
in condPars]
93 option = matches[1].
group(1)
97 option = matches[2].
group(1)
102 if len(condPars) == 1:
105 elif len(condPars) == 2:
106 number, jobm = condPars
108 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally jobm index)".
format(option))
110 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/{}{}/".
format(option, number)
111 if not os.path.exists(folder):
113 folder = os.path.join(folder,
"jobData")
116 for filename
in os.listdir(folder):
117 if re.match(
"jobm([0-9]*)", filename)
and os.path.isdir(os.path.join(folder, filename)):
118 jobmfolders.add(filename)
119 if len(jobmfolders) == 0:
121 elif len(jobmfolders) == 1:
122 folder = os.path.join(folder, jobmfolders.pop())
125 "Multiple jobm or jobm(number) folders in {}\n".
format(folder)
126 +
", ".
join(jobmfolders) +
"\n" 127 +
"Please specify 0 for jobm, or a number for one of the others." 130 folder = os.path.join(folder,
"jobm")
131 if os.path.exists(folder +
"0"):
132 raise AllInOneError(
"Not set up to handle a folder named jobm0")
134 folder = os.path.join(folder,
"jobm{}".
format(jobm))
136 dbfile = os.path.join(folder,
"alignments_MP.db")
137 if not os.path.exists(dbfile):
138 raise AllInOneError(
"No file {}. Maybe your alignment folder is corrupted, or maybe you specified the wrong jobm?".
format(dbfile))
140 elif option
in (
"hp",
"sm"):
141 if len(condPars) == 1:
144 elif len(condPars) == 2:
145 number, iteration = condPars
147 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally iteration)".
format(option))
148 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy/alignments/{}{}".
format(option, number)
149 if not os.path.exists(folder):
151 if iteration
is None:
152 for filename
in os.listdir(folder):
153 match = re.match(
"alignments_iter([0-9]*).db", filename)
155 if iteration
is None or int(match.group(1)) > iteration:
156 iteration =
int(match.group(1))
157 if iteration
is None:
159 dbfile = os.path.join(folder,
"alignments_iter{}.db".
format(iteration))
160 if not os.path.exists(dbfile):
163 if "\nDeformations" not in conddb(
"--db", dbfile,
"listTags"):
172 conditions.append({
"rcdName":
"TrackerAlignmentRcd",
173 "connectString":
"sqlite_file:"+dbfile,
174 "tagName":
"Alignments",
177 conditions.append({
"rcdName":
"TrackerSurfaceDeformationRcd",
178 "connectString":
"sqlite_file:"+dbfile,
179 "tagName":
"Deformations",
182 elif option.startswith(
"condition " ):
183 rcdName = option.split(
"condition " )[1]
184 condPars = theConfig.get( theSection, option ).
split(
"," )
185 if len(condPars) == 1:
186 if len(condPars[0])==0:
187 msg = (
"In section [%s]: '%s' is used with too few " 188 "arguments. A connect_string and a tag are " 189 "required!"%(theSection, option))
192 shorthand = condPars[0]
194 self.
condShorts[rcdName][shorthand][
"connectString"],
195 self.
condShorts[rcdName][shorthand][
"tagName"],
196 self.
condShorts[rcdName][shorthand][
"labelName"]]
197 elif rcdName ==
"TrackerAlignmentErrorExtendedRcd" and condPars[0] ==
"zeroAPE":
198 raise AllInOneError(
"Please specify either zeroAPE_phase0 or zeroAPE_phase1")
202 msg = (
"In section [%s]: '%s' is used with '%s', " 203 "which is an unknown shorthand for '%s'. Either " 204 "provide at least a connect_string and a tag or " 205 "use a known shorthand.\n" 206 %(theSection, option, condPars[0], rcdName))
208 msg +=
"Known shorthands for '%s':\n"%(rcdName)
210 knownShorts = [(
"\t"+key+
": " 211 +theShorts[key][
"connectString"]+
"," 212 +theShorts[key][
"tagName"]+
"," 213 +theShorts[key][
"labelName"]) \
214 for key
in theShorts]
215 msg+=
"\n".
join(knownShorts)
217 msg += (
"There are no known shorthands for '%s'." 220 if len( condPars ) == 2:
221 condPars.append(
"" )
222 if len(condPars) > 3:
223 msg = (
"In section [%s]: '%s' is used with too many " 224 "arguments. A maximum of 3 arguments is allowed." 225 %(theSection, option))
227 conditions.append({
"rcdName": rcdName.strip(),
228 "connectString": condPars[0].
strip(),
229 "tagName": condPars[1].
strip(),
230 "labelName": condPars[2].
strip()})
232 rcdnames = collections.Counter(condition[
"rcdName"]
for condition
in conditions)
233 if rcdnames
and max(rcdnames.values()) >= 2:
234 raise AllInOneError(
"Some conditions are specified multiple times (possibly through mp or hp options)!\n" 235 +
", ".
join(rcdname
for rcdname, count
in six.iteritems(rcdnames)
if count >= 2))
237 for condition
in conditions:
238 self.
__testDbExist(condition[
"connectString"], condition[
"tagName"])
243 if dbpath.startswith(
"sqlite_file:"):
244 if not os.path.exists( dbpath.split(
"sqlite_file:")[1] ):
245 raise AllInOneError(
"could not find file: '%s'"%dbpath.split(
"sqlite_file:")[1])
246 elif "\n"+tagname
not in conddb(
"--db", dbpath.split(
"sqlite_file:")[1],
"listTags"):
251 if not restriction ==
None:
252 for mode
in self.
mode:
253 if mode
in restriction:
254 result.append( mode )
269 """This function creates the configuration snippet to override 270 global tag conditions. 273 loadCond = (
"\nimport CalibTracker.Configuration." 274 "Common.PoolDBESSource_cfi\n")
276 if not cond[
"labelName"] ==
"":
277 temp = configTemplates.conditionsTemplate.replace(
278 "tag = cms.string('.oO[tagName]Oo.')",
279 (
"tag = cms.string('.oO[tagName]Oo.')," 280 "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
282 temp = configTemplates.conditionsTemplate
def __getConditions(self, theConfig, theSection)
def __testDbExist(self, dbpath, tagname)
def restrictTo(self, restriction)
def __shorthandExists(self, theRcdName, theShorthand)
def replaceByMap(target, the_map)
— Helpers —############################
static std::string join(char **cmd)
def __init__(self, name, config, runGeomComp="1")