CMS 3D CMS Logo

offlineValidation.py
Go to the documentation of this file.
1 import os
2 import configTemplates
3 import globalDictionaries
4 from genericValidation import GenericValidationData
5 from helperFunctions import replaceByMap, addIndex
6 from TkAlExceptions import AllInOneError
7 
8 
10  def __init__(self, valName, alignment, config, addDefaults = {}, addMandatories = [],
11  configBaseName = "TkAlOfflineValidation", scriptBaseName = "TkAlOfflineValidation", crabCfgBaseName = "TkAlOfflineValidation",
12  resultBaseName = "AlignmentValidation", outputBaseName = "AlignmentValidation"):
13  defaults = {
14  "offlineModuleLevelHistsTransient":"False",
15  "offlineModuleLevelProfiles":"True",
16  "stripYResiduals":"False",
17  }
18  deprecateddefaults = {
19  "DMRMethod":"",
20  "DMRMinimum":"",
21  "DMROptions":"",
22  "OfflineTreeBaseDir":"",
23  "SurfaceShapes":"",
24  }
25 
26  mandatories = [ "trackcollection" ]
27  defaults.update(deprecateddefaults)
28  defaults.update(addDefaults)
29  mandatories += addMandatories
30  self.configBaseName = configBaseName
31  self.scriptBaseName = scriptBaseName
32  self.crabCfgBaseName = crabCfgBaseName
33  self.resultBaseName = resultBaseName
34  self.outputBaseName = outputBaseName
35  self.needParentFiles = False
36  GenericValidationData.__init__(self, valName, alignment, config,
37  "offline", addDefaults=defaults,
38  addMandatories=mandatories)
39 
40  for option in deprecateddefaults:
41  if self.general[option]:
42  raise AllInOneError("The '%s' option has been moved to the [plots:offline] section. Please specify it there."%option)
43  del self.general[option]
44 
45  def createConfiguration(self, path):
46  cfgName = "%s.%s.%s_cfg.py"%( self.configBaseName, self.name,
47  self.alignmentToValidate.name )
48  repMap = self.getRepMap()
49  if self.NJobs > 1 and self.general["offlineModuleLevelHistsTransient"] == "True":
50  msg = ("To be able to merge results when running parallel jobs,"
51  " set offlineModuleLevelHistsTransient to false.")
52  raise AllInOneError(msg)
53 
54  templateToUse = configTemplates.offlineTemplate
55  if self.AutoAlternates:
56  if "Cosmics" in self.general["trackcollection"]:
57  Bfield = self.dataset.magneticFieldForRun()
58  if Bfield > 3.3 and Bfield < 4.3: #Should never be 4.3, but this covers strings, which always compare bigger than ints
59  templateToUse = configTemplates.CosmicsOfflineValidation
60  print ("B field for %s = %sT. Using the template for cosmics at 3.8T.\n"
61  "To override this behavior, specify AutoAlternates = false in the [alternateTemplates] section") % (self.dataset.name(), Bfield)
62  elif Bfield < 0.5:
63  templateToUse = configTemplates.CosmicsAt0TOfflineValidation
64  print ("B field for %s = %sT. Using the template for cosmics at 0T.\n"
65  "To override this behavior, specify AutoAlternates = false in the [alternateTemplates] section") % (self.dataset.name(), Bfield)
66  else:
67  try:
68  if "unknown " in Bfield:
69  msg = Bfield.replace("unknown ","",1)
70  elif "Bfield" is "unknown":
71  msg = "Can't get the B field for %s." % self.dataset.name()
72  except TypeError:
73  msg = "B field for %s = %sT. This is not that close to 0T or 3.8T." % (self.dataset.name(), Bfield)
74  raise AllInOneError(msg + "\n"
75  "To use this data, turn off the automatic alternates using AutoAlternates = false\n"
76  "in the [alternateTemplates] section, and choose the alternate template yourself.")
77 
78  cfgs = {cfgName: templateToUse}
79  self.filesToCompare[
80  GenericValidationData.defaultReferenceName ] = repMap["finalResultFile"]
81  return GenericValidationData.createConfiguration(self, cfgs, path, repMap = repMap)
82 
83  def createScript(self, path):
84  return GenericValidationData.createScript(self, path)
85 
86 
87  def createCrabCfg(self, path):
88  return GenericValidationData.createCrabCfg(self, path, self.crabCfgBaseName)
89 
90  def getRepMap(self, alignment = None):
91  repMap = GenericValidationData.getRepMap(self, alignment)
92  repMap.update({
93  "nEvents": self.general["maxevents"],
94  "TrackSelectionTemplate": configTemplates.TrackSelectionTemplate,
95  "LorentzAngleTemplate": configTemplates.LorentzAngleTemplate,
96  "offlineValidationMode": "Standalone",
97  "offlineValidationFileOutput": configTemplates.offlineFileOutputTemplate,
98  "TrackCollection": self.general["trackcollection"],
99  })
100 
101  return repMap
102 
103  def appendToExtendedValidation( self, validationsSoFar = "" ):
104  """
105  if no argument or "" is passed a string with an instantiation is
106  returned, else the validation is appended to the list
107  """
108  repMap = self.getRepMap()
109  if validationsSoFar == "":
110  validationsSoFar = ('PlotAlignmentValidation p("root://eoscms//eos/cms%(finalResultFile)s",'
111  '"%(title)s", %(color)s, %(style)s, .oO[bigtext]Oo.);\n')%repMap
112  else:
113  validationsSoFar += (' p.loadFileList("root://eoscms//eos/cms%(finalResultFile)s", "%(title)s",'
114  '%(color)s, %(style)s);\n')%repMap
115  return validationsSoFar
116 
117  def appendToMerge( self, validationsSoFar = "" ):
118  """
119  if no argument or "" is passed a string with an instantiation is returned,
120  else the validation is appended to the list
121  """
122  repMap = self.getRepMap()
123 
124  parameters = "root://eoscms//eos/cms" + ",root://eoscms//eos/cms".join(repMap["resultFiles"])
125 
126  mergedoutputfile = "root://eoscms//eos/cms%(finalResultFile)s"%repMap
127  validationsSoFar += ('root -x -b -q -l "TkAlOfflineJobsMerge.C(\\\"'
128  +parameters+'\\\",\\\"'+mergedoutputfile+'\\\")"'
129  +"\n")
130  return validationsSoFar
131 
133  def __init__(self, valName, alignment, config, configBaseName = "TkAlOfflineValidationDQM"):
134  OfflineValidation.__init__(self, valName, alignment, config,
135  configBaseName = configBaseName)
136  if not config.has_section("DQM"):
137  msg = "You need to have a DQM section in your configfile!"
138  raise AllInOneError(msg)
139 
140  self.__PrimaryDataset = config.get("DQM", "primaryDataset")
141  self.__firstRun = int(config.get("DQM", "firstRun"))
142  self.__lastRun = int(config.get("DQM", "lastRun"))
143 
144  def createConfiguration(self, path):
145  OfflineValidation.createConfiguration(self, path)
146 
147  def createScript(self, path):
148  return OfflineValidation.createScript(self, path)
149 
150  def getRepMap(self, alignment = None):
151  repMap = OfflineValidation.getRepMap(self, alignment)
152  repMap.update({
153  "workdir": os.path.expandvars(repMap["workdir"]),
154  "offlineValidationMode": "Dqm",
155  "offlineValidationFileOutput": configTemplates.offlineDqmFileOutputTemplate,
156  "workflow": ("/%s/TkAl%s-.oO[alignmentName]Oo._R%09i_R%09i_"
157  "ValSkim-v1/ALCARECO"
158  %(self.__PrimaryDataset,
159  datetime.datetime.now().strftime("%y"),
160  self.__firstRun, self.__lastRun)),
161  "firstRunNumber": "%i"% self.__firstRun
162  })
163  if "__" in repMap["workflow"]:
164  msg = ("the DQM workflow specefication must not contain '__'. "
165  "it is: %s"%repMap["workflow"])
166  raise AllInOneError(msg)
167  return repMap
def appendToExtendedValidation(self, validationsSoFar="")
def getRepMap(self, alignment=None)
def appendToMerge(self, validationsSoFar="")
def __init__(self, valName, alignment, config, configBaseName="TkAlOfflineValidationDQM")
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def __init__(self, valName, alignment, config, addDefaults={}, addMandatories=[], configBaseName="TkAlOfflineValidation", scriptBaseName="TkAlOfflineValidation", crabCfgBaseName="TkAlOfflineValidation", resultBaseName="AlignmentValidation", outputBaseName="AlignmentValidation")
def getRepMap(self, alignment=None)