4 import globalDictionaries
6 from dataset
import Dataset
7 from helperFunctions
import replaceByMap, addIndex, getCommandOutput2
8 from TkAlExceptions
import AllInOneError
12 defaultReferenceName =
"DEFAULT"
13 def __init__(self, valName, alignment, config, valType,
14 addDefaults = {}, addMandatories=[]):
24 defaults = {
"jobmode": self.
general[
"jobmode"],
25 "cmssw": os.environ[
'CMSSW_BASE'],
28 defaults.update(addDefaults)
30 mandatories += addMandatories
31 theUpdate = config.getResultingSection(valType+
":"+self.
name,
32 defaultDict = defaults,
33 demandPars = mandatories)
34 self.general.update(theUpdate)
40 maximumNumberJobs = 40
41 if self.
NJobs > maximumNumberJobs:
42 msg = (
"Maximum allowed number of parallel jobs "
43 +str(maximumNumberJobs)+
" exceeded!!!")
48 for character
in badcharacters:
49 if character
in self.
cmssw:
50 raise AllInOneError(
"The bad characters " + badcharacters +
" are not allowed in the cmssw\n"
51 "path name. If you really have it in such a ridiculously named location,\n"
52 "try making a symbolic link somewhere with a decent name.")
54 os.listdir(self.
cmssw)
58 if self.
cmssw == os.environ[
"CMSSW_BASE"]:
62 command = (
"cd '" + self.
cmssw +
"' && eval `scramv1 ru -sh 2> /dev/null`"
63 ' && echo "$CMSSW_BASE\n$SCRAM_ARCH\n$CMSSW_RELEASE_BASE"')
65 self.
cmssw = commandoutput[0]
70 if config.has_option(
"alternateTemplates",
"AutoAlternates"):
72 self.
AutoAlternates = json.loads(config.get(
"alternateTemplates",
"AutoAlternates").lower())
74 raise AllInOneError(
"AutoAlternates needs to be true or false, not %s" % config.get(
"alternateTemplates",
"AutoAlternates"))
76 knownOpts = defaults.keys()+mandatories
78 config.checkInput(valType+
":"+self.
name,
79 knownSimpleOptions = knownOpts,
80 ignoreOptions = ignoreOpts)
85 result = alignment.getRepMap()
88 "workdir": os.path.join(self.
general[
"workdir"],
90 "datadir": self.
general[
"datadir"],
91 "logdir": self.
general[
"logdir"],
92 "CommandLineTemplate": (
"#run configfile and post-proccess it\n"
93 "cmsRun %(cfgFile)s\n"
95 "CMSSW_BASE": self.
cmssw,
98 "alignmentName": alignment.name,
99 "condLoad": alignment.getConditions(),
105 repMap = self.alignmentToValidate.getRepMap()
108 if repMap[
"file"].startswith(
"/castor/" ):
109 repMap[
"file"] =
"rfio:%(file)s"%repMap
110 elif repMap[
"file"].startswith(
"/store/" ):
111 repMap[
"file"] =
"root://eoscms.cern.ch//eos/cms%(file)s"%repMap
113 result[validationId]=repMap[
"file"]
115 result[validationId]=
"%(file)s=%(title)s|%(color)s|%(style)s"%repMap
116 if requestId ==
None:
119 if not "." in requestId:
120 requestId +=
".%s"%GenericValidation.defaultReferenceName
121 if not requestId.split(
".")[-1]
in result:
122 msg = (
"could not find %s in reference Objects!"
123 %requestId.split(
".")[-1])
125 return result[ requestId.split(
".")[-1] ]
127 def createFiles(self, fileContents, path, repMap = None, repMaps = None):
128 """repMap: single map for all files
129 repMaps: a dict, with the filenames as the keys"""
130 if repMap
is not None and repMaps
is not None:
131 raise AllInOneError(
"createFiles can only take repMap or repMaps (or neither), not both")
133 for fileName
in fileContents:
134 filePath = os.path.join(path, fileName)
135 result.append(filePath)
137 for (i, filePathi)
in enumerate(
addIndex(filePath, self.
NJobs)):
138 theFile = open( filePathi,
"w" )
139 fileContentsi = fileContents[ fileName ]
140 if repMaps
is not None:
141 repMap = repMaps[fileName]
142 if repMap
is not None:
143 repMap.update({
"nIndex": str(i)})
145 theFile.write( fileContentsi )
151 self.
configFiles = GenericValidation.createFiles(self, fileContents,
152 path, repMap = repMap, repMaps = repMaps)
153 if not schedule ==
None:
154 schedule = [os.path.join( path, cfgName)
for cfgName
in schedule]
155 for cfgName
in schedule:
157 msg = (
"scheduled %s missing in generated configfiles: %s"
161 if not cfgName
in schedule:
162 msg = (
"generated configuration %s not scheduled: %s"
163 %(cfgName, schedule))
168 def createScript(self, fileContents, path, downloadFiles=[], repMap = None, repMaps = None):
169 self.
scriptFiles = GenericValidation.createFiles(self, fileContents,
170 path, repMap = repMap, repMaps = repMaps)
173 os.chmod(scriptwithindex,0755)
178 msg = (
"jobmode 'crab' not supported for parallel validation."
179 " Please set parallelJobs = 1.")
188 Subclass of `GenericValidation` which is the base for validations using
192 def __init__(self, valName, alignment, config, valType,
193 addDefaults = {}, addMandatories=[]):
195 This method adds additional items to the `self.general` dictionary
196 which are only needed for validations using datasets.
199 - `valName`: String which identifies individual validation instances
200 - `alignment`: `Alignment` instance to validate
201 - `config`: `BetterConfigParser` instance which includes the
202 configuration of the validations
203 - `valType`: String which specifies the type of validation
204 - `addDefaults`: Dictionary which contains default values for individual
205 validations in addition to the general default values
206 - `addMandatories`: List which contains mandatory parameters for
207 individual validations in addition to the general
211 defaults = {
"runRange":
"",
218 defaults.update(addDefaults)
219 mandatories = [
"dataset",
"maxevents" ]
220 mandatories += addMandatories
221 GenericValidation.__init__(self, valName, alignment, config, valType, defaults, mandatories)
225 if int( self.
general[
"maxevents"] ) == -1
and self.
NJobs > 1:
226 msg = (
"Maximum number of events (maxevents) not specified: "
227 "cannot use parallel jobs.")
230 tryPredefinedFirst = (
not self.jobmode.split(
',' )[0] ==
"crab" and self.
general[
"JSON"] ==
""
231 and self.
general[
"firstRun"] ==
"" and self.
general[
"lastRun"] ==
""
234 if self.
general[
"dataset"]
not in globalDictionaries.usedDatasets:
235 globalDictionaries.usedDatasets[self.
general[
"dataset"]] = {}
237 if self.
cmssw not in globalDictionaries.usedDatasets[self.
general[
"dataset"]]:
238 if globalDictionaries.usedDatasets[self.
general[
"dataset"]] != {}:
239 print (
"Warning: you use the same dataset '%s' in multiple cmssw releases.\n"
240 "This is allowed, but make sure it's not a mistake") % self.
general[
"dataset"]
241 globalDictionaries.usedDatasets[self.
general[
"dataset"]][self.
cmssw] = {
False:
None,
True:
None}
243 if globalDictionaries.usedDatasets[self.
general[
"dataset"]][self.
cmssw][tryPredefinedFirst]
is None:
245 self.
general[
"dataset"], tryPredefinedFirst = tryPredefinedFirst,
247 globalDictionaries.usedDatasets[self.
general[
"dataset"]][self.
cmssw][tryPredefinedFirst] = dataset
248 if tryPredefinedFirst
and not dataset.predefined():
249 globalDictionaries.usedDatasets[self.
general[
"dataset"]][self.
cmssw][
False] = dataset
252 self.
general[
"magneticField"] = self.dataset.magneticField()
253 self.
general[
"defaultMagneticField"] =
"MagneticField"
254 if self.
general[
"magneticField"] ==
"unknown":
255 print "Could not get the magnetic field for this dataset."
256 print "Using the default: ", self.
general[
"defaultMagneticField"]
257 self.
general[
"magneticField"] =
'.oO[defaultMagneticField]Oo.'
259 if not self.jobmode.split(
',' )[0] ==
"crab":
261 self.
general[
"datasetDefinition"] = self.dataset.datasetSnippet(
262 jsonPath = self.
general[
"JSON"],
263 firstRun = self.
general[
"firstRun"],
264 lastRun = self.
general[
"lastRun"],
267 parent = self.needParentFiles )
268 except AllInOneError, e:
269 msg =
"In section [%s:%s]: "%(valType, self.
name)
273 if self.dataset.predefined():
274 msg = (
"For jobmode 'crab' you cannot use predefined datasets "
275 "(in your case: '%s')."%( self.dataset.name() ))
278 theUpdate = config.getResultingSection(valType+
":"+self.
name,
279 demandPars = [
"parallelJobs"])
280 except AllInOneError, e:
281 msg = str(e)[:-1]+
" when using 'jobmode: crab'."
283 self.general.update(theUpdate)
288 self.
general[
"lastRun"] ) = self.dataset.convertTimeToRun(
289 firstRun = self.
general[
"firstRun"],
290 lastRun = self.
general[
"lastRun"],
294 if self.
general[
"begin"] ==
None:
296 if self.
general[
"end"] ==
None:
300 if (
not self.
general[
"firstRun"] )
and \
302 self.
general[
"firstRun"] = str(
303 self.dataset.runList()[0][
"run_number"])
304 if (
not self.
general[
"lastRun"] )
and \
307 self.dataset.runList()[-1][
"run_number"])
310 msg = (
"The lower time/runrange limit ('begin'/'firstRun') "
311 "chosen is greater than the upper time/runrange limit "
312 "('end'/'lastRun').")
315 +
'-' + self.
general[
"lastRun"])
317 self.
general[
"datasetDefinition"] = self.dataset.datasetSnippet(
318 jsonPath = self.
general[
"JSON"],
319 firstRun = self.
general[
"firstRun"],
320 lastRun = self.
general[
"lastRun"],
324 except AllInOneError, e:
325 msg =
"In section [%s:%s]: "%(valType, self.
name)
330 result = GenericValidation.getRepMap(self, alignment)
332 "%s_%s_.oO[name]Oo..root" % (self.outputBaseName, self.
name)
334 resultfile = os.path.expandvars(
replaceByMap((
"/store/caf/user/$USER/.oO[eosdir]Oo./" +
335 "%s_%s_.oO[name]Oo..root" % (self.resultBaseName, self.
name))
338 "resultFile":
".oO[resultFiles[.oO[nIndex]Oo.]]Oo.",
340 "finalResultFile": resultfile,
341 "outputFile":
".oO[outputFiles[.oO[nIndex]Oo.]]Oo.",
343 "finalOutputFile": outputfile
347 def createScript(self, path, template = configTemplates.scriptTemplate, downloadFiles=[], repMap = None, repMaps = None):
348 scriptName =
"%s.%s.%s.sh"%(self.scriptBaseName, self.
name,
349 self.alignmentToValidate.name )
350 if repMap
is None and repMaps
is None:
352 repMap[
"CommandLine"]=
""
354 repMap[
"CommandLine"]+= repMap[
"CommandLineTemplate"]%{
"cfgFile":
addIndex(cfg, self.
NJobs,
".oO[nIndex]Oo."),
357 scripts = {scriptName: template}
358 return GenericValidation.createScript(self, scripts, path, downloadFiles = downloadFiles,
359 repMap = repMap, repMaps = repMaps)
363 Method which creates a `crab.cfg` for a validation on datasets.
366 - `path`: Path at which the file will be stored.
367 - `crabCfgBaseName`: String which depends on the actual type of
368 validation calling this method.
370 crabCfgName =
"crab.%s.%s.%s.cfg"%( crabCfgBaseName, self.
name,
371 self.alignmentToValidate.name )
373 repMap[
"script"] =
"dummy_script.sh"
375 repMap[
"crabWorkingDir"] = crabCfgName.split(
'.cfg' )[0]
377 repMap[
"numberOfJobs"] = self.
general[
"parallelJobs"]
379 repMap[
"queue"] = self.jobmode.split(
',' )[1].
split(
'-q' )[1]
380 if self.dataset.dataType() ==
"mc":
381 repMap[
"McOrData"] =
"events = .oO[nEvents]Oo."
382 elif self.dataset.dataType() ==
"data":
383 repMap[
"McOrData"] =
"lumis = -1"
384 if self.jobmode.split(
',' )[0] ==
"crab":
385 print (
"For jobmode 'crab' the parameter 'maxevents' will be "
386 "ignored and all events will be processed.")
388 raise AllInOneError(
"Unknown data type! Can't run in crab mode")
389 crabCfg = {crabCfgName:
replaceByMap( configTemplates.crabCfgTemplate,
391 return GenericValidation.createCrabCfg( self, crabCfg, path )
def replaceByMap
— Helpers —############################