CMS 3D CMS Logo

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