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
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',
'mp_APEs',
'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",
"mp_APEs",
"hp",
"hp_alignments",
"hp_deformations",
"sm",
"sm_alignments",
"sm_deformations"):
83 matches = [re.match(_, option)
for _
in (
"^(..)$",
"^(..)_alignments$",
"^(..)_deformations$",
"^(..)_APEs$")]
84 assert sum(
bool(_)
for _
in matches) == 1, option
85 condPars = theConfig.get(theSection, option).
split(
",")
86 condPars = [_.strip()
for _
in condPars]
90 APEs = {
"hp":
False,
"mp":
True}[option]
95 option = matches[1].
group(1)
100 option = matches[2].
group(1)
105 option = matches[3].
group(1)
110 if len(condPars) == 1:
113 elif len(condPars) == 2:
114 number, jobm = condPars
116 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally jobm index)".
format(option))
118 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/{}{}/".
format(option, number)
119 if not os.path.exists(folder):
121 folder = os.path.join(folder,
"jobData")
124 for filename
in os.listdir(folder):
125 if re.match(
"jobm([0-9]*)", filename)
and os.path.isdir(os.path.join(folder, filename)):
126 jobmfolders.add(filename)
127 if len(jobmfolders) == 0:
129 elif len(jobmfolders) == 1:
130 folder = os.path.join(folder, jobmfolders.pop())
133 "Multiple jobm or jobm(number) folders in {}\n".
format(folder)
134 +
", ".
join(jobmfolders) +
"\n" 135 +
"Please specify 0 for jobm, or a number for one of the others." 138 folder = os.path.join(folder,
"jobm")
139 if os.path.exists(folder +
"0"):
140 raise AllInOneError(
"Not set up to handle a folder named jobm0")
142 folder = os.path.join(folder,
"jobm{}".
format(jobm))
144 dbfile = os.path.join(folder,
"alignments_MP.db")
145 if not os.path.exists(dbfile):
146 raise AllInOneError(
"No file {}. Maybe your alignment folder is corrupted, or maybe you specified the wrong jobm?".
format(dbfile))
148 elif option
in (
"hp",
"sm"):
149 if len(condPars) == 1:
152 elif len(condPars) == 2:
153 number, iteration = condPars
155 raise AllInOneError(
"Up to 2 arguments accepted for {} (job number, and optionally iteration)".
format(option))
156 folder =
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy/alignments/{}{}".
format(option, number)
157 if not os.path.exists(folder):
159 if iteration
is None:
160 for filename
in os.listdir(folder):
161 match = re.match(
"alignments_iter([0-9]*).db", filename)
163 if iteration
is None or int(match.group(1)) > iteration:
164 iteration =
int(match.group(1))
165 if iteration
is None:
167 dbfile = os.path.join(folder,
"alignments_iter{}.db".
format(iteration))
168 if not os.path.exists(dbfile):
180 conditions.append({
"rcdName":
"TrackerAlignmentRcd",
181 "connectString":
"sqlite_file:"+dbfile,
182 "tagName":
"Alignments",
185 conditions.append({
"rcdName":
"TrackerSurfaceDeformationRcd",
186 "connectString":
"sqlite_file:"+dbfile,
187 "tagName":
"Deformations",
190 conditions.append({
"rcdName":
"TrackerAlignmentErrorExtendedRcd",
191 "connectString":
"sqlite_file:"+dbfile,
192 "tagName":
"AlignmentErrorsExtended",
195 elif option.startswith(
"condition " ):
196 rcdName = option.split(
"condition " )[1]
197 condPars = theConfig.get( theSection, option ).
split(
"," )
198 if len(condPars) == 1:
199 if len(condPars[0])==0:
200 msg = (
"In section [%s]: '%s' is used with too few " 201 "arguments. A connect_string and a tag are " 202 "required!"%(theSection, option))
205 shorthand = condPars[0]
207 self.
condShorts[rcdName][shorthand][
"connectString"],
208 self.
condShorts[rcdName][shorthand][
"tagName"],
209 self.
condShorts[rcdName][shorthand][
"labelName"]]
210 elif rcdName ==
"TrackerAlignmentErrorExtendedRcd" and condPars[0] ==
"zeroAPE":
211 raise AllInOneError(
"Please specify either zeroAPE_phase0 or zeroAPE_phase1")
215 msg = (
"In section [%s]: '%s' is used with '%s', " 216 "which is an unknown shorthand for '%s'. Either " 217 "provide at least a connect_string and a tag or " 218 "use a known shorthand.\n" 219 %(theSection, option, condPars[0], rcdName))
221 msg +=
"Known shorthands for '%s':\n"%(rcdName)
223 knownShorts = [(
"\t"+key+
": " 224 +theShorts[key][
"connectString"]+
"," 225 +theShorts[key][
"tagName"]+
"," 226 +theShorts[key][
"labelName"]) \
227 for key
in theShorts]
228 msg+=
"\n".
join(knownShorts)
230 msg += (
"There are no known shorthands for '%s'." 233 if len( condPars ) == 2:
234 condPars.append(
"" )
235 if len(condPars) > 3:
236 msg = (
"In section [%s]: '%s' is used with too many " 237 "arguments. A maximum of 3 arguments is allowed." 238 %(theSection, option))
240 conditions.append({
"rcdName": rcdName.strip(),
241 "connectString": condPars[0].
strip(),
242 "tagName": condPars[1].
strip(),
243 "labelName": condPars[2].
strip()})
245 rcdnames = collections.Counter(condition[
"rcdName"]
for condition
in conditions)
246 if rcdnames
and max(rcdnames.values()) >= 2:
247 raise AllInOneError(
"Some conditions are specified multiple times (possibly through mp or hp options)!\n" 248 +
", ".
join(rcdname
for rcdname, count
in rcdnames.items()
if count >= 2))
250 for condition
in conditions:
251 self.
__testDbExist(condition[
"connectString"], condition[
"tagName"])
256 if dbpath.startswith(
"sqlite_file:"):
257 if not os.path.exists( dbpath.split(
"sqlite_file:")[1] ):
258 raise AllInOneError(
"could not find file: '%s'"%dbpath.split(
"sqlite_file:")[1])
264 if not restriction ==
None:
265 for mode
in self.
mode:
266 if mode
in restriction:
267 result.append( mode )
282 """This function creates the configuration snippet to override 283 global tag conditions. 286 loadCond = (
"\nimport CalibTracker.Configuration." 287 "Common.PoolDBESSource_cfi\n")
289 if not cond[
"labelName"] ==
"":
290 temp = configTemplates.conditionsTemplate.replace(
291 "tag = cms.string('.oO[tagName]Oo.')",
292 (
"tag = cms.string('.oO[tagName]Oo.')," 293 "\nlabel = cms.untracked.string('.oO[labelName]Oo.')"))
295 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 —############################
def split(sequence, size)
static std::string join(char **cmd)
def __init__(self, name, config, runGeomComp="1")