CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
trackSplittingValidation.py
Go to the documentation of this file.
1 import os
2 import configTemplates
3 from genericValidation import GenericValidationData
4 from helperFunctions import replaceByMap
5 from TkAlExceptions import AllInOneError
6 
7 
9  def __init__(self, valName, alignment, config,
10  configBaseName = "TkAlTrackSplitting", scriptBaseName = "TkAlTrackSplitting", crabCfgBaseName = "TkAlTrackSplitting",
11  resultBaseName = "TrackSplitting", outputBaseName = "TrackSplitting"):
12  mandatories = ["trackcollection"]
13  defaults = {"subdetector": "BPIX"}
14  self.configBaseName = configBaseName
15  self.scriptBaseName = scriptBaseName
16  self.crabCfgBaseName = crabCfgBaseName
17  self.resultBaseName = resultBaseName
18  self.outputBaseName = outputBaseName
19  self.needParentFiles = False
20  GenericValidationData.__init__(self, valName, alignment, config,
21  "split", addMandatories = mandatories, addDefaults = defaults)
22  validsubdets = self.validsubdets()
23  if self.general["subdetector"] not in validsubdets:
24  raise AllInOneError("'%s' is not a valid subdetector!\n" % self.general["subdetector"] + "The options are: " + ", ".join(validsubdets))
25 
26  def createConfiguration(self, path ):
27  cfgName = "%s.%s.%s_cfg.py"%(self.configBaseName, self.name,
28  self.alignmentToValidate.name)
29  repMap = self.getRepMap()
30  cfgs = {cfgName: configTemplates.TrackSplittingTemplate}
31  self.filesToCompare[GenericValidationData.defaultReferenceName] = \
32  repMap["finalResultFile"]
33  GenericValidationData.createConfiguration(self, cfgs, path, repMap = repMap)
34 
35  def createScript(self, path):
36  return GenericValidationData.createScript(self, path)
37 
38  def createCrabCfg(self, path):
39  return GenericValidationData.createCrabCfg(self, path, self.crabCfgBaseName)
40 
41  def getRepMap( self, alignment = None ):
42  repMap = GenericValidationData.getRepMap(self)
43  if self.general["subdetector"] == "none":
44  subdetselection = ""
45  else:
46  subdetselection = "process.AlignmentTrackSelector.minHitsPerSubDet.in.oO[subdetector]Oo. = 2"
47  repMap.update({
48  "nEvents": self.general["maxevents"],
49  "TrackCollection": self.general["trackcollection"],
50  "subdetselection": subdetselection,
51  "subdetector": self.general["subdetector"],
52  })
53  # repMap["outputFile"] = os.path.abspath( repMap["outputFile"] )
54  # if self.jobmode.split( ',' )[0] == "crab":
55  # repMap["outputFile"] = os.path.basename( repMap["outputFile"] )
56  return repMap
57 
58 
59  def appendToExtendedValidation( self, validationsSoFar = "" ):
60  """
61  if no argument or "" is passed a string with an instantiation is
62  returned, else the validation is appended to the list
63  """
64  repMap = self.getRepMap()
65  comparestring = self.getCompareStrings("TrackSplittingValidation")
66  if validationsSoFar != "":
67  validationsSoFar += ',"\n "'
68  validationsSoFar += comparestring
69  return validationsSoFar
70 
71  def appendToMerge( self, validationsSoFar = "" ):
72  """
73  if no argument or "" is passed a string with an instantiation is returned,
74  else the validation is appended to the list
75  """
76  repMap = self.getRepMap()
77 
78  parameters = " ".join(os.path.join("root://eoscms//eos/cms", file.lstrip("/")) for file in repMap["resultFiles"])
79 
80  mergedoutputfile = os.path.join("root://eoscms//eos/cms", repMap["finalResultFile"].lstrip("/"))
81  validationsSoFar += "hadd -f %s %s\n" % (mergedoutputfile, parameters)
82  return validationsSoFar
83 
84  def validsubdets(self):
85  filename = os.path.join(self.cmssw, "src/Alignment/CommonAlignmentProducer/python/AlignmentTrackSelector_cfi.py")
86  if not os.path.isfile(filename):
87  filename = os.path.join(self.cmsswreleasebase, "src/Alignment/CommonAlignmentProducer/python/AlignmentTrackSelector_cfi.py")
88  with open(filename) as f:
89  trackselector = f.read()
90 
91  minhitspersubdet = trackselector.split("minHitsPerSubDet")[1].split("(",1)[1]
92 
93  parenthesesdepth = 0
94  i = 0
95  for character in minhitspersubdet:
96  if character == "(":
97  parenthesesdepth += 1
98  if character == ")":
99  parenthesesdepth -= 1
100  if parenthesesdepth < 0:
101  break
102  i += 1
103  minhitspersubdet = minhitspersubdet[0:i]
104 
105  results = minhitspersubdet.split(",")
106  empty = []
107  for i in range(len(results)):
108  results[i] = results[i].split("=")[0].strip().replace("in", "", 1)
109 
110  results.append("none")
111 
112  return [a for a in results if a]
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139