CMS 3D CMS Logo

ProvenanceAnalyzer.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from builtins import range
3 import itertools
4 
5 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
6 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
7 from PhysicsTools.HeppyCore.framework.event import Event
8 from PhysicsTools.HeppyCore.statistics.counter import Counter, Counters
9 
10 from DataFormats.FWLite import Events, Handle,Lumis
11 
13  #---------------------------------------------
14  # TO FINDS THE INITIAL EVENTS BEFORE THE SKIM
15  #---------------------------------------------
16 
17  def __init__(self, cfg_ana, cfg_comp, looperName):
18  super(ProvenanceAnalyzer, self).__init__(cfg_ana, cfg_comp, looperName)
19  self.lastId = (0,0)
20  self.provenance = []
21 
22  def declareHandles(self):
23  super(ProvenanceAnalyzer, self).declareHandles()
24 
25  def cmsswVNums(self, release):
26  vpieces = release.split("_")[1:]
27  vnums = [ int(v) for v in vpieces[:3] ]
28  if len(vpieces) > 3:
29  if "patch" in vpieces[3]:
30  vnums.append(int(vpieces[3].replace("patch","")))
31  elif "pre" in vpieces[3]:
32  vnums.append(-100+int(vpieces[3].replace("pre","")))
33  else:
34  vnums.append(0)
35  return tuple(vnums)
36  def miniAODVersion(self, vnums):
37  if vnums[:2] == (7,4):
38  if vnums >= (7,4,14,0): return (2015,2.1)
39  if vnums >= (7,4,12,0): return (2015,2.0)
40  if vnums >= (7,4, 8,1): return (2015,1.1)
41  return (2015,1.0)
42  elif vnums[:2] == (7,2):
43  return (2014,2.1)
44  elif vnums[:2] == (7,0):
45  if vnums >= (7,0,9,1): return (2014,2.0)
46  return (2014,1.0)
47  else:
48  return (-999,-999)
49 
50  def process(self, event):
51  eid = ( event.input.eventAuxiliary().id().run(),
52  event.input.eventAuxiliary().id().luminosityBlock() )
53  if eid != self.lastId:
54  #import pdb; pdb.set_trace()
55  history = event.input.object().processHistory()
56  for i in reversed(list(range(history.size()))):
57  conf = history.at(i)
58  release = conf.releaseVersion().replace('"',"")
59  vnums = self.cmsswVNums(release)
60  if conf.processName() in ("PAT", "RECO","REC2"):
61  print("processing step %d: process %s, release %r %s, miniAOD %s" % (i, conf.processName(), release, vnums, self.miniAODVersion(vnums)))
62  self.provenance = [
63  ('release', release),
64  ('releaseVersion', vnums),
65  ('miniAODVersion', self.miniAODVersion(vnums)),
66  ]
67  break
68  self.lastId = eid
69  for key,value in self.provenance:
70  setattr(event, key, value)
71  return True
72 
73 import PhysicsTools.HeppyCore.framework.config as cfg
74 setattr(ProvenanceAnalyzer,"defaultConfig", cfg.Analyzer(
75  class_object = ProvenanceAnalyzer
76 ))
77 
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
core.ProvenanceAnalyzer.ProvenanceAnalyzer.__init__
def __init__(self, cfg_ana, cfg_comp, looperName)
Definition: ProvenanceAnalyzer.py:17
core.ProvenanceAnalyzer.ProvenanceAnalyzer.provenance
provenance
Definition: ProvenanceAnalyzer.py:20
remoteMonitoring_LED_IterMethod_cfg.Analyzer
Analyzer
Definition: remoteMonitoring_LED_IterMethod_cfg.py:32
core.ProvenanceAnalyzer.ProvenanceAnalyzer
Definition: ProvenanceAnalyzer.py:12
core.ProvenanceAnalyzer.ProvenanceAnalyzer.miniAODVersion
def miniAODVersion(self, vnums)
Definition: ProvenanceAnalyzer.py:36
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
core.ProvenanceAnalyzer.ProvenanceAnalyzer.cmsswVNums
def cmsswVNums(self, release)
Definition: ProvenanceAnalyzer.py:25
createfilelist.int
int
Definition: createfilelist.py:10
core.ProvenanceAnalyzer.ProvenanceAnalyzer.declareHandles
def declareHandles(self)
Definition: ProvenanceAnalyzer.py:22
core.ProvenanceAnalyzer.ProvenanceAnalyzer.lastId
lastId
Definition: ProvenanceAnalyzer.py:19
writedatasetfile.run
run
Definition: writedatasetfile.py:27
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
core.ProvenanceAnalyzer.ProvenanceAnalyzer.process
def process(self, event)
Definition: ProvenanceAnalyzer.py:50
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444