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