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  repMap.update({
44  "nEvents": self.general["maxevents"],
45  "TrackCollection": self.general["trackcollection"],
46  "subdetector": self.general["subdetector"],
47  })
48  # repMap["outputFile"] = os.path.abspath( repMap["outputFile"] )
49  # if self.jobmode.split( ',' )[0] == "crab":
50  # repMap["outputFile"] = os.path.basename( repMap["outputFile"] )
51  return repMap
52 
53 
54  def appendToExtendedValidation( self, validationsSoFar = "" ):
55  """
56  if no argument or "" is passed a string with an instantiation is
57  returned, else the validation is appended to the list
58  """
59  repMap = self.getRepMap()
60  comparestring = self.getCompareStrings("TrackSplittingValidation")
61  if validationsSoFar != "":
62  validationsSoFar += ',"\n "'
63  validationsSoFar += comparestring
64  return validationsSoFar
65 
66  def appendToMerge( self, validationsSoFar = "" ):
67  """
68  if no argument or "" is passed a string with an instantiation is returned,
69  else the validation is appended to the list
70  """
71  repMap = self.getRepMap()
72 
73  parameters = " ".join(os.path.join("root://eoscms//eos/cms", file.lstrip("/")) for file in repMap["resultFiles"])
74 
75  mergedoutputfile = os.path.join("root://eoscms//eos/cms", repMap["finalResultFile"].lstrip("/"))
76  validationsSoFar += "hadd -f %s %s\n" % (mergedoutputfile, parameters)
77  return validationsSoFar
78 
79  def validsubdets(self):
80  filename = os.path.join(self.cmssw, "src/Alignment/CommonAlignmentProducer/python/AlignmentTrackSelector_cfi.py")
81  if not os.path.isfile(filename):
82  filename = os.path.join(self.cmsswreleasebase, "src/Alignment/CommonAlignmentProducer/python/AlignmentTrackSelector_cfi.py")
83  with open(filename) as f:
84  trackselector = f.read()
85 
86  minhitspersubdet = trackselector.split("minHitsPerSubDet")[1].split("(",1)[1]
87 
88  parenthesesdepth = 0
89  i = 0
90  for character in minhitspersubdet:
91  if character == "(":
92  parenthesesdepth += 1
93  if character == ")":
94  parenthesesdepth -= 1
95  if parenthesesdepth < 0:
96  break
97  i += 1
98  minhitspersubdet = minhitspersubdet[0:i]
99 
100  results = minhitspersubdet.split(",")
101  empty = []
102  for i in range(len(results)):
103  results[i] = results[i].split("=")[0].strip().replace("in", "", 1)
104 
105  return [a for a in results if a]
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139