test
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": ""}
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  deprecateddefaults = {
102  "DMRMethod":"",
103  "DMRMinimum":"",
104  "DMROptions":"",
105  "OfflineTreeBaseDir":"",
106  "SurfaceShapes":""
107  }
108  defaults.update(deprecateddefaults)
109  defaults.update(addDefaults)
110  PreexistingValidation.__init__(self, valName, config, "offline",
111  defaults, addMandatories)
112  for option in deprecateddefaults:
113  if self.general[option]:
114  raise AllInOneError("The '%s' option has been moved to the [plots:offline] section. Please specify it there."%option)
115 
116  def appendToExtendedValidation( self, validationsSoFar = "" ):
117  """
118  if no argument or "" is passed a string with an instantiation is
119  returned, else the validation is appended to the list
120  """
121  repMap = self.getRepMap()
122  repMap["file"] = self.getCompareStrings("OfflineValidation", plain = True)
123  if validationsSoFar == "":
124  validationsSoFar = ('PlotAlignmentValidation p("%(file)s",'
125  '"%(title)s", %(color)s, %(style)s, .oO[bigtext]Oo.);\n')%repMap
126  else:
127  validationsSoFar += (' p.loadFileList("%(file)s", "%(title)s",'
128  '%(color)s, %(style)s);\n')%repMap
129  return validationsSoFar
130 
132  def __init__(self, valName, config,
133  addDefaults = {}, addMandatories=[]):
134  defaults = {"subdetector": "BPIX"}
135  defaults.update(addDefaults)
136  PreexistingValidation.__init__(self, valName, config, "split",
137  defaults, addMandatories)
138  def appendToExtendedValidation( self, validationsSoFar = "" ):
139  """
140  if no argument or "" is passed a string with an instantiation is
141  returned, else the validation is appended to the list
142  """
143  repMap = self.getRepMap()
144  comparestring = self.getCompareStrings("TrackSplittingValidation")
145  if validationsSoFar != "":
146  validationsSoFar += ',"\n "'
147  validationsSoFar += comparestring
148  return validationsSoFar
149 
151  def __init__(self, valName, config,
152  addDefaults = {}, addMandatories=[]):
153  PreexistingValidation.__init__(self, valName, config, "mcValidate",
154  addDefaults, addMandatories)
155 
157  def __init__(self, *args, **kwargs):
158  raise AllInOneError("Preexisting Z->mumu validation not implemented")
159  #more complicated, it has multiple output files
160 
162  def __init__(self, *args, **kwargs):
163  raise AllInOneError("Preexisting geometry comparison not implemented")