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
52 result[validationId]=repMap[
"file"]
54 result[validationId]=
"%(file)s=%(name)s|%(color)s|%(style)s"%repMap
58 if not "." in requestId:
59 requestId +=
".%s"%GenericValidation.defaultReferenceName
60 if not requestId.split(
".")[-1]
in result:
61 msg = (
"could not find %s in reference Objects!"
62 %requestId.split(
".")[-1])
64 return result[ requestId.split(
".")[-1] ]
68 for fileName
in fileContents:
69 filePath = os.path.join( path, fileName)
70 theFile = open( filePath,
"w" )
71 theFile.write( fileContents[ fileName ] )
73 result.append( filePath )
77 self.
configFiles = GenericValidation.createFiles(self, fileContents,
79 if not schedule ==
None:
80 schedule = [os.path.join( path, cfgName)
for cfgName
in schedule]
81 for cfgName
in schedule:
83 msg = (
"scheduled %s missing in generated configfiles: %s"
87 if not cfgName
in schedule:
88 msg = (
"generated configuration %s not scheduled: %s"
95 self.
scriptFiles = GenericValidation.createFiles(self, fileContents,
109 Subclass of `GenericValidation` which is the base for validations using
113 def __init__(self, valName, alignment, config, valType,
114 addDefaults = {}, addMandatories=[]):
116 This method adds additional items to the `self.general` dictionary
117 which are only needed for validations using datasets.
120 - `valName`: String which identifies individual validation instances
121 - `alignment`: `Alignment` instance to validate
122 - `config`: `BetterConfigParser` instance which includes the
123 configuration of the validations
124 - `valType`: String which specifies the type of validation
125 - `addDefaults`: Dictionary which contains default values for individual
126 validations in addition to the general default values
127 - `addMandatories`: List which contains mandatory parameters for
128 individual validations in addition to the general
130 (currently there are no general mandatories)
133 GenericValidation.__init__(self, valName, alignment, config)
134 defaults = {
"jobmode": self.
jobmode,
142 defaults.update(addDefaults)
144 mandatories += addMandatories
145 theUpdate = config.getResultingSection(valType+
":"+self.
name,
146 defaultDict = defaults,
147 demandPars = mandatories)
148 self.general.update(theUpdate)
151 knownOpts = defaults.keys()+mandatories
153 if self.jobmode.split(
",")[0] ==
"crab" \
154 or self.__class__.__name__==
"OfflineValidationParallel":
155 knownOpts.append(
"parallelJobs")
157 ignoreOpts.append(
"parallelJobs")
158 config.checkInput(valType+
":"+self.
name,
159 knownSimpleOptions = knownOpts,
160 ignoreOptions = ignoreOpts)
162 if self.
general[
"dataset"]
not in globalDictionaries.usedDatasets:
163 globalDictionaries.usedDatasets[self.
general[
"dataset"]] =
Dataset(
167 if not self.jobmode.split(
',' )[0] ==
"crab":
169 self.
general[
"datasetDefinition"] = self.dataset.datasetSnippet(
170 jsonPath = self.
general[
"JSON"],
171 nEvents = self.
general[
"maxevents"],
172 firstRun = self.
general[
"firstRun"],
173 lastRun = self.
general[
"lastRun"],
176 except AllInOneError, e:
177 msg =
"In section [%s:%s]: "%(valType, self.
name)
181 if self.dataset.predefined():
182 msg = (
"For jobmode 'crab' you cannot use predefined datasets "
183 "(in your case: '%s')."%( self.dataset.name() ))
186 theUpdate = config.getResultingSection(valType+
":"+self.
name,
187 demandPars = [
"parallelJobs"])
188 except AllInOneError, e:
189 msg = str(e)[:-1]+
" when using 'jobmode: crab'."
191 self.general.update(theUpdate)
196 self.
general[
"lastRun"] ) = self.dataset.convertTimeToRun(
197 firstRun = self.
general[
"firstRun"],
198 lastRun = self.
general[
"lastRun"],
202 if self.
general[
"begin"] ==
None:
204 if self.
general[
"end"] ==
None:
208 if (
not self.
general[
"firstRun"] )
and \
210 self.
general[
"firstRun"] = str(
211 self.dataset.runList()[0][
"run_number"])
212 if (
not self.
general[
"lastRun"] )
and \
215 self.dataset.runList()[-1][
"run_number"])
218 msg = (
"The lower time/runrange limit ('begin'/'firstRun') "
219 "chosen is greater than the upper time/runrange limit "
220 "('end'/'lastRun').")
223 +
'-' + self.
general[
"lastRun"])
225 self.
general[
"datasetDefinition"] = self.dataset.datasetSnippet(
226 jsonPath = self.
general[
"JSON"],
227 nEvents = self.
general[
"maxevents"],
228 firstRun = self.
general[
"firstRun"],
229 lastRun = self.
general[
"lastRun"],
233 except AllInOneError, e:
234 msg =
"In section [%s:%s]: "%(valType, self.
name)
240 Method which creates a `crab.cfg` for a validation on datasets.
243 - `path`: Path at which the file will be stored.
244 - `crabCfgBaseName`: String which depends on the actual type of
245 validation calling this method.
247 crabCfgName =
"crab.%s.%s.%s.cfg"%( crabCfgBaseName, self.
name,
248 self.alignmentToValidate.name )
250 repMap[
"script"] =
"dummy_script.sh"
252 repMap[
"crabWorkingDir"] = crabCfgName.split(
'.cfg' )[0]
254 repMap[
"numberOfJobs"] = self.
general[
"parallelJobs"]
256 repMap[
"queue"] = self.jobmode.split(
',' )[1].
split(
'-q' )[1]
257 if self.dataset.dataType() ==
"mc":
258 repMap[
"McOrData"] =
"events = .oO[nEvents]Oo."
259 elif self.dataset.dataType() ==
"data":
260 repMap[
"McOrData"] =
"lumis = -1"
261 if self.jobmode.split(
',' )[0] ==
"crab":
262 print (
"For jobmode 'crab' the parameter 'maxevents' will be "
263 "ignored and all events will be processed.")
264 crabCfg = {crabCfgName:
replaceByMap( configTemplates.crabCfgTemplate,
266 return GenericValidation.createCrabCfg( self, crabCfg, path )
def replaceByMap
— Helpers —############################