1 from __future__
import print_function
7 from PhysicsTools.SelectorUtils.centralIDRegistry
import central_id_registry
8 from PhysicsTools.SelectorUtils.VIDCutFlowResult
import VIDCutFlowResult
9 import DataFormats.FWLite
12 ROOT.gSystem.Load(
"libFWCoreFWLite.so");
13 ROOT.gSystem.Load(
"libDataFormatsFWLite.so");
14 ROOT.FWLiteEnabler.enable()
17 ROOT.gInterpreter.Declare(
""" 18 #include "FWCore/ParameterSetReader/interface/ParameterSetReader.h" 20 template <class PhysObj> 21 struct MakeVersionedSelector { 22 MakeVersionedSelector() {} 24 VersionedSelector<edm::Ptr<PhysObj> > operator()(const std::string& pset, const std::string& which_config) { 25 const edm::ParameterSet& temp = edm::readPSetsFrom(pset)->getParameter<edm::ParameterSet>(which_config); 26 return VersionedSelector<edm::Ptr<PhysObj> >(temp); 29 VersionedSelector<edm::Ptr<PhysObj> > operator()() { return VersionedSelector<edm::Ptr<PhysObj> >(); } 32 template <class Collection, 33 class InPhysObj = typename Collection::value_type, 34 class OutPhysObj = typename Collection::value_type> 35 struct MakePtrFromCollection { 36 edm::Ptr<OutPhysObj> operator()(const Collection& coll, unsigned idx) { 37 edm::Ptr<InPhysObj> temp(&coll, idx); 38 return edm::Ptr<OutPhysObj>(temp); 45 import FWCore.ParameterSet.Config as cms 47 from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry 55 """ turn a python cms.PSet into a VID ID """ 56 idname = pythonpset.idName.value().
replace(
'-',
'_') + suffix
57 escaped_pset = config_template%(idname, pythonpset)
59 return builder(escaped_pset,idname)
61 def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
62 return ''.
join(random.choice(chars)
for _
in range(size))
65 def __init__(self, vidSelectorBuilder, ptrMaker, pythonpset = None):
71 if pythonpset
is not None:
72 if hasattr(pythonpset,
'isPOGApproved'):
73 approved = pythonpset.isPOGApproved.value()
75 sys.stderr.write(
'This ID is not POG approved and likely under development!!!!\n')
76 sys.stderr.write(
'Please make sure to report your progress with this ID'\
77 ' at the next relevant POG meeting.\n')
78 del pythonpset.isPOGApproved
80 sys.stderr.write(
'This ID is not POG approved and likely under development!!!!\n')
81 sys.stderr.write(
'Please make sure to report your progress with this ID'\
82 ' at the next relevant POG meeting.\n')
84 expectedmd5 = central_id_registry.getMD5FromName(pythonpset.idName)
86 sys.stderr.write(
"ID: %s\n"%self.
name())
87 sys.stderr.write(
"The expected md5: %s does not match the md5\n"%expectedmd5)
88 sys.stderr.write(
"calculated by the ID: %s please\n"%self.
md5String())
89 sys.stderr.write(
"update your python configuration or determine the source\n")
90 sys.stderr.write(
"of transcription error!\n")
98 if( len(args) == 2
and isinstance(args[1],DataFormats.FWLite.Events) ):
100 elif( len(args) == 2
and isinstance(args[1], int) ):
104 if( len(args) == 3
and isinstance(args[1], int)
and isinstance(args[2], DataFormats.FWLite.Events) ):
109 raise ValueError(
'VIDSelectorBase __call__ with args: "%s" is not a valid call pattern'%(
','.
join([repr(arg)
for arg
in args])))
114 print(
'VID Selector is already initialized, doing nothing!')
116 del process.__instance
117 if hasattr(pythonpset,
'isPOGApproved'):
118 approved = pythonpset.isPOGApproved.value()
120 sys.stderr.write(
'This ID is not POG approved and likely under development!!!!\n')
121 sys.stderr.write(
'Please make sure to report your progress with this ID'\
122 ' at the next relevant POG meeting.\n')
123 del pythonpset.isPOGApproved
125 sys.stderr.write(
'This ID is not POG approved and likely under development!!!!\n')
126 sys.stderr.write(
'Please make sure to report your progress with this ID'\
127 ' at the next relevant POG meeting.\n')
129 expectedmd5 = central_id_registry.getMD5FromName(pythonpset.idName)
131 sys.stderr.write(
"ID: %s\n"%self.
name())
132 sys.stderr.write(
"The expected md5: %s does not match the md5\n"%expectedmd5)
133 sys.stderr.write(
"calculated by the ID: %s please\n"%self.
md5String())
134 sys.stderr.write(
"update your python configuration or determine the source\n")
135 sys.stderr.write(
"of transcription error!\n")
160 out = ROOT.std.stringstream()
def replace(string, replacements)
def process_pset(builder, pythonpset, suffix)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def initialize(self, pythonpset)
def __init__(self, vidSelectorBuilder, ptrMaker, pythonpset=None)
def id_generator(size=6, chars=string.ascii_uppercase+string.digits)
static std::string join(char **cmd)
def howFarInCutFlow(self)