CMS 3D CMS Logo

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