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(),
100 "condLoad": alignment.getConditions(),
106 repMap = self.alignmentToValidate.getRepMap()
109 if repMap[
"file"].startswith(
"/castor/" ):
110 repMap[
"file"] =
"rfio:%(file)s"%repMap
111 elif repMap[
"file"].startswith(
"/store/" ):
112 repMap[
"file"] =
"root://eoscms.cern.ch//eos/cms%(file)s"%repMap
114 result[validationId]=repMap[
"file"]
116 result[validationId]=
"%(file)s=%(title)s|%(color)s|%(style)s"%repMap
117 if requestId ==
None:
120 if not "." in requestId:
121 requestId +=
".%s"%GenericValidation.defaultReferenceName
122 if not requestId.split(
".")[-1]
in result:
123 msg = (
"could not find %s in reference Objects!"
124 %requestId.split(
".")[-1])
126 return result[ requestId.split(
".")[-1] ]
128 def createFiles(self, fileContents, path, repMap = None, repMaps = None):
129 """repMap: single map for all files
130 repMaps: a dict, with the filenames as the keys"""
131 if repMap
is not None and repMaps
is not None:
132 raise AllInOneError(
"createFiles can only take repMap or repMaps (or neither), not both")
134 for fileName
in fileContents:
135 filePath = os.path.join(path, fileName)
136 result.append(filePath)
138 for (i, filePathi)
in enumerate(
addIndex(filePath, self.
NJobs)):
139 theFile = open( filePathi,
"w" )
140 fileContentsi = fileContents[ fileName ]
141 if repMaps
is not None:
142 repMap = repMaps[fileName]
143 if repMap
is not None:
144 repMap.update({
"nIndex": str(i)})
146 theFile.write( fileContentsi )
152 self.
configFiles = GenericValidation.createFiles(self, fileContents,
153 path, repMap = repMap, repMaps = repMaps)
154 if not schedule ==
None:
155 schedule = [os.path.join( path, cfgName)
for cfgName
in schedule]
156 for cfgName
in schedule:
158 msg = (
"scheduled %s missing in generated configfiles: %s"
162 if not cfgName
in schedule:
163 msg = (
"generated configuration %s not scheduled: %s"
164 %(cfgName, schedule))
169 def createScript(self, fileContents, path, downloadFiles=[], repMap = None, repMaps = None):
170 self.
scriptFiles = GenericValidation.createFiles(self, fileContents,
171 path, repMap = repMap, repMaps = repMaps)
174 os.chmod(scriptwithindex,0755)
179 msg = (
"jobmode 'crab' not supported for parallel validation."
180 " Please set parallelJobs = 1.")
189 Subclass of `GenericValidation` which is the base for validations using
193 def __init__(self, valName, alignment, config, valType,
194 addDefaults = {}, addMandatories=[]):
196 This method adds additional items to the `self.general` dictionary
197 which are only needed for validations using datasets.
200 - `valName`: String which identifies individual validation instances
201 - `alignment`: `Alignment` instance to validate
202 - `config`: `BetterConfigParser` instance which includes the
203 configuration of the validations
204 - `valType`: String which specifies the type of validation
205 - `addDefaults`: Dictionary which contains default values for individual
206 validations in addition to the general default values
207 - `addMandatories`: List which contains mandatory parameters for
208 individual validations in addition to the general
212 defaults = {
"runRange":
"",
219 defaults.update(addDefaults)
220 mandatories = [
"dataset",
"maxevents" ]
221 mandatories += addMandatories
222 GenericValidation.__init__(self, valName, alignment, config, valType, defaults, mandatories)
226 if int( self.
general[
"maxevents"] ) == -1
and self.
NJobs > 1:
227 msg = (
"Maximum number of events (maxevents) not specified: "
228 "cannot use parallel jobs.")
231 tryPredefinedFirst = (
not self.jobmode.split(
',' )[0] ==
"crab" and self.
general[
"JSON"] ==
""
232 and self.
general[
"firstRun"] ==
"" and self.
general[
"lastRun"] ==
""
235 if self.
general[
"dataset"]
not in globalDictionaries.usedDatasets:
236 globalDictionaries.usedDatasets[self.
general[
"dataset"]] = {}
238 if self.
cmssw not in globalDictionaries.usedDatasets[self.
general[
"dataset"]]:
239 if globalDictionaries.usedDatasets[self.
general[
"dataset"]] != {}:
240 print (
"Warning: you use the same dataset '%s' in multiple cmssw releases.\n"
241 "This is allowed, but make sure it's not a mistake") % self.
general[
"dataset"]
242 globalDictionaries.usedDatasets[self.
general[
"dataset"]][self.
cmssw] = {
False:
None,
True:
None}
244 if globalDictionaries.usedDatasets[self.
general[
"dataset"]][self.
cmssw][tryPredefinedFirst]
is None:
246 self.
general[
"dataset"], tryPredefinedFirst = tryPredefinedFirst,
248 globalDictionaries.usedDatasets[self.
general[
"dataset"]][self.
cmssw][tryPredefinedFirst] = dataset
249 if tryPredefinedFirst
and not dataset.predefined():
250 globalDictionaries.usedDatasets[self.
general[
"dataset"]][self.
cmssw][
False] = dataset
253 self.
general[
"magneticField"] = self.dataset.magneticField()
254 self.
general[
"defaultMagneticField"] =
"MagneticField"
255 if self.
general[
"magneticField"] ==
"unknown":
256 print "Could not get the magnetic field for this dataset."
257 print "Using the default: ", self.
general[
"defaultMagneticField"]
258 self.
general[
"magneticField"] =
'.oO[defaultMagneticField]Oo.'
260 if not self.jobmode.split(
',' )[0] ==
"crab":
262 self.
general[
"datasetDefinition"] = self.dataset.datasetSnippet(
263 jsonPath = self.
general[
"JSON"],
264 firstRun = self.
general[
"firstRun"],
265 lastRun = self.
general[
"lastRun"],
268 parent = self.needParentFiles )
269 except AllInOneError, e:
270 msg =
"In section [%s:%s]: "%(valType, self.
name)
274 if self.dataset.predefined():
275 msg = (
"For jobmode 'crab' you cannot use predefined datasets "
276 "(in your case: '%s')."%( self.dataset.name() ))
279 theUpdate = config.getResultingSection(valType+
":"+self.
name,
280 demandPars = [
"parallelJobs"])
281 except AllInOneError, e:
282 msg = str(e)[:-1]+
" when using 'jobmode: crab'."
284 self.general.update(theUpdate)
289 self.
general[
"lastRun"] ) = self.dataset.convertTimeToRun(
290 firstRun = self.
general[
"firstRun"],
291 lastRun = self.
general[
"lastRun"],
295 if self.
general[
"begin"] ==
None:
297 if self.
general[
"end"] ==
None:
301 if (
not self.
general[
"firstRun"] )
and \
303 self.
general[
"firstRun"] = str(
304 self.dataset.runList()[0][
"run_number"])
305 if (
not self.
general[
"lastRun"] )
and \
308 self.dataset.runList()[-1][
"run_number"])
311 msg = (
"The lower time/runrange limit ('begin'/'firstRun') "
312 "chosen is greater than the upper time/runrange limit "
313 "('end'/'lastRun').")
316 +
'-' + self.
general[
"lastRun"])
318 self.
general[
"datasetDefinition"] = self.dataset.datasetSnippet(
319 jsonPath = self.
general[
"JSON"],
320 firstRun = self.
general[
"firstRun"],
321 lastRun = self.
general[
"lastRun"],
325 except AllInOneError, e:
326 msg =
"In section [%s:%s]: "%(valType, self.
name)
331 result = GenericValidation.getRepMap(self, alignment)
333 "%s_%s_.oO[name]Oo..root" % (self.outputBaseName, self.
name)
335 resultfile = os.path.expandvars(
replaceByMap((
"/store/caf/user/$USER/.oO[eosdir]Oo./" +
336 "%s_%s_.oO[name]Oo..root" % (self.resultBaseName, self.
name))
339 "resultFile":
".oO[resultFiles[.oO[nIndex]Oo.]]Oo.",
341 "finalResultFile": resultfile,
342 "outputFile":
".oO[outputFiles[.oO[nIndex]Oo.]]Oo.",
344 "finalOutputFile": outputfile
348 def createScript(self, path, template = configTemplates.scriptTemplate, downloadFiles=[], repMap = None, repMaps = None):
349 scriptName =
"%s.%s.%s.sh"%(self.scriptBaseName, self.
name,
350 self.alignmentToValidate.name )
351 if repMap
is None and repMaps
is None:
353 repMap[
"CommandLine"]=
""
355 repMap[
"CommandLine"]+= repMap[
"CommandLineTemplate"]%{
"cfgFile":
addIndex(cfg, self.
NJobs,
".oO[nIndex]Oo."),
358 scripts = {scriptName: template}
359 return GenericValidation.createScript(self, scripts, path, downloadFiles = downloadFiles,
360 repMap = repMap, repMaps = repMaps)
364 Method which creates a `crab.cfg` for a validation on datasets.
367 - `path`: Path at which the file will be stored.
368 - `crabCfgBaseName`: String which depends on the actual type of
369 validation calling this method.
371 crabCfgName =
"crab.%s.%s.%s.cfg"%( crabCfgBaseName, self.
name,
372 self.alignmentToValidate.name )
374 repMap[
"script"] =
"dummy_script.sh"
376 repMap[
"crabWorkingDir"] = crabCfgName.split(
'.cfg' )[0]
378 repMap[
"numberOfJobs"] = self.
general[
"parallelJobs"]
380 repMap[
"queue"] = self.jobmode.split(
',' )[1].
split(
'-q' )[1]
381 if self.dataset.dataType() ==
"mc":
382 repMap[
"McOrData"] =
"events = .oO[nEvents]Oo."
383 elif self.dataset.dataType() ==
"data":
384 repMap[
"McOrData"] =
"lumis = -1"
385 if self.jobmode.split(
',' )[0] ==
"crab":
386 print (
"For jobmode 'crab' the parameter 'maxevents' will be "
387 "ignored and all events will be processed.")
389 raise AllInOneError(
"Unknown data type! Can't run in crab mode")
390 crabCfg = {crabCfgName:
replaceByMap( configTemplates.crabCfgTemplate,
392 return GenericValidation.createCrabCfg( self, crabCfg, path )
def replaceByMap
— Helpers —############################