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 )
112 numberParallelJobs = int( self.
general[
"parallelJobs"] )
115 maximumNumberJobs = 40
116 if numberParallelJobs > maximumNumberJobs:
117 msg = (
"Maximum allowed number of parallel jobs "
118 +str(maximumNumberJobs)+
" exceeded!!!")
122 if int( self.
general[
"maxevents"] ) == -1:
123 msg = (
"Maximum number of events (maxevents) not specified: "
124 "cannot use parallel jobs in offline validation")
126 if numberParallelJobs > 1:
127 if self.
general[
"offlineModuleLevelHistsTransient"] ==
"True":
128 msg = (
"To be able to merge results when running parallel jobs,"
129 " set offlineModuleLevelHistsTransient to false.")
131 for index
in range(numberParallelJobs):
132 cfgName =
"%s.%s.%s_%s_cfg.py"%(configBaseName, self.
name,
133 self.alignmentToValidate.name,
140 repMap.update({
"nIndex": str(index)})
146 "_.oO[name]Oo._.oO[nIndex]Oo..root",
149 repMap[
"outputFile"] = os.path.expandvars( repMap[
"outputFile"] )
151 cfgs = {cfgName:
replaceByMap(configTemplates.offlineParallelTemplate,
153 self.
filesToCompare[GenericValidationData.defaultReferenceName] = repMap[
"resultFile"]
154 GenericValidationData.createConfiguration(self, cfgs, path)
158 def createScript(self, path, scriptBaseName = "TkAlOfflineValidation"):
162 numJobs = int( self.
general[
"parallelJobs"] )
163 for index
in range(numJobs):
164 scriptName =
"%s.%s.%s_%s.sh"%(scriptBaseName, self.
name,
165 self.alignmentToValidate.name,
169 repMap[
"nIndex"]=str(index)
170 repMap[
"CommandLine"]=
""
174 "_.oO[name]Oo._.oO[nIndex]Oo..root",
179 cfgtemp = cfg.replace(str(numJobs-1)+
"_cfg.py",
180 str(index)+
"_cfg.py")
181 repMap[
"CommandLine"]+= repMap[
"CommandLineTemplate"]%{
"cfgFile":cfgtemp,
184 scripts = {scriptName:
replaceByMap(configTemplates.parallelScriptTemplate,
186 returnValue.extend(GenericValidationData.createScript(self,
192 repMap = OfflineValidation.getRepMap(self, alignment)
194 "nJobs": self.
general[
"parallelJobs"],
195 "offlineValidationFileOutput":
196 configTemplates.offlineParallelFileOutputTemplate,
197 "nameValidation": self.
name
202 if str(self.
general[
"maxevents"]) ==
"-1":
203 repMap.update({
"nJobs":
"1" })
208 if no argument or "" is passed a string with an instantiation is returned,
209 else the validation is appended to the list
215 for index
in range(int(self.
__NJobs)):
216 fileToAdd =
'%(outputFile)s'%repMap
217 fileToAdd = fileToAdd.replace(
'.root',
'_'+str(index)+
'.root')
218 if index < int( self.
general[
"parallelJobs"] )-1:
219 parameters = parameters+fileToAdd+
','
221 parameters = parameters+fileToAdd
223 mergedoutputfile = (
"AlignmentValidation_" + self.
name +
"_"
224 +
'%(name)s'%repMap +
".root")
225 validationsSoFar += (
'root -x -b -q "TkAlOfflineJobsMerge.C(\\\"'
226 +parameters+
'\\\",\\\"'+mergedoutputfile+
'\\\")"'
228 return validationsSoFar
231 msg = (
"jobmode 'crab' not supported for 'offlineParallel' validation."
232 " Please choose another 'jobmode'.")
238 OfflineValidation.__init__(self, valName, alignment, config)
239 if not config.has_section(
"DQM"):
240 msg =
"You need to have a DQM section in your configfile!"
248 OfflineValidation.createConfiguration(self, path,
249 "TkAlOfflineValidationDQM")
252 return OfflineValidation.createScript(self, path,
253 "TkAlOfflineValidationDQM")
256 repMap = OfflineValidation.getRepMap(self, alignment)
258 "workdir": os.path.expandvars(repMap[
"workdir"]),
259 "offlineValidationMode":
"Dqm",
260 "offlineValidationFileOutput": configTemplates.offlineDqmFileOutputTemplate,
261 "workflow": (
"/%s/TkAl%s-.oO[alignmentName]Oo._R%09i_R%09i_"
262 "ValSkim-v1/ALCARECO"
264 datetime.datetime.now().strftime(
"%y"),
268 if "__" in repMap[
"workflow"]:
269 msg = (
"the DQM workflow specefication must not contain '__'. "
270 "it is: %s"%repMap[
"workflow"])
def appendToExtendedValidation
def replaceByMap
— Helpers —############################