3 import globalDictionaries
4 from genericValidation
import GenericValidationData
5 from helperFunctions
import replaceByMap
6 from TkAlExceptions
import AllInOneError
12 "DMRMethod":
"median,rmsNorm",
15 "offlineModuleLevelHistsTransient":
"False",
16 "offlineModuleLevelProfiles":
"False",
17 "OfflineTreeBaseDir":
"TrackHitFilter",
18 "SurfaceShapes":
"none"
20 mandatories = [
"dataset",
"maxevents",
"trackcollection" ]
21 GenericValidationData.__init__(self, valName, alignment, config,
22 "offline", addDefaults=defaults,
23 addMandatories=mandatories)
26 configBaseName =
"TkAlOfflineValidation" ):
27 cfgName =
"%s.%s.%s_cfg.py"%( configBaseName, self.
name,
28 self.alignmentToValidate.name )
31 cfgs = {cfgName:
replaceByMap( configTemplates.offlineTemplate, repMap)}
33 GenericValidationData.defaultReferenceName ] = repMap[
"resultFile"]
34 GenericValidationData.createConfiguration(self, cfgs, path)
36 def createScript(self, path, scriptBaseName = "TkAlOfflineValidation"):
37 scriptName =
"%s.%s.%s.sh"%( scriptBaseName, self.
name,
38 self.alignmentToValidate.name )
40 repMap[
"CommandLine"]=
""
42 repMap[
"CommandLine"]+= repMap[
"CommandLineTemplate"]%{
"cfgFile":cfg,
45 scripts = {scriptName:
replaceByMap( configTemplates.scriptTemplate,
47 return GenericValidationData.createScript(self, scripts, path)
49 def createCrabCfg(self, path, crabCfgBaseName = "TkAlOfflineValidation"):
50 return GenericValidationData.createCrabCfg(self, path, crabCfgBaseName)
53 repMap = GenericValidationData.getRepMap(self, alignment)
55 "nEvents": self.
general[
"maxevents"],
58 "_.oO[name]Oo..root"), repMap ),
59 "resultFile":
replaceByMap( (
"/store/caf/user/$USER/.oO[eosdir]Oo."
60 "/AlignmentValidation_"
62 "_.oO[name]Oo..root"), repMap ),
63 "TrackSelectionTemplate": configTemplates.TrackSelectionTemplate,
64 "LorentzAngleTemplate": configTemplates.LorentzAngleTemplate,
65 "offlineValidationMode":
"Standalone",
66 "offlineValidationFileOutput":
67 configTemplates.offlineStandaloneFileOutputTemplate,
68 "TrackCollection": self.
general[
"trackcollection"]
70 repMap[
"outputFile"] = os.path.expandvars( repMap[
"outputFile"] )
71 repMap[
"resultFile"] = os.path.expandvars( repMap[
"resultFile"] )
76 if no argument or "" is passed a string with an instantiation is
77 returned, else the validation is appended to the list
80 if validationsSoFar ==
"":
81 validationsSoFar = (
'PlotAlignmentValidation p("%(outputFile)s",'
82 '"%(name)s", %(color)s, %(style)s);\n')%repMap
84 validationsSoFar += (
'p.loadFileList("%(outputFile)s", "%(name)s",'
85 '%(color)s, %(style)s);\n')%repMap
86 return validationsSoFar
90 append all merges here
93 mergesSoFar +=
replaceByMap(configTemplates.mergeOfflineParallelResults,
100 OfflineValidation.__init__(self, valName, alignment, config)
105 offline = config.getResultingSection(
"offline:"+self.
name,
106 defaultDict = defaults )
107 self.general.update( offline )
110 for index
in range(int(self.
general[
"parallelJobs"])):
112 +
"_.oO[name]Oo._%d.root"%(index),
114 self.outputFiles.append(fName)
119 numberParallelJobs = int( self.
general[
"parallelJobs"] )
122 maximumNumberJobs = 40
123 if numberParallelJobs > maximumNumberJobs:
124 msg = (
"Maximum allowed number of parallel jobs "
125 +str(maximumNumberJobs)+
" exceeded!!!")
129 if int( self.
general[
"maxevents"] ) == -1:
130 msg = (
"Maximum number of events (maxevents) not specified: "
131 "cannot use parallel jobs in offline validation")
133 if numberParallelJobs > 1:
134 if self.
general[
"offlineModuleLevelHistsTransient"] ==
"True":
135 msg = (
"To be able to merge results when running parallel jobs,"
136 " set offlineModuleLevelHistsTransient to false.")
138 for index
in range(numberParallelJobs):
139 cfgName =
"%s.%s.%s_%s_cfg.py"%(configBaseName, self.
name,
140 self.alignmentToValidate.name,
147 repMap.update({
"nIndex": str(index)})
150 repMap.update({
"outputFile": self.
outputFiles[index]})
151 repMap[
"outputFile"] = os.path.expandvars( repMap[
"outputFile"] )
153 cfgs = {cfgName:
replaceByMap(configTemplates.offlineParallelTemplate,
155 self.
filesToCompare[GenericValidationData.defaultReferenceName] = repMap[
"resultFile"]
156 GenericValidationData.createConfiguration(self, cfgs, path)
160 def createScript(self, path, scriptBaseName = "TkAlOfflineValidation"):
164 numJobs = int( self.
general[
"parallelJobs"] )
165 for index
in range(numJobs):
166 scriptName =
"%s.%s.%s_%s.sh"%(scriptBaseName, self.
name,
167 self.alignmentToValidate.name,
171 repMap[
"nIndex"]=str(index)
172 repMap[
"CommandLine"]=
""
173 repMap.update({
"outputFile": self.
outputFiles[index]})
176 cfgtemp = cfg.replace(str(numJobs-1)+
"_cfg.py",
177 str(index)+
"_cfg.py")
178 repMap[
"CommandLine"]+= repMap[
"CommandLineTemplate"]%{
"cfgFile":cfgtemp,
181 scripts = {scriptName:
replaceByMap(configTemplates.parallelScriptTemplate,
183 returnValue.extend(GenericValidationData.createScript(self,
189 repMap = OfflineValidation.getRepMap(self, alignment)
191 "nJobs": self.
general[
"parallelJobs"],
192 "offlineValidationFileOutput":
193 configTemplates.offlineParallelFileOutputTemplate,
194 "nameValidation": self.
name
199 if str(self.
general[
"maxevents"]) ==
"-1":
200 repMap.update({
"nJobs":
"1" })
205 if no argument or "" is passed a string with an instantiation is returned,
206 else the validation is appended to the list
212 for index
in range(int(self.
__NJobs)):
213 fileToAdd =
'%(outputFile)s'%repMap
214 fileToAdd = fileToAdd.replace(
'.root',
'_'+str(index)+
'.root')
215 if index < int( self.
general[
"parallelJobs"] )-1:
216 parameters = parameters+fileToAdd+
','
218 parameters = parameters+fileToAdd
220 mergedoutputfile = (
"AlignmentValidation_" + self.
name +
"_"
221 +
'%(name)s'%repMap +
".root")
222 validationsSoFar += (
'root -x -b -q -l "TkAlOfflineJobsMerge.C(\\\"'
223 +parameters+
'\\\",\\\"'+mergedoutputfile+
'\\\")"'
225 return validationsSoFar
228 msg = (
"jobmode 'crab' not supported for 'offlineParallel' validation."
229 " Please choose another 'jobmode'.")
235 OfflineValidation.__init__(self, valName, alignment, config)
236 if not config.has_section(
"DQM"):
237 msg =
"You need to have a DQM section in your configfile!"
245 OfflineValidation.createConfiguration(self, path,
246 "TkAlOfflineValidationDQM")
249 return OfflineValidation.createScript(self, path,
250 "TkAlOfflineValidationDQM")
253 repMap = OfflineValidation.getRepMap(self, alignment)
255 "workdir": os.path.expandvars(repMap[
"workdir"]),
256 "offlineValidationMode":
"Dqm",
257 "offlineValidationFileOutput": configTemplates.offlineDqmFileOutputTemplate,
258 "workflow": (
"/%s/TkAl%s-.oO[alignmentName]Oo._R%09i_R%09i_"
259 "ValSkim-v1/ALCARECO"
261 datetime.datetime.now().strftime(
"%y"),
265 if "__" in repMap[
"workflow"]:
266 msg = (
"the DQM workflow specefication must not contain '__'. "
267 "it is: %s"%repMap[
"workflow"])
def appendToExtendedValidation
def replaceByMap
— Helpers —############################