CMS 3D CMS Logo

StringParserTools.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_interface_StringParserTools_h
2 #define PhysicsTools_PatUtils_interface_StringParserTools_h
3 
6 
15 
17 public:
19  PATStringObjectFunction(const std::string &string);
20 
21  double operator()(const reco::Candidate &c) const;
22 
23 private:
25  std::shared_ptr<StringObjectFunction<reco::Candidate> > candFunc_;
26 
27  std::shared_ptr<StringObjectFunction<pat::Electron> > eleFunc_;
28  std::shared_ptr<StringObjectFunction<pat::Muon> > muFunc_;
29  std::shared_ptr<StringObjectFunction<pat::Tau> > tauFunc_;
30  std::shared_ptr<StringObjectFunction<pat::Photon> > gamFunc_;
31  std::shared_ptr<StringObjectFunction<pat::Jet> > jetFunc_;
32  std::shared_ptr<StringObjectFunction<pat::MET> > metFunc_;
33  std::shared_ptr<StringObjectFunction<pat::GenericParticle> > gpFunc_;
34  std::shared_ptr<StringObjectFunction<pat::PFParticle> > pfFunc_;
35 
36  template <typename Obj>
37  std::shared_ptr<StringObjectFunction<Obj> > tryGet(const std::string &str) {
38  try {
39  return std::shared_ptr<StringObjectFunction<Obj> >(new StringObjectFunction<Obj>(str));
40  } catch (cms::Exception const &) {
41  return std::shared_ptr<StringObjectFunction<Obj> >();
42  }
43  }
44 
45  template <typename Obj>
46  double tryEval(const reco::Candidate &c, const std::shared_ptr<StringObjectFunction<Obj> > &func) const {
47  if (func.get())
48  return (*func)(static_cast<const Obj &>(c));
49  else
50  throwBadType(typeid(c));
51  assert(false);
52  return 0;
53  }
54 
55  // out of line throw exception
56  void throwBadType(const std::type_info &ty1) const;
57 };
58 
60 public:
63 
64  bool operator()(const reco::Candidate &c) const;
65 
66 private:
68  std::shared_ptr<StringCutObjectSelector<reco::Candidate> > candFunc_;
69 
70  std::shared_ptr<StringCutObjectSelector<pat::Electron> > eleFunc_;
71  std::shared_ptr<StringCutObjectSelector<pat::Muon> > muFunc_;
72  std::shared_ptr<StringCutObjectSelector<pat::Tau> > tauFunc_;
73  std::shared_ptr<StringCutObjectSelector<pat::Photon> > gamFunc_;
74  std::shared_ptr<StringCutObjectSelector<pat::Jet> > jetFunc_;
75  std::shared_ptr<StringCutObjectSelector<pat::MET> > metFunc_;
76  std::shared_ptr<StringCutObjectSelector<pat::GenericParticle> > gpFunc_;
77  std::shared_ptr<StringCutObjectSelector<pat::PFParticle> > pfFunc_;
78 
79  template <typename Obj>
80  std::shared_ptr<StringCutObjectSelector<Obj> > tryGet(const std::string &str) {
81  try {
82  return std::shared_ptr<StringCutObjectSelector<Obj> >(new StringCutObjectSelector<Obj>(str));
83  } catch (cms::Exception const &) {
84  return std::shared_ptr<StringCutObjectSelector<Obj> >();
85  }
86  }
87 
88  template <typename Obj>
89  bool tryEval(const reco::Candidate &c, const std::shared_ptr<StringCutObjectSelector<Obj> > &func) const {
90  if (func.get())
91  return (*func)(static_cast<const Obj &>(c));
92  else
93  throwBadType(typeid(c));
94  assert(false);
95  return false;
96  }
97 
98  // out of line throw exception
99  void throwBadType(const std::type_info &ty1) const;
100 };
101 
102 #endif
PATStringCutObjectSelector::candFunc_
std::shared_ptr< StringCutObjectSelector< reco::Candidate > > candFunc_
Definition: StringParserTools.h:68
PATStringObjectFunction::PATStringObjectFunction
PATStringObjectFunction()
Definition: StringParserTools.h:18
StringObjectFunction
Definition: StringObjectFunction.h:16
PATStringCutObjectSelector::tryEval
bool tryEval(const reco::Candidate &c, const std::shared_ptr< StringCutObjectSelector< Obj > > &func) const
Definition: StringParserTools.h:89
PATStringCutObjectSelector::pfFunc_
std::shared_ptr< StringCutObjectSelector< pat::PFParticle > > pfFunc_
Definition: StringParserTools.h:77
Muon.h
Photon.h
GenericParticle.h
PATStringObjectFunction::tryGet
std::shared_ptr< StringObjectFunction< Obj > > tryGet(const std::string &str)
Definition: StringParserTools.h:37
cms::cuda::assert
assert(be >=bs)
PATStringObjectFunction::pfFunc_
std::shared_ptr< StringObjectFunction< pat::PFParticle > > pfFunc_
Definition: StringParserTools.h:34
PATStringCutObjectSelector::tauFunc_
std::shared_ptr< StringCutObjectSelector< pat::Tau > > tauFunc_
Definition: StringParserTools.h:72
PATStringObjectFunction::jetFunc_
std::shared_ptr< StringObjectFunction< pat::Jet > > jetFunc_
Definition: StringParserTools.h:31
Tau.h
PATStringCutObjectSelector::jetFunc_
std::shared_ptr< StringCutObjectSelector< pat::Jet > > jetFunc_
Definition: StringParserTools.h:74
PATStringObjectFunction::gpFunc_
std::shared_ptr< StringObjectFunction< pat::GenericParticle > > gpFunc_
Definition: StringParserTools.h:33
PATStringObjectFunction::candFunc_
std::shared_ptr< StringObjectFunction< reco::Candidate > > candFunc_
Definition: StringParserTools.h:25
PATStringObjectFunction::tauFunc_
std::shared_ptr< StringObjectFunction< pat::Tau > > tauFunc_
Definition: StringParserTools.h:29
PATStringObjectFunction::tryEval
double tryEval(const reco::Candidate &c, const std::shared_ptr< StringObjectFunction< Obj > > &func) const
Definition: StringParserTools.h:46
str
#define str(s)
Definition: TestProcessor.cc:48
PATStringCutObjectSelector::eleFunc_
std::shared_ptr< StringCutObjectSelector< pat::Electron > > eleFunc_
Definition: StringParserTools.h:70
PATStringCutObjectSelector::PATStringCutObjectSelector
PATStringCutObjectSelector()
Definition: StringParserTools.h:61
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PATStringObjectFunction::eleFunc_
std::shared_ptr< StringObjectFunction< pat::Electron > > eleFunc_
Definition: StringParserTools.h:27
PATStringCutObjectSelector::operator()
bool operator()(const reco::Candidate &c) const
Definition: StringParserTools.cc:62
PATStringCutObjectSelector::metFunc_
std::shared_ptr< StringCutObjectSelector< pat::MET > > metFunc_
Definition: StringParserTools.h:75
PATStringCutObjectSelector::gamFunc_
std::shared_ptr< StringCutObjectSelector< pat::Photon > > gamFunc_
Definition: StringParserTools.h:73
PATStringObjectFunction::metFunc_
std::shared_ptr< StringObjectFunction< pat::MET > > metFunc_
Definition: StringParserTools.h:32
PFParticle.h
PATStringObjectFunction::expr_
std::string expr_
Definition: StringParserTools.h:24
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
MET.h
Jet.h
reco::Candidate
Definition: Candidate.h:27
PATStringCutObjectSelector::gpFunc_
std::shared_ptr< StringCutObjectSelector< pat::GenericParticle > > gpFunc_
Definition: StringParserTools.h:76
PATStringCutObjectSelector::throwBadType
void throwBadType(const std::type_info &ty1) const
Definition: StringParserTools.cc:87
PATStringObjectFunction
Definition: StringParserTools.h:16
PATStringObjectFunction::throwBadType
void throwBadType(const std::type_info &ty1) const
Definition: StringParserTools.cc:43
StringCutObjectSelector.h
StringCutObjectSelector
Definition: StringCutObjectSelector.h:16
Electron.h
PATStringObjectFunction::gamFunc_
std::shared_ptr< StringObjectFunction< pat::Photon > > gamFunc_
Definition: StringParserTools.h:30
PATStringCutObjectSelector::muFunc_
std::shared_ptr< StringCutObjectSelector< pat::Muon > > muFunc_
Definition: StringParserTools.h:71
cms::Exception
Definition: Exception.h:70
StringObjectFunction.h
PATStringObjectFunction::muFunc_
std::shared_ptr< StringObjectFunction< pat::Muon > > muFunc_
Definition: StringParserTools.h:28
PATStringCutObjectSelector::tryGet
std::shared_ptr< StringCutObjectSelector< Obj > > tryGet(const std::string &str)
Definition: StringParserTools.h:80
PATStringObjectFunction::operator()
double operator()(const reco::Candidate &c) const
Definition: StringParserTools.cc:18
PATStringCutObjectSelector
Definition: StringParserTools.h:59
PATStringCutObjectSelector::expr_
std::string expr_
Definition: StringParserTools.h:67