CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
validateAlignments.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #test execute: export CMSSW_BASE=/tmp/CMSSW && ./validateAlignments.py -c defaultCRAFTValidation.ini,test.ini -n -N test
3 import os
4 import sys
5 import optparse
6 import datetime
7 import shutil
8 import fnmatch
9 
10 import Alignment.OfflineValidation.TkAlAllInOneTool.configTemplates \
11  as configTemplates
12 import Alignment.OfflineValidation.TkAlAllInOneTool.crabWrapper as crabWrapper
13 from Alignment.OfflineValidation.TkAlAllInOneTool.TkAlExceptions \
14  import AllInOneError
15 from Alignment.OfflineValidation.TkAlAllInOneTool.helperFunctions \
16  import replaceByMap, getCommandOutput2
17 from Alignment.OfflineValidation.TkAlAllInOneTool.betterConfigParser \
18  import BetterConfigParser
19 from Alignment.OfflineValidation.TkAlAllInOneTool.alignment import Alignment
20 
21 from Alignment.OfflineValidation.TkAlAllInOneTool.genericValidation \
22  import GenericValidation
23 from Alignment.OfflineValidation.TkAlAllInOneTool.geometryComparison \
24  import GeometryComparison
25 from Alignment.OfflineValidation.TkAlAllInOneTool.offlineValidation \
26  import OfflineValidation, OfflineValidationDQM, OfflineValidationParallel
27 from Alignment.OfflineValidation.TkAlAllInOneTool.monteCarloValidation \
28  import MonteCarloValidation
29 from Alignment.OfflineValidation.TkAlAllInOneTool.trackSplittingValidation \
30  import TrackSplittingValidation
31 from Alignment.OfflineValidation.TkAlAllInOneTool.zMuMuValidation \
32  import ZMuMuValidation
33 import Alignment.OfflineValidation.TkAlAllInOneTool.globalDictionaries \
34  as globalDictionaries
35 
36 
37 ####################--- Classes ---############################
39 
40  # these count the jobs of different varieties that are being run
41  crabCount = 0
42  interactCount = 0
43  batchCount = 0
44  batchJobIds = []
45  jobCount = 0
46 
47  def __init__( self, validation, config, options ):
48  if validation[1] == "":
49  # intermediate syntax
50  valString = validation[0].split( "->" )[0]
51  alignments = validation[0].split( "->" )[1]
52  # force user to use the normal syntax
53  if "->" in validation[0]:
54  msg = ("Instead of using the intermediate syntax\n'"
55  +valString.strip()+"-> "+alignments.strip()
56  +":'\nyou have to use the now fully supported syntax \n'"
57  +valString.strip()+": "
58  +alignments.strip()+"'.")
59  raise AllInOneError(msg)
60  else:
61  valString = validation[0]
62  alignments = validation[1]
63  valString = valString.split()
64  self.__valType = valString[0]
65  self.__valName = valString[1]
66  self.__commandLineOptions = options
67  self.__config = config
68  # workaround for intermediate parallel version
69  if self.__valType == "offlineParallel":
70  section = "offline" + ":" + self.__valName
71  else:
72  section = self.__valType + ":" + self.__valName
73  if not self.__config.has_section( section ):
74  raise AllInOneError, ("Validation '%s' of type '%s' is requested in"
75  " '[validation]' section, but is not defined."
76  "\nYou have to add a '[%s]' section."
77  %( self.__valName, self.__valType, section ))
78  self.validation = self.__getValidation( self.__valType, self.__valName,
79  alignments, self.__config,
80  options )
81 
82  def __getValidation( self, valType, name, alignments, config, options ):
83  if valType == "compare":
84  alignmentsList = alignments.split( "," )
85  firstAlignList = alignmentsList[0].split()
86  firstAlignName = firstAlignList[0].strip()
87  if firstAlignName == "IDEAL":
88  raise AllInOneError, ("'IDEAL' has to be the second (reference)"
89  " alignment in 'compare <val_name>: "
90  "<alignment> <reference>'.")
91  if len( firstAlignList ) > 1:
92  firstRun = firstAlignList[1]
93  else:
94  firstRun = "1"
95  firstAlign = Alignment( firstAlignName, self.__config, firstRun )
96  secondAlignList = alignmentsList[1].split()
97  secondAlignName = secondAlignList[0].strip()
98  if len( secondAlignList ) > 1:
99  secondRun = secondAlignList[1]
100  else:
101  secondRun = "1"
102  if secondAlignName == "IDEAL":
103  secondAlign = secondAlignName
104  else:
105  secondAlign = Alignment( secondAlignName, self.__config,
106  secondRun )
107  # check if alignment was already compared previously
108  try:
109  randomWorkdirPart = \
110  globalDictionaries.alignRandDict[firstAlignName]
111  except KeyError:
112  randomWorkdirPart = None
113 
114  validation = GeometryComparison( name, firstAlign, secondAlign,
115  self.__config,
116  self.__commandLineOptions.getImages,
117  randomWorkdirPart )
118  globalDictionaries.alignRandDict[firstAlignName] = \
119  validation.randomWorkdirPart
120  if not secondAlignName == "IDEAL":
121  globalDictionaries.alignRandDict[secondAlignName] = \
122  validation.randomWorkdirPart
123  elif valType == "offline":
124  validation = OfflineValidation( name,
125  Alignment( alignments.strip(), self.__config ), self.__config )
126  elif valType == "offlineDQM":
127  validation = OfflineValidationDQM( name,
128  Alignment( alignments.strip(), self.__config ), self.__config )
129  elif valType == "offlineParallel":
130  validation = OfflineValidationParallel( name,
131  Alignment( alignments.strip(), self.__config ), self.__config )
132  elif valType == "mcValidate":
133  validation = MonteCarloValidation( name,
134  Alignment( alignments.strip(), self.__config ), self.__config )
135  elif valType == "split":
136  validation = TrackSplittingValidation( name,
137  Alignment( alignments.strip(), self.__config ), self.__config )
138  elif valType == "zmumu":
139  validation = ZMuMuValidation( name,
140  Alignment( alignments.strip(), self.__config ), self.__config )
141  else:
142  raise AllInOneError, "Unknown validation mode '%s'"%valType
143  return validation
144 
145  def __createJob( self, jobMode, outpath ):
146  """This private method creates the needed files for the validation job.
147  """
148  self.validation.createConfiguration( outpath )
149  self.__scripts = self.validation.createScript( outpath )
150  if jobMode.split( ',' )[0] == "crab":
151  self.validation.createCrabCfg( outpath )
152  return None
153 
154  def createJob(self):
155  """This is the method called to create the job files."""
156  self.__createJob( self.validation.jobmode,
157  os.path.abspath( self.__commandLineOptions.Name) )
158 
159  def runJob( self ):
160  general = self.__config.getGeneral()
161  log = ""
162  for script in self.__scripts:
163  name = os.path.splitext( os.path.basename( script) )[0]
164  ValidationJob.jobCount += 1
165  if self.__commandLineOptions.dryRun:
166  print "%s would run: %s"%( name, os.path.basename( script) )
167  continue
168  log = "> Validating "+name
169  print "> Validating "+name
170  if self.validation.jobmode == "interactive":
171  log += getCommandOutput2( script )
172  ValidationJob.interactCount += 1
173  elif self.validation.jobmode.split(",")[0] == "lxBatch":
174  repMap = {
175  "commands": self.validation.jobmode.split(",")[1],
176  "logDir": general["logdir"],
177  "jobName": name,
178  "script": script,
179  "bsub": "/afs/cern.ch/cms/caf/scripts/cmsbsub"
180  }
181  bsubOut=getCommandOutput2("%(bsub)s %(commands)s "
182  "-J %(jobName)s "
183  "-o %(logDir)s/%(jobName)s.stdout "
184  "-e %(logDir)s/%(jobName)s.stderr "
185  "%(script)s"%repMap)
186  #Attention: here it is assumed that bsub returns a string
187  #containing a job id like <123456789>
188  ValidationJob.batchJobIds.append(bsubOut.split("<")[1].split(">")[0])
189  log+=bsubOut
190  ValidationJob.batchCount += 1
191  elif self.validation.jobmode.split( "," )[0] == "crab":
192  os.chdir( general["logdir"] )
193  crabName = "crab." + os.path.basename( script )[:-3]
194  theCrab = crabWrapper.CrabWrapper()
195  options = { "-create": "",
196  "-cfg": crabName + ".cfg",
197  "-submit": "" }
198  try:
199  theCrab.run( options )
200  except AllInOneError, e:
201  print "crab:", str(e).split("\n")[0]
202  exit(1)
203  ValidationJob.crabCount += 1
204 
205  else:
206  raise AllInOneError, ("Unknown 'jobmode'!\n"
207  "Please change this parameter either in "
208  "the [general] or in the ["
209  + self.__valType + ":" + self.__valName
210  + "] section to one of the following "
211  "values:\n"
212  "\tinteractive\n\tlxBatch, -q <queue>\n"
213  "\tcrab, -q <queue>")
214 
215  return log
216 
217  def getValidation( self ):
218  return self.validation
219 
220 
221 ####################--- Functions ---############################
222 def createOfflineJobsMergeScript(offlineValidationList, outFilePath):
223  repMap = offlineValidationList[0].getRepMap() # bit ugly since some special features are filled
224  repMap[ "mergeOfflinParJobsInstantiation" ] = "" #give it a "" at first in order to get the initialisation back
225 
226  theFile = open( outFilePath, "w" )
227  theFile.write( replaceByMap( configTemplates.mergeOfflineParJobsTemplate ,repMap ) )
228  theFile.close()
229 
230 def createExtendedValidationScript(offlineValidationList, outFilePath, resultPlotFile):
231  repMap = offlineValidationList[0].getRepMap() # bit ugly since some special features are filled
232  repMap[ "resultPlotFile" ] = resultPlotFile
233  repMap[ "extendedInstantiation" ] = "" #give it a "" at first in order to get the initialisation back
234 
235  for validation in offlineValidationList:
236  repMap[ "extendedInstantiation" ] = validation.appendToExtendedValidation( repMap[ "extendedInstantiation" ] )
237 
238  theFile = open( outFilePath, "w" )
239  # theFile.write( replaceByMap( configTemplates.extendedValidationTemplate ,repMap ) )
240  theFile.write( replaceByMap( configTemplates.extendedValidationTemplate ,repMap ) )
241  theFile.close()
242 
243 def createTrackSplitPlotScript(trackSplittingValidationList, outFilePath):
244  repMap = trackSplittingValidationList[0].getRepMap() # bit ugly since some special features are filled
245  repMap[ "trackSplitPlotInstantiation" ] = "" #give it a "" at first in order to get the initialisation back
246 
247  for validation in trackSplittingValidationList:
248  repMap[ "trackSplitPlotInstantiation" ] = validation.appendToExtendedValidation( repMap[ "trackSplitPlotInstantiation" ] )
249 
250  theFile = open( outFilePath, "w" )
251  # theFile.write( replaceByMap( configTemplates.trackSplitPlotTemplate ,repMap ) )
252  theFile.write( replaceByMap( configTemplates.trackSplitPlotTemplate ,repMap ) )
253  theFile.close()
254 
255 def createMergeScript( path, validations ):
256  if(len(validations) == 0):
257  msg = "Cowardly refusing to merge nothing!"
258  raise AllInOneError(msg)
259 
260  repMap = validations[0].getRepMap() #FIXME - not nice this way
261  repMap.update({
262  "DownloadData":"",
263  "CompareAlignments":"",
264  "RunExtendedOfflineValidation":"",
265  "RunTrackSplitPlot":""
266  })
267 
268  comparisonLists = {} # directory of lists containing the validations that are comparable
269  for validation in validations:
270  for referenceName in validation.filesToCompare:
271  validationName = "%s.%s"%(validation.__class__.__name__, referenceName)
272  validationName = validationName.split(".%s"%GenericValidation.defaultReferenceName )[0]
273  if validationName in comparisonLists:
274  comparisonLists[ validationName ].append( validation )
275  else:
276  comparisonLists[ validationName ] = [ validation ]
277 
278  if "OfflineValidation" in comparisonLists:
279  repMap["extendeValScriptPath"] = \
280  os.path.join(path, "TkAlExtendedOfflineValidation.C")
281  createExtendedValidationScript(comparisonLists["OfflineValidation"],
282  repMap["extendeValScriptPath"],
283  "OfflineValidation")
284  repMap["RunExtendedOfflineValidation"] = \
285  replaceByMap(configTemplates.extendedValidationExecution, repMap)
286 
287  if "TrackSplittingValidation" in comparisonLists:
288  repMap["trackSplitPlotScriptPath"] = \
289  os.path.join(path, "TkAlTrackSplitPlot.C")
290  createTrackSplitPlotScript(comparisonLists["TrackSplittingValidation"],
291  repMap["trackSplitPlotScriptPath"] )
292  repMap["RunTrackSplitPlot"] = \
293  replaceByMap(configTemplates.trackSplitPlotExecution, repMap)
294 
295  repMap["CompareAlignments"] = "#run comparisons"
296  for validationId in comparisonLists:
297  compareStrings = [ val.getCompareStrings(validationId) for val in comparisonLists[validationId] ]
298  compareStringsPlain = [ val.getCompareStrings(validationId, plain=True) for val in comparisonLists[validationId] ]
299 
300  repMap.update({"validationId": validationId,
301  "compareStrings": " , ".join(compareStrings),
302  "compareStringsPlain": " ".join(compareStringsPlain) })
303 
304  repMap["CompareAlignments"] += \
305  replaceByMap(configTemplates.compareAlignmentsExecution, repMap)
306 
307  filePath = os.path.join(path, "TkAlMerge.sh")
308  theFile = open( filePath, "w" )
309  theFile.write( replaceByMap( configTemplates.mergeTemplate, repMap ) )
310  theFile.close()
311  os.chmod(filePath,0755)
312 
313  return filePath
314 
315 def createParallelMergeScript( path, validations ):
316  if( len(validations) == 0 ):
317  raise AllInOneError, "cowardly refusing to merge nothing!"
318 
319  repMap = validations[0].getRepMap() #FIXME - not nice this way
320  repMap.update({
321  "DownloadData":"",
322  "CompareAlignments":"",
323  "RunExtendedOfflineValidation":"",
324  "RunTrackSplitPlot":""
325  })
326 
327  comparisonLists = {} # directory of lists containing the validations that are comparable
328  for validation in validations:
329  for referenceName in validation.filesToCompare:
330  validationName = "%s.%s"%(validation.__class__.__name__, referenceName)
331  validationName = validationName.split(".%s"%GenericValidation.defaultReferenceName )[0]
332  if validationName in comparisonLists:
333  comparisonLists[ validationName ].append( validation )
334  else:
335  comparisonLists[ validationName ] = [ validation ]
336 
337  if "OfflineValidationParallel" in comparisonLists:
338  repMap["extendeValScriptPath"] = os.path.join(path, "TkAlExtendedOfflineValidation.C")
339  repMap["mergeOfflineParJobsScriptPath"] = os.path.join(path, "TkAlOfflineJobsMerge.C")
340  createOfflineJobsMergeScript( comparisonLists["OfflineValidationParallel"],
341  repMap["mergeOfflineParJobsScriptPath"] )
342 
343  # introduced to merge individual validation outputs separately
344  # -> avoids problems with merge script
345  repMap["haddLoop"] = "mergeRetCode=0\n"
346  repMap["rmUnmerged"] = ("if [[ mergeRetCode -eq 0 ]]; then\n"
347  " echo -e \\n\"Merging succeeded, removing original files.\"\n")
348  for validation in comparisonLists["OfflineValidationParallel"]:
349  repMap["haddLoop"] = validation.appendToMergeParJobs(repMap["haddLoop"])
350  repMap["haddLoop"] += "tmpMergeRetCode=${?}\n"
351  repMap["haddLoop"] += ("if [[ tmpMergeRetCode -eq 0 ]]; then "
352  "cmsStage -f "
353  +validation.getRepMap()["outputFile"]
354  +" "
355  +validation.getRepMap()["resultFile"]
356  +"; fi\n")
357  repMap["haddLoop"] += ("if [[ ${tmpMergeRetCode} -gt ${mergeRetCode} ]]; then "
358  "mergeRetCode=${tmpMergeRetCode}; fi\n")
359  for f in validation.outputFiles:
360  longName = os.path.join("/store/caf/user/$USER/",
361  validation.getRepMap()["eosdir"], f)
362  repMap["rmUnmerged"] += " cmsRm "+longName+"\n"
363  repMap["rmUnmerged"] += ("else\n"
364  " echo -e \\n\"WARNING: Merging failed, unmerged"
365  " files won't be deleted.\\n"
366  "(Ignore this warning if merging was done earlier)\"\n"
367  "fi\n")
368 
369  repMap["RunExtendedOfflineValidation"] = \
370  replaceByMap(configTemplates.extendedValidationExecution, repMap)
371 
372  # DownloadData is the section which merges output files from parallel jobs
373  # it uses the file TkAlOfflineJobsMerge.C
374  repMap["DownloadData"] += replaceByMap("rfcp .oO[mergeOfflineParJobsScriptPath]Oo. .", repMap)
375  repMap["DownloadData"] += replaceByMap( configTemplates.mergeOfflineParallelResults, repMap )
376 
377  # For the rest of the script, OfflineValidations and
378  # OfflineParallelValidations are comparable:
379  if "OfflineValidation" in comparisonLists:
380  comparisonLists["OfflineValidationParallel"].extend(comparisonLists["OfflineValidation"])
381  del comparisonLists["OfflineValidation"]
382  createExtendedValidationScript( comparisonLists["OfflineValidationParallel"],
383  repMap["extendeValScriptPath"],
384  "OfflineValidationParallel")
385 
386  repMap["CompareAlignments"] = "#run comparisons"
387  for validationId in comparisonLists:
388  compareStrings = [ val.getCompareStrings(validationId) for val in comparisonLists[validationId] ]
389  compareStringsPlain = [ val.getCompareStrings(validationId, plain=True) for val in comparisonLists[validationId] ]
390 
391  repMap.update({"validationId": validationId,
392  "compareStrings": " , ".join(compareStrings),
393  "compareStringsPlain": " ".join(compareStringsPlain) })
394 
395  repMap["CompareAlignments"] += \
396  replaceByMap(configTemplates.compareAlignmentsExecution, repMap)
397 
398  filePath = os.path.join(path, "TkAlMerge.sh")
399  theFile = open( filePath, "w" )
400  theFile.write( replaceByMap( configTemplates.mergeTemplate, repMap ) )
401  theFile.close()
402  os.chmod(filePath,0755)
403 
404  return filePath
405 
406 def loadTemplates( config ):
407  if config.has_section("alternateTemplates"):
408  for templateName in config.options("alternateTemplates"):
409  newTemplateName = config.get("alternateTemplates", templateName )
410  #print "replacing default %s template by %s"%( templateName, newTemplateName)
411  configTemplates.alternateTemplate(templateName, newTemplateName)
412 
413 
414 ####################--- Main ---############################
415 def main(argv = None):
416  if argv == None:
417  argv = sys.argv[1:]
418  optParser = optparse.OptionParser()
419  optParser.description = """All-in-one Alignment Validation.
420 This will run various validation procedures either on batch queues or interactviely.
421 If no name is given (-N parameter) a name containing time and date is created automatically.
422 To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
423 """
424  optParser.add_option("-n", "--dryRun", dest="dryRun", action="store_true", default=False,
425  help="create all scripts and cfg File but do not start jobs (default=False)")
426  optParser.add_option( "--getImages", dest="getImages", action="store_true", default=False,
427  help="get all Images created during the process (default= False)")
428  defaultConfig = "TkAlConfig.ini"
429  optParser.add_option("-c", "--config", dest="config", default = defaultConfig,
430  help="configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge", metavar="CONFIG")
431  optParser.add_option("-N", "--Name", dest="Name",
432  help="Name of this validation (default: alignmentValidation_DATE_TIME)", metavar="NAME")
433  optParser.add_option("-r", "--restrictTo", dest="restrictTo",
434  help="restrict validations to given modes (comma seperated) (default: no restriction)", metavar="RESTRICTTO")
435  optParser.add_option("-s", "--status", dest="crabStatus", action="store_true", default = False,
436  help="get the status of the crab jobs", metavar="STATUS")
437  optParser.add_option("-d", "--debug", dest="debugMode", action="store_true",
438  default = False,
439  help="run the tool to get full traceback of errors",
440  metavar="DEBUG")
441  optParser.add_option("-m", "--autoMerge", dest="autoMerge", action="store_true", default = False,
442  help="submit TkAlMerge.sh to run automatically when all jobs have finished (default=False)."
443  " Works only for batch jobs")
444 
445  (options, args) = optParser.parse_args(argv)
446 
447  if not options.restrictTo == None:
448  options.restrictTo = options.restrictTo.split(",")
449 
450  options.config = [ os.path.abspath( iniFile ) for iniFile in \
451  options.config.split( "," ) ]
452  config = BetterConfigParser()
453  outputIniFileSet = set( config.read( options.config ) )
454  failedIniFiles = [ iniFile for iniFile in options.config if iniFile not in outputIniFileSet ]
455 
456  # Check for missing ini file
457  if options.config == [ os.path.abspath( defaultConfig ) ]:
458  if ( not options.crabStatus ) and \
459  ( not os.path.exists( defaultConfig ) ):
460  raise AllInOneError, ( "Default 'ini' file '%s' not found!\n"
461  "You can specify another name with the "
462  "command line option '-c'/'--config'."
463  %( defaultConfig ))
464  else:
465  for iniFile in failedIniFiles:
466  if not os.path.exists( iniFile ):
467  raise AllInOneError, ( "'%s' does not exist. Please check for "
468  "typos in the filename passed to the "
469  "'-c'/'--config' option!"
470  %( iniFile ) )
471  else:
472  raise AllInOneError, ( "'%s' does exist, but parsing of the "
473  "content failed!" )
474 
475  # get the job name
476  if options.Name == None:
477  if not options.crabStatus:
478  options.Name = "alignmentValidation_%s"%(datetime.datetime.now().strftime("%y%m%d_%H%M%S"))
479  else:
480  existingValDirs = fnmatch.filter( os.walk( '.' ).next()[1],
481  "alignmentValidation_*" )
482  if len( existingValDirs ) > 0:
483  options.Name = existingValDirs[-1]
484  else:
485  print "Cannot guess last working directory!"
486  print ( "Please use the parameter '-N' or '--Name' to specify "
487  "the task for which you want a status report." )
488  return 1
489 
490  # set output path
491  outPath = os.path.abspath( options.Name )
492 
493  # Check status of submitted jobs and return
494  if options.crabStatus:
495  os.chdir( outPath )
496  crabLogDirs = fnmatch.filter( os.walk('.').next()[1], "crab.*" )
497  if len( crabLogDirs ) == 0:
498  print "Found no crab tasks for job name '%s'"%( options.Name )
499  return 1
500  theCrab = crabWrapper.CrabWrapper()
501  for crabLogDir in crabLogDirs:
502  print
503  print "*" + "=" * 78 + "*"
504  print ( "| Status report and output retrieval for:"
505  + " " * (77 - len( "Status report and output retrieval for:" ) )
506  + "|" )
507  taskName = crabLogDir.replace( "crab.", "" )
508  print "| " + taskName + " " * (77 - len( taskName ) ) + "|"
509  print "*" + "=" * 78 + "*"
510  print
511  crabOptions = { "-getoutput":"",
512  "-c": crabLogDir }
513  try:
514  theCrab.run( crabOptions )
515  except AllInOneError, e:
516  print "crab: No output retrieved for this task."
517  crabOptions = { "-status": "",
518  "-c": crabLogDir }
519  theCrab.run( crabOptions )
520  return
521 
522  general = config.getGeneral()
523  config.set("internals","workdir",os.path.join(general["workdir"],options.Name) )
524  config.set("general","datadir",os.path.join(general["datadir"],options.Name) )
525  config.set("general","logdir",os.path.join(general["logdir"],options.Name) )
526  config.set("general","eosdir",os.path.join("AlignmentValidation", general["eosdir"], options.Name) )
527 
528  # clean up of log directory to avoid cluttering with files with different
529  # random numbers for geometry comparison
530  if os.path.isdir( outPath ):
531  shutil.rmtree( outPath )
532 
533  if not os.path.exists( outPath ):
534  os.makedirs( outPath )
535  elif not os.path.isdir( outPath ):
536  raise AllInOneError,"the file %s is in the way rename the Job or move it away"%outPath
537 
538  # replace default templates by the ones specified in the "alternateTemplates" section
539  loadTemplates( config )
540 
541  #save backup configuration file
542  backupConfigFile = open( os.path.join( outPath, "usedConfiguration.ini" ) , "w" )
543  config.write( backupConfigFile )
544 
545  validations = []
546  for validation in config.items("validation"):
547  alignmentList = validation[1].split(config.getSep())
548  validationsToAdd = [(validation[0],alignment) \
549  for alignment in alignmentList]
550  validations.extend(validationsToAdd)
551  jobs = [ ValidationJob( validation, config, options) \
552  for validation in validations ]
553  map( lambda job: job.createJob(), jobs )
554  validations = [ job.getValidation() for job in jobs ]
555 
556  if "OfflineValidationParallel" not in [val.__class__.__name__ for val in validations]:
557  createMergeScript(outPath, validations)
558  else:
559  createParallelMergeScript( outPath, validations )
560 
561  print
562  map( lambda job: job.runJob(), jobs )
563 
564  if options.autoMerge:
565  # if everything is done as batch job, also submit TkAlMerge.sh to be run
566  # after the jobs have finished
567  if ValidationJob.jobCount == ValidationJob.batchCount and config.getGeneral()["jobmode"].split(",")[0] == "lxBatch":
568  print "> Automatically merging jobs when they have ended"
569  repMap = {
570  "commands": config.getGeneral()["jobmode"].split(",")[1],
571  "jobName": "TkAlMerge",
572  "logDir": config.getGeneral()["logdir"],
573  "script": "TkAlMerge.sh",
574  "bsub": "/afs/cern.ch/cms/caf/scripts/cmsbsub",
575  "conditions": '"' + " && ".join(["ended(" + jobId + ")" for jobId in ValidationJob.batchJobIds]) + '"'
576  }
577  getCommandOutput2("%(bsub)s %(commands)s "
578  "-o %(logDir)s/%(jobName)s.stdout "
579  "-e %(logDir)s/%(jobName)s.stderr "
580  "-w %(conditions)s "
581  "%(logDir)s/%(script)s"%repMap)
582 
583 if __name__ == "__main__":
584  # main(["-n","-N","test","-c","defaultCRAFTValidation.ini,latestObjects.ini","--getImages"])
585  if "-d" in sys.argv[1:] or "--debug" in sys.argv[1:]:
586  main()
587  else:
588  try:
589  main()
590  except AllInOneError, e:
591  print "\nAll-In-One Tool:", str(e)
592  exit(1)
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
— Classes —############################
def main
— Main —############################
def alternateTemplate
### Alternate Templates ###
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def replaceByMap
— Helpers —############################
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
double split
Definition: MVATrainer.cc:139
void set(const std::string &name, int value)
set the flag, with a run-time name