CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
23 """
24 
25 def process_pset( builder, pythonpset ):
26  """ turn a python cms.PSet into a VID ID """
27  escaped_pset = config_template%(pythonpset)
28 
29  idname = pythonpset.idName.value().replace('-','_')
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 )
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 type(args[1]) is int ):
74  temp = self.__ptrMaker(args[0],args[1])
75  newargs = [temp]
76  return self.__instance(*newargs)
77  if( len(args) == 3 ):
78  temp = self.__ptrMaker(args[0],args[1])
79  newargs = [temp]
80  newargs += [args[2].object().event()]
81  return self.__instance(*newargs)
82 
83  def initialize(self,pythonpset):
84  if( self.__initialized ):
85  print 'VID Selector is already initialized, doing nothing!'
86  return
87  del process.__instance
88  if hasattr(pythonpset,'isPOGApproved'):
89  approved = pythonpset.isPOGApproved.value()
90  if not approved:
91  sys.stderr.write('This ID is not POG approved and likely under development!!!!\n')
92  sys.stderr.write('Please make sure to report your progress with this ID'\
93  ' at the next relevant POG meeting.\n')
94  del pythonpset.isPOGApproved
95  else:
96  sys.stderr.write('This ID is not POG approved and likely under development!!!!\n')
97  sys.stderr.write('Please make sure to report your progress with this ID'\
98  ' at the next relevant POG meeting.\n')
99  self.__instance = process_pset( self.__selectorBuilder, pythonpset )
100  expectedmd5 = central_id_registry.getMD5FromName(pythonpset.idName)
101  if expectedmd5 != self.md5String():
102  sys.stderr.write("ID: %s\n"%self.name())
103  sys.stderr.write("The expected md5: %s does not match the md5\n"%expectedmd5)
104  sys.stderr.write("calculated by the ID: %s please\n"%self.md5String())
105  sys.stderr.write("update your python configuration or determine the source\n")
106  sys.stderr.write("of transcription error!\n")
107  self.__initialized = True
108 
109  def cutFlowSize(self):
110  return self.__instance.cutFlowSize()
111 
112  def cutFlowResult(self):
113  return VIDCutFlowResult(self.__instance.cutFlowResult())
114 
115  def howFarInCutFlow(self):
116  return self.__instance.howFarInCutFlow()
117 
118  def name(self):
119  return self.__instance.name()
120 
121  def bitMap(self):
122  return self.__instance.bitMap()
123 
124  def md5String(self):
125  return self.__instance.md5String()
126 
127  def md55Raw(self):
128  return self.__instance.md55Raw()
129 
130  def __repr__(self):
131  return self.__printer(self.__instance)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
list object
Definition: dbtoconf.py:77
if(conf.exists("allCellsPositionCalc"))
Definition: event.py:1