2 import globalDictionaries
4 from dataset
import Dataset
5 from helperFunctions
import replaceByMap
6 from TkAlExceptions
import AllInOneError
10 defaultReferenceName =
"DEFAULT"
11 def __init__(self, valName, alignment, config):
25 result = alignment.getRepMap()
28 "workdir": os.path.join(self.
general[
"workdir"],
30 "datadir": self.
general[
"datadir"],
31 "logdir": self.
general[
"logdir"],
32 "CommandLineTemplate": (
"#run configfile and post-proccess it\n"
33 "cmsRun %(cfgFile)s\n"
35 "CMSSW_BASE": os.environ[
'CMSSW_BASE'],
36 "SCRAM_ARCH": os.environ[
'SCRAM_ARCH'],
37 "alignmentName": alignment.name,
38 "condLoad": alignment.getConditions()
44 repMap = self.alignmentToValidate.getRepMap()
47 if repMap[
"file"].startswith(
"/castor/" ):
48 repMap[
"file"] =
"rfio:%(file)s"%repMap
49 elif repMap[
"file"].startswith(
"/store/" ):
50 repMap[
"file"] =
"root://eoscms.cern.ch//eos/cms%(file)s"%repMap
51 result[validationId]=
"%(file)s=%(name)s|%(color)s|%(style)s"%repMap
55 if not "." in requestId:
56 requestId +=
".%s"%GenericValidation.defaultReferenceName
57 if not requestId.split(
".")[-1]
in result:
58 msg = (
"could not find %s in reference Objects!"
59 %requestId.split(
".")[-1])
61 return result[ requestId.split(
".")[-1] ]
65 for fileName
in fileContents:
66 filePath = os.path.join( path, fileName)
67 theFile = open( filePath,
"w" )
68 theFile.write( fileContents[ fileName ] )
70 result.append( filePath )
74 self.
configFiles = GenericValidation.createFiles(self, fileContents,
76 if not schedule ==
None:
77 schedule = [os.path.join( path, cfgName)
for cfgName
in schedule]
78 for cfgName
in schedule:
80 msg = (
"scheduled %s missing in generated configfiles: %s"
84 if not cfgName
in schedule:
85 msg = (
"generated configuration %s not scheduled: %s"
92 self.
scriptFiles = GenericValidation.createFiles(self, fileContents,
106 Subclass of `GenericValidation` which is the base for validations using
110 def __init__(self, valName, alignment, config, valType,
111 addDefaults = {}, addMandatories=[]):
113 This method adds additional items to the `self.general` dictionary
114 which are only needed for validations using datasets.
117 - `valName`: String which identifies individual validation instances
118 - `alignment`: `Alignment` instance to validate
119 - `config`: `BetterConfigParser` instance which includes the
120 configuration of the validations
121 - `valType`: String which specifies the type of validation
122 - `addDefaults`: Dictionary which contains default values for individual
123 validations in addition to the general default values
124 - `addMandatories`: List which contains mandatory parameters for
125 individual validations in addition to the general
127 (currently there are no general mandatories)
130 GenericValidation.__init__(self, valName, alignment, config)
131 defaults = {
"jobmode": self.
jobmode,
139 defaults.update(addDefaults)
141 mandatories += addMandatories
142 theUpdate = config.getResultingSection(valType+
":"+self.
name,
143 defaultDict = defaults,
144 demandPars = mandatories)
145 self.general.update(theUpdate)
148 knownOpts = defaults.keys()+mandatories
150 if self.jobmode.split(
",")[0] ==
"crab" \
151 or self.__class__.__name__==
"OfflineValidationParallel":
152 knownOpts.append(
"parallelJobs")
154 ignoreOpts.append(
"parallelJobs")
155 config.checkInput(valType+
":"+self.
name,
156 knownSimpleOptions = knownOpts,
157 ignoreOptions = ignoreOpts)
159 if self.
general[
"dataset"]
not in globalDictionaries.usedDatasets:
160 globalDictionaries.usedDatasets[self.
general[
"dataset"]] =
Dataset(
164 if not self.jobmode.split(
',' )[0] ==
"crab":
166 self.
general[
"datasetDefinition"] = self.dataset.datasetSnippet(
167 jsonPath = self.
general[
"JSON"],
168 nEvents = self.
general[
"maxevents"],
169 firstRun = self.
general[
"firstRun"],
170 lastRun = self.
general[
"lastRun"],
173 except AllInOneError, e:
174 msg =
"In section [%s:%s]: "%(valType, self.
name)
178 if self.dataset.predefined():
179 msg = (
"For jobmode 'crab' you cannot use predefined datasets "
180 "(in your case: '%s')."%( self.dataset.name() ))
183 theUpdate = config.getResultingSection(valType+
":"+self.
name,
184 demandPars = [
"parallelJobs"])
185 except AllInOneError, e:
186 msg = str(e)[:-1]+
" when using 'jobmode: crab'."
188 self.general.update(theUpdate)
193 self.
general[
"lastRun"] ) = self.dataset.convertTimeToRun(
194 firstRun = self.
general[
"firstRun"],
195 lastRun = self.
general[
"lastRun"],
199 if self.
general[
"begin"] ==
None:
201 if self.
general[
"end"] ==
None:
205 if (
not self.
general[
"firstRun"] )
and \
207 self.
general[
"firstRun"] = str(
208 self.dataset.runList()[0][
"run_number"])
209 if (
not self.
general[
"lastRun"] )
and \
212 self.dataset.runList()[-1][
"run_number"])
215 msg = (
"The lower time/runrange limit ('begin'/'firstRun') "
216 "chosen is greater than the upper time/runrange limit "
217 "('end'/'lastRun').")
220 +
'-' + self.
general[
"lastRun"])
222 self.
general[
"datasetDefinition"] = self.dataset.datasetSnippet(
223 jsonPath = self.
general[
"JSON"],
224 nEvents = self.
general[
"maxevents"],
225 firstRun = self.
general[
"firstRun"],
226 lastRun = self.
general[
"lastRun"],
230 except AllInOneError, e:
231 msg =
"In section [%s:%s]: "%(valType, self.
name)
237 Method which creates a `crab.cfg` for a validation on datasets.
240 - `path`: Path at which the file will be stored.
241 - `crabCfgBaseName`: String which depends on the actual type of
242 validation calling this method.
244 crabCfgName =
"crab.%s.%s.%s.cfg"%( crabCfgBaseName, self.
name,
245 self.alignmentToValidate.name )
247 repMap[
"script"] =
"dummy_script.sh"
249 repMap[
"crabWorkingDir"] = crabCfgName.split(
'.cfg' )[0]
251 repMap[
"numberOfJobs"] = self.
general[
"parallelJobs"]
253 repMap[
"queue"] = self.jobmode.split(
',' )[1].
split(
'-q' )[1]
254 if self.dataset.dataType() ==
"mc":
255 repMap[
"McOrData"] =
"events = .oO[nEvents]Oo."
256 elif self.dataset.dataType() ==
"data":
257 repMap[
"McOrData"] =
"lumis = -1"
258 if self.jobmode.split(
',' )[0] ==
"crab":
259 print (
"For jobmode 'crab' the parameter 'maxevents' will be "
260 "ignored and all events will be processed.")
261 crabCfg = {crabCfgName:
replaceByMap( configTemplates.crabCfgTemplate,
263 return GenericValidation.createCrabCfg( self, crabCfg, path )
def replaceByMap
— Helpers —############################