CMS 3D CMS Logo

VIDSelectorBase.py
Go to the documentation of this file.
1 import ROOT
2 import string
3 import random
4 import sys
5 
6 from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry
7 from PhysicsTools.SelectorUtils.VIDCutFlowResult import VIDCutFlowResult
8 import DataFormats.FWLite
9 
10 # load FWLite C++ libraries
11 ROOT.gSystem.Load("libFWCoreFWLite.so");
12 ROOT.gSystem.Load("libDataFormatsFWLite.so");
13 ROOT.FWLiteEnabler.enable()
14 
15 config_template = """
16 import FWCore.ParameterSet.Config as cms
17 
18 from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry
19 
20 ebCutOff = 1.479
21 
22 %s = %s
23 """
24 
25 def process_pset( builder, pythonpset, suffix ):
26  """ turn a python cms.PSet into a VID ID """
27  idname = pythonpset.idName.value().replace('-','_') + suffix
28  escaped_pset = config_template%(idname, pythonpset)
29 
30  return builder(escaped_pset,idname)
31 
32 def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
33  return ''.join(random.choice(chars) for _ in range(size))
34 
36  def __init__(self, vidSelectorBuilder, ptrMaker, printer, pythonpset = None):
37  self.__initialized = False
39  self.__printer = printer()
40  self.__ptrMaker = ptrMaker()
41  self.__selectorBuilder = vidSelectorBuilder()
42  self.__instance = None
43  if pythonpset is not None:
44  if hasattr(pythonpset,'isPOGApproved'):
45  approved = pythonpset.isPOGApproved.value()
46  if not approved:
47  sys.stderr.write('This ID is not POG approved and likely under development!!!!\n')
48  sys.stderr.write('Please make sure to report your progress with this ID'\
49  ' at the next relevant POG meeting.\n')
50  del pythonpset.isPOGApproved
51  else:
52  sys.stderr.write('This ID is not POG approved and likely under development!!!!\n')
53  sys.stderr.write('Please make sure to report your progress with this ID'\
54  ' at the next relevant POG meeting.\n')
55  self.__instance = process_pset( self.__selectorBuilder, pythonpset, self.__suffix )
56  expectedmd5 = central_id_registry.getMD5FromName(pythonpset.idName)
57  if expectedmd5 != self.md5String():
58  sys.stderr.write("ID: %s\n"%self.name())
59  sys.stderr.write("The expected md5: %s does not match the md5\n"%expectedmd5)
60  sys.stderr.write("calculated by the ID: %s please\n"%self.md5String())
61  sys.stderr.write("update your python configuration or determine the source\n")
62  sys.stderr.write("of transcription error!\n")
63  self.__initialized = True
64  else:
65  self.__instance = self.__selectorBuilder()
66 
67  def __call__(self,*args):
68  if( len(args) == 1 ):
69  return self.__instance(*args)
70  if( len(args) == 2 and isinstance(args[1],DataFormats.FWLite.Events) ):
71  return self.__instance(args[0],args[1].object().event())
72  elif( len(args) == 2 and isinstance(args[1], int) ):
73  temp = self.__ptrMaker(args[0],args[1])
74  newargs = [temp]
75  return self.__instance(*newargs)
76  if( len(args) == 3 and isinstance(args[1], int) and isinstance(args[2], DataFormats.FWLite.Events) ):
77  temp = self.__ptrMaker(args[0],args[1])
78  newargs = [temp]
79  newargs += [args[2].object().event()]
80  return self.__instance(*newargs)
81  raise ValueError('VIDSelectorBase __call__ with args: "%s" is not a valid call pattern'%(','.join([repr(arg) for arg in args])))
82 
83 
84  def initialize(self,pythonpset):
85  if( self.__initialized ):
86  print 'VID Selector is already initialized, doing nothing!'
87  return
88  del process.__instance
89  if hasattr(pythonpset,'isPOGApproved'):
90  approved = pythonpset.isPOGApproved.value()
91  if not approved:
92  sys.stderr.write('This ID is not POG approved and likely under development!!!!\n')
93  sys.stderr.write('Please make sure to report your progress with this ID'\
94  ' at the next relevant POG meeting.\n')
95  del pythonpset.isPOGApproved
96  else:
97  sys.stderr.write('This ID is not POG approved and likely under development!!!!\n')
98  sys.stderr.write('Please make sure to report your progress with this ID'\
99  ' at the next relevant POG meeting.\n')
100  self.__instance = process_pset( self.__selectorBuilder, pythonpset, self.__suffix )
101  expectedmd5 = central_id_registry.getMD5FromName(pythonpset.idName)
102  if expectedmd5 != self.md5String():
103  sys.stderr.write("ID: %s\n"%self.name())
104  sys.stderr.write("The expected md5: %s does not match the md5\n"%expectedmd5)
105  sys.stderr.write("calculated by the ID: %s please\n"%self.md5String())
106  sys.stderr.write("update your python configuration or determine the source\n")
107  sys.stderr.write("of transcription error!\n")
108  self.__initialized = True
109 
110  def cutFlowSize(self):
111  return self.__instance.cutFlowSize()
112 
113  def cutFlowResult(self):
114  return VIDCutFlowResult(self.__instance.cutFlowResult())
115 
116  def howFarInCutFlow(self):
117  return self.__instance.howFarInCutFlow()
118 
119  def name(self):
120  return self.__instance.name()
121 
122  def bitMap(self):
123  return self.__instance.bitMap()
124 
125  def md5String(self):
126  return self.__instance.md5String()
127 
128  def md55Raw(self):
129  return self.__instance.md55Raw()
130 
131  def __repr__(self):
132  return self.__printer(self.__instance)
def replace(string, replacements)
def process_pset(builder, pythonpset, suffix)
def initialize(self, pythonpset)
def id_generator(size=6, chars=string.ascii_uppercase+string.digits)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def __init__(self, vidSelectorBuilder, ptrMaker, printer, pythonpset=None)
Definition: event.py:1