6 from helperFunctions
import conddb, parsecolor, parsestyle, replaceByMap
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',
'hp_alignments',
'hp_deformations',
'sm',
'sm_alignments',
'sm_deformations'],
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",
"hp",
"hp_alignments",
"hp_deformations",
"sm",
"sm_alignments",
"sm_deformations"):
82 matches = [re.match(_, option)
for _
in (
"^(..)$",
"^(..)_alignments$",
"^(..)_deformations$")]
83 assert sum(
bool(_)
for _
in matches) == 1, option
84 condPars = theConfig.get(theSection, option).
split(
",")
85 condPars = [_.strip()
for _
in condPars]
92 option = matches[1].
group(1)
96 option = matches[2].
group(1)
101 if len(condPars) == 1:
104 elif len(condPars) == 2:
105 number, jobm = condPars
107 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally jobm index)".
format(option))
109 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/{}{}/".
format(option, number)
110 if not os.path.exists(folder):
112 folder = os.path.join(folder,
"jobData")
115 for filename
in os.listdir(folder):
116 if re.match(
"jobm([0-9]*)", filename)
and os.path.isdir(os.path.join(folder, filename)):
117 jobmfolders.add(filename)
118 if len(jobmfolders) == 0:
120 elif len(jobmfolders) == 1:
121 folder = os.path.join(folder, jobmfolders.pop())
124 "Multiple jobm or jobm(number) folders in {}\n".
format(folder)
125 +
", ".
join(jobmfolders) +
"\n" 126 +
"Please specify 0 for jobm, or a number for one of the others." 129 folder = os.path.join(folder,
"jobm")
130 if os.path.exists(folder +
"0"):
131 raise AllInOneError(
"Not set up to handle a folder named jobm0")
133 folder = os.path.join(folder,
"jobm{}".
format(jobm))
135 dbfile = os.path.join(folder,
"alignments_MP.db")
136 if not os.path.exists(dbfile):
137 raise AllInOneError(
"No file {}. Maybe your alignment folder is corrupted, or maybe you specified the wrong jobm?".
format(dbfile))
139 elif option
in (
"hp",
"sm"):
140 if len(condPars) == 1:
143 elif len(condPars) == 2:
144 number, iteration = condPars
146 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally iteration)".
format(option))
147 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy/alignments/{}{}".
format(option, number)
148 if not os.path.exists(folder):
150 if iteration
is None:
151 for filename
in os.listdir(folder):
152 match = re.match(
"alignments_iter([0-9]*).db", filename)
154 if iteration
is None or int(match.group(1)) > iteration:
155 iteration =
int(match.group(1))
156 if iteration
is None:
158 dbfile = os.path.join(folder,
"alignments_iter{}.db".
format(iteration))
159 if not os.path.exists(dbfile):
162 if "\nDeformations" not in conddb(
"--db", dbfile,
"listTags"):
171 conditions.append({
"rcdName":
"TrackerAlignmentRcd",
172 "connectString":
"sqlite_file:"+dbfile,
173 "tagName":
"Alignments",
176 conditions.append({
"rcdName":
"TrackerSurfaceDeformationRcd",
177 "connectString":
"sqlite_file:"+dbfile,
178 "tagName":
"Deformations",
181 elif option.startswith(
"condition " ):
182 rcdName = option.split(
"condition " )[1]
183 condPars = theConfig.get( theSection, option ).
split(
"," )
184 if len(condPars) == 1:
185 if len(condPars[0])==0:
186 msg = (
"In section [%s]: '%s' is used with too few " 187 "arguments. A connect_string and a tag are " 188 "required!"%(theSection, option))
191 shorthand = condPars[0]
193 self.
condShorts[rcdName][shorthand][
"connectString"],
194 self.
condShorts[rcdName][shorthand][
"tagName"],
195 self.
condShorts[rcdName][shorthand][
"labelName"]]
196 elif rcdName ==
"TrackerAlignmentErrorExtendedRcd" and condPars[0] ==
"zeroAPE":
197 raise AllInOneError(
"Please specify either zeroAPE_phase0 or zeroAPE_phase1")
201 msg = (
"In section [%s]: '%s' is used with '%s', " 202 "which is an unknown shorthand for '%s'. Either " 203 "provide at least a connect_string and a tag or " 204 "use a known shorthand.\n" 205 %(theSection, option, condPars[0], rcdName))
207 msg +=
"Known shorthands for '%s':\n"%(rcdName)
209 knownShorts = [(
"\t"+key+
": " 210 +theShorts[key][
"connectString"]+
"," 211 +theShorts[key][
"tagName"]+
"," 212 +theShorts[key][
"labelName"]) \
213 for key
in theShorts]
214 msg+=
"\n".
join(knownShorts)
216 msg += (
"There are no known shorthands for '%s'." 219 if len( condPars ) == 2:
220 condPars.append(
"" )
221 if len(condPars) > 3:
222 msg = (
"In section [%s]: '%s' is used with too many " 223 "arguments. A maximum of 3 arguments is allowed." 224 %(theSection, option))
226 conditions.append({
"rcdName": rcdName.strip(),
227 "connectString": condPars[0].
strip(),
228 "tagName": condPars[1].
strip(),
229 "labelName": condPars[2].
strip()})
231 rcdnames = collections.Counter(condition[
"rcdName"]
for condition
in conditions)
232 if rcdnames
and max(rcdnames.values()) >= 2:
233 raise AllInOneError(
"Some conditions are specified multiple times (possibly through mp or hp options)!\n" 234 +
", ".
join(rcdname
for rcdname, count
in rcdnames.iteritems()
if count >= 2))
236 for condition
in conditions:
237 self.
__testDbExist(condition[
"connectString"], condition[
"tagName"])
242 if dbpath.startswith(
"sqlite_file:"):
243 if not os.path.exists( dbpath.split(
"sqlite_file:")[1] ):
244 raise AllInOneError(
"could not find file: '%s'"%dbpath.split(
"sqlite_file:")[1])
245 elif "\n"+tagname
not in conddb(
"--db", dbpath.split(
"sqlite_file:")[1],
"listTags"):
250 if not restriction ==
None:
251 for mode
in self.
mode:
252 if mode
in restriction:
253 result.append( mode )
268 """This function creates the configuration snippet to override 269 global tag conditions. 272 loadCond = (
"\nimport CalibTracker.Configuration." 273 "Common.PoolDBESSource_cfi\n")
275 if not cond[
"labelName"] ==
"":
276 temp = configTemplates.conditionsTemplate.replace(
277 "tag = cms.string('.oO[tagName]Oo.')",
278 (
"tag = cms.string('.oO[tagName]Oo.')," 279 "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
281 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")