1 from __future__
import absolute_import
6 from .
import configTemplates
7 from .helperFunctions
import parsecolor, parsestyle, replaceByMap, clean_name, getTagsMap
8 from .TkAlExceptions
import AllInOneError
13 "TrackerAlignmentErrorExtendedRcd": {
15 "connectString":(
"frontier://FrontierProd"
17 "tagName":
"TrackerIdealGeometryErrorsExtended210_mc",
21 "connectString":(
"frontier://FrontierProd"
23 "tagName":
"TrackerAlignmentErrorsExtended_Upgrade2017_design_v0",
27 "TrackerSurfaceDeformationRcd": {
29 "connectString":(
"frontier://FrontierProd"
31 "tagName":
"TrackerSurfaceDeformations_zero",
36 def __init__(self, name, config, runGeomComp = "1"):
37 section =
"alignment:%s"%name
38 if not config.has_section( section ):
39 raise AllInOneError(
"section %s not found. Please define the "
41 config.checkInput(section,
42 knownSimpleOptions = [
'globaltag',
'style',
'color',
'title',
'mp',
'mp_alignments',
'mp_deformations',
'mp_APEs',
'hp',
'hp_alignments',
'hp_deformations',
'sm',
'sm_alignments',
'sm_deformations'],
43 knownKeywords = [
'condition'])
45 if config.exists(section,
"title"):
46 self.
title = config.get(section,
"title")
49 if (
int(runGeomComp) != 1):
50 self.
name +=
"_run" + runGeomComp
51 self.
title +=
" run " + runGeomComp
53 msg =
"The characters '|', '\"', and ',' cannot be used in the alignment title!"
59 self.
color = config.get(section,
"color")
60 self.
style = config.get(section,
"style")
66 """Method which checks, if `theShorthand` is a valid shorthand for the
70 - `theRcdName`: String which specifies the database record.
71 - `theShorthand`: String which specifies the shorthand to check.
82 for option
in theConfig.options( theSection ):
83 if option
in (
"mp",
"mp_alignments",
"mp_deformations",
"mp_APEs",
"hp",
"hp_alignments",
"hp_deformations",
"sm",
"sm_alignments",
"sm_deformations"):
84 matches = [re.match(_, option)
for _
in (
"^(..)$",
"^(..)_alignments$",
"^(..)_deformations$",
"^(..)_APEs$")]
85 assert sum(
bool(_)
for _
in matches) == 1, option
86 condPars = theConfig.get(theSection, option).
split(
",")
87 condPars = [_.strip()
for _
in condPars]
91 APEs = {
"hp":
False,
"mp":
True}[option]
96 option = matches[1].
group(1)
101 option = matches[2].
group(1)
106 option = matches[3].
group(1)
111 if len(condPars) == 1:
114 elif len(condPars) == 2:
115 number, jobm = condPars
117 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally jobm index)".
format(option))
119 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/{}{}/".
format(option, number)
120 if not os.path.exists(folder):
122 folder = os.path.join(folder,
"jobData")
125 for filename
in os.listdir(folder):
126 if re.match(
"jobm([0-9]*)", filename)
and os.path.isdir(os.path.join(folder, filename)):
127 jobmfolders.add(filename)
128 if len(jobmfolders) == 0:
130 elif len(jobmfolders) == 1:
131 folder = os.path.join(folder, jobmfolders.pop())
134 "Multiple jobm or jobm(number) folders in {}\n".
format(folder)
135 +
", ".
join(jobmfolders) +
"\n"
136 +
"Please specify 0 for jobm, or a number for one of the others."
139 folder = os.path.join(folder,
"jobm")
140 if os.path.exists(folder +
"0"):
141 raise AllInOneError(
"Not set up to handle a folder named jobm0")
143 folder = os.path.join(folder,
"jobm{}".
format(jobm))
145 dbfile = os.path.join(folder,
"alignments_MP.db")
146 if not os.path.exists(dbfile):
147 raise AllInOneError(
"No file {}. Maybe your alignment folder is corrupted, or maybe you specified the wrong jobm?".
format(dbfile))
149 elif option
in (
"hp",
"sm"):
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):
181 conditions.append({
"rcdName":
"TrackerAlignmentRcd",
182 "connectString":
"sqlite_file:"+dbfile,
183 "tagName":
"Alignments",
186 conditions.append({
"rcdName":
"TrackerSurfaceDeformationRcd",
187 "connectString":
"sqlite_file:"+dbfile,
188 "tagName":
"Deformations",
191 conditions.append({
"rcdName":
"TrackerAlignmentErrorExtendedRcd",
192 "connectString":
"sqlite_file:"+dbfile,
193 "tagName":
"AlignmentErrorsExtended",
196 elif option.startswith(
"condition " ):
197 rcdName = option.split(
"condition " )[1]
198 condPars = theConfig.get( theSection, option ).
split(
"," )
199 if len(condPars) == 1:
200 if len(condPars[0])==0:
201 msg = (
"In section [%s]: '%s' is used with too few "
202 "arguments. A connect_string and a tag are "
203 "required!"%(theSection, option))
206 shorthand = condPars[0]
208 self.
condShorts[rcdName][shorthand][
"connectString"],
209 self.
condShorts[rcdName][shorthand][
"tagName"],
210 self.
condShorts[rcdName][shorthand][
"labelName"]]
211 elif rcdName ==
"TrackerAlignmentErrorExtendedRcd" and condPars[0] ==
"zeroAPE":
212 raise AllInOneError(
"Please specify either zeroAPE_phase0 or zeroAPE_phase1")
216 msg = (
"In section [%s]: '%s' is used with '%s', "
217 "which is an unknown shorthand for '%s'. Either "
218 "provide at least a connect_string and a tag or "
219 "use a known shorthand.\n"
220 %(theSection, option, condPars[0], rcdName))
222 msg +=
"Known shorthands for '%s':\n"%(rcdName)
224 knownShorts = [(
"\t"+key+
": "
225 +theShorts[key][
"connectString"]+
","
226 +theShorts[key][
"tagName"]+
","
227 +theShorts[key][
"labelName"]) \
228 for key
in theShorts]
229 msg+=
"\n".
join(knownShorts)
231 msg += (
"There are no known shorthands for '%s'."
234 if len( condPars ) == 2:
235 condPars.append(
"" )
236 if len(condPars) > 3:
237 msg = (
"In section [%s]: '%s' is used with too many "
238 "arguments. A maximum of 3 arguments is allowed."
239 %(theSection, option))
241 conditions.append({
"rcdName": rcdName.strip(),
242 "connectString": condPars[0].
strip(),
243 "tagName": condPars[1].
strip(),
244 "labelName": condPars[2].
strip()})
246 rcdnames = collections.Counter(condition[
"rcdName"]
for condition
in conditions)
247 if rcdnames
and max(rcdnames.values()) >= 2:
248 raise AllInOneError(
"Some conditions are specified multiple times (possibly through mp or hp options)!\n"
249 +
", ".
join(rcdname
for rcdname, count
in six.iteritems(rcdnames)
if count >= 2))
251 for condition
in conditions:
252 self.
__testDbExist(condition[
"connectString"], condition[
"tagName"])
257 if dbpath.startswith(
"sqlite_file:"):
258 if not os.path.exists( dbpath.split(
"sqlite_file:")[1] ):
259 raise AllInOneError(
"could not find file: '%s'"%dbpath.split(
"sqlite_file:")[1])
265 if not restriction ==
None:
266 for mode
in self.
mode:
267 if mode
in restriction:
268 result.append( mode )
283 """This function creates the configuration snippet to override
284 global tag conditions.
287 loadCond = (
"\nimport CalibTracker.Configuration."
288 "Common.PoolDBESSource_cfi\n")
290 if not cond[
"labelName"] ==
"":
291 temp = configTemplates.conditionsTemplate.replace(
292 "tag = cms.string('.oO[tagName]Oo.')",
293 (
"tag = cms.string('.oO[tagName]Oo.'),"
294 "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
296 temp = configTemplates.conditionsTemplate