CMS 3D CMS Logo

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