CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
preexistingValidation.py
Go to the documentation of this file.
1 import os
2 from genericValidation import GenericValidation, GenericValidationData
3 from geometryComparison import GeometryComparison
4 from helperFunctions import getCommandOutput2, parsecolor, parsestyle
5 from monteCarloValidation import MonteCarloValidation
6 from offlineValidation import OfflineValidation
7 from TkAlExceptions import AllInOneError
8 from trackSplittingValidation import TrackSplittingValidation
9 from zMuMuValidation import ZMuMuValidation
10 
12  """
13  Object representing a validation that has already been run,
14  but should be included in plots.
15  """
16  def __init__(self, valName, config, valType,
17  addDefaults = {}, addMandatories=[]):
18  self.name = valName
19  self.general = config.getGeneral()
20  self.config = config
21  self.filesToCompare = {}
22 
23  defaults = {"title": self.name, "jobid": "", "subdetector": "BPIX"}
24  defaults.update(addDefaults)
25  mandatories = ["file", "color", "style"]
26  mandatories += addMandatories
27 
28  theUpdate = config.getResultingSection("preexisting"+valType+":"+self.name,
29  defaultDict = defaults,
30  demandPars = mandatories)
31  self.general.update(theUpdate)
32 
33  self.title = self.general["title"]
34  if "|" in self.title or "," in self.title or '"' in self.title:
35  msg = "The characters '|', '\"', and ',' cannot be used in the alignment title!"
36  raise AllInOneError(msg)
37 
38  self.jobid = self.general["jobid"]
39  if self.jobid:
40  try: #make sure it's actually a valid jobid
41  output = getCommandOutput2("bjobs %(jobid)s 2>&1"%self.general)
42  if "is not found" in output: raise RuntimeError
43  except RuntimeError:
44  raise AllInOneError("%s is not a valid jobid.\nMaybe it finished already?"%self.jobid)
45 
46  self.filesToCompare[GenericValidationData.defaultReferenceName] = \
47  self.general["file"]
48 
49  knownOpts = defaults.keys()+mandatories
50  ignoreOpts = []
51  config.checkInput("preexisting"+valType+":"+self.name,
52  knownSimpleOptions = knownOpts,
53  ignoreOptions = ignoreOpts)
54  self.jobmode = None
55 
56  def getRepMap(self):
57  result = self.general
58  result.update({
59  "color": str(parsecolor(result["color"])),
60  "style": str(parsestyle(result["style"])),
61  })
62  return result
63 
64  def getCompareStrings( self, requestId = None, plain = False ):
65  result = {}
66  repMap = self.getRepMap()
67  for validationId in self.filesToCompare:
68  repMap["file"] = self.filesToCompare[ validationId ]
69  if repMap["file"].startswith( "/castor/" ):
70  repMap["file"] = "rfio:%(file)s"%repMap
71  elif repMap["file"].startswith( "/store/" ):
72  repMap["file"] = "root://eoscms.cern.ch//eos/cms%(file)s"%repMap
73  if plain:
74  result[validationId]=repMap["file"]
75  else:
76  result[validationId]= "%(file)s=%(title)s|%(color)s|%(style)s"%repMap
77  if requestId == None:
78  return result
79  else:
80  if not "." in requestId:
81  requestId += ".%s"%GenericValidation.defaultReferenceName
82  if not requestId.split(".")[-1] in result:
83  msg = ("could not find %s in reference Objects!"
84  %requestId.split(".")[-1])
85  raise AllInOneError(msg)
86  return result[ requestId.split(".")[-1] ]
87 
88  def createFiles(self, *args, **kwargs):
89  raise AllInOneError("Shouldn't be here...")
90  def createConfiguration(self, *args, **kwargs):
91  pass
92  def createScript(self, *args, **kwargs):
93  raise AllInOneError("Shouldn't be here...")
94  def createCrabCfg(self, *args, **kwargs):
95  raise AllInOneError("Shouldn't be here...")
96 
98  def __init__(self, valName, config,
99  addDefaults = {}, addMandatories=[]):
100  defaults = {
101  "DMRMethod":"median,rmsNorm",
102  "DMRMinimum":"30",
103  "DMROptions":"",
104  "OfflineTreeBaseDir":"TrackHitFilter",
105  "SurfaceShapes":"coarse",
106  }
107  defaults.update(addDefaults)
108  PreexistingValidation.__init__(self, valName, config, "offline",
109  defaults, addMandatories)
110  def appendToExtendedValidation( self, validationsSoFar = "" ):
111  """
112  if no argument or "" is passed a string with an instantiation is
113  returned, else the validation is appended to the list
114  """
115  repMap = self.getRepMap()
116  repMap["file"] = self.getCompareStrings("OfflineValidation", plain = True)
117  if validationsSoFar == "":
118  validationsSoFar = ('PlotAlignmentValidation p("%(file)s",'
119  '"%(title)s", %(color)s, %(style)s);\n')%repMap
120  else:
121  validationsSoFar += (' p.loadFileList("%(file)s", "%(title)s",'
122  '%(color)s, %(style)s);\n')%repMap
123  return validationsSoFar
124 
126  def __init__(self, valName, config,
127  addDefaults = {}, addMandatories=[]):
128  PreexistingValidation.__init__(self, valName, config, "split",
129  addDefaults, addMandatories)
130  def appendToExtendedValidation( self, validationsSoFar = "" ):
131  """
132  if no argument or "" is passed a string with an instantiation is
133  returned, else the validation is appended to the list
134  """
135  repMap = self.getRepMap()
136  comparestring = self.getCompareStrings("TrackSplittingValidation")
137  if validationsSoFar != "":
138  validationsSoFar += ',"\n "'
139  validationsSoFar += comparestring
140  return validationsSoFar
141 
143  def __init__(self, valName, config,
144  addDefaults = {}, addMandatories=[]):
145  PreexistingValidation.__init__(self, valName, config, "mcValidate",
146  addDefaults, addMandatories)
147 
149  def __init__(self, *args, **kwargs):
150  raise AllInOneError("Preexisting Z->mumu validation not implemented")
151  #more complicated, it has multiple output files
152 
154  def __init__(self, *args, **kwargs):
155  raise AllInOneError("Preexisting geometry comparison not implemented")