Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:27

0001 from __future__ import print_function
0002 from builtins import range
0003 import itertools
0004 
0005 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
0006 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
0007 from PhysicsTools.HeppyCore.framework.event import Event
0008 from PhysicsTools.HeppyCore.statistics.counter import Counter, Counters
0009 
0010 from DataFormats.FWLite import Events, Handle,Lumis
0011 
0012 class ProvenanceAnalyzer( Analyzer ):
0013     #---------------------------------------------
0014     # TO FINDS THE INITIAL EVENTS BEFORE THE SKIM
0015     #---------------------------------------------
0016     
0017     def __init__(self, cfg_ana, cfg_comp, looperName):
0018         super(ProvenanceAnalyzer, self).__init__(cfg_ana, cfg_comp, looperName)
0019         self.lastId = (0,0)
0020         self.provenance = []
0021  
0022     def declareHandles(self):
0023         super(ProvenanceAnalyzer, self).declareHandles()
0024     
0025     def cmsswVNums(self, release):
0026         vpieces = release.split("_")[1:]
0027         vnums = [ int(v) for v in vpieces[:3] ]
0028         if len(vpieces) > 3:
0029             if "patch" in vpieces[3]:
0030                 vnums.append(int(vpieces[3].replace("patch","")))
0031             elif "pre" in vpieces[3]:
0032                 vnums.append(-100+int(vpieces[3].replace("pre","")))
0033         else:
0034             vnums.append(0)
0035         return tuple(vnums)
0036     def miniAODVersion(self, vnums):
0037         if vnums[:2] == (7,4):
0038             if vnums >= (7,4,14,0): return (2015,2.1)
0039             if vnums >= (7,4,12,0): return (2015,2.0)
0040             if vnums >= (7,4, 8,1): return (2015,1.1)
0041             return (2015,1.0)
0042         elif vnums[:2] == (7,2):
0043             return (2014,2.1)   
0044         elif vnums[:2] == (7,0):
0045             if vnums >= (7,0,9,1): return (2014,2.0)
0046             return (2014,1.0)
0047         else:
0048             return (-999,-999)
0049 
0050     def process(self, event):
0051         eid = (  event.input.eventAuxiliary().id().run(),
0052                  event.input.eventAuxiliary().id().luminosityBlock() )
0053         if eid != self.lastId:
0054             #import pdb; pdb.set_trace()
0055             history = event.input.object().processHistory()
0056             for i in reversed(list(range(history.size()))):
0057                 conf = history.at(i)
0058                 release = conf.releaseVersion().replace('"',"")
0059                 vnums = self.cmsswVNums(release)
0060                 if conf.processName() in  ("PAT", "RECO","REC2"):
0061                     print("processing step %d: process %s, release %r %s, miniAOD %s" % (i, conf.processName(), release, vnums, self.miniAODVersion(vnums)))
0062                     self.provenance = [
0063                         ('release', release),
0064                         ('releaseVersion', vnums),
0065                         ('miniAODVersion', self.miniAODVersion(vnums)),
0066                     ]
0067                     break
0068             self.lastId = eid
0069         for key,value in self.provenance:
0070             setattr(event, key, value)
0071         return True
0072 
0073 import PhysicsTools.HeppyCore.framework.config as cfg
0074 setattr(ProvenanceAnalyzer,"defaultConfig", cfg.Analyzer(
0075     class_object = ProvenanceAnalyzer
0076 ))
0077