CMS 3D CMS Logo

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