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
std::shared_ptr< StringCutObjectSelector< pat::Tau > > tauFunc_
std::shared_ptr< StringObjectFunction< pat::Photon > > gamFunc_
std::shared_ptr< StringObjectFunction< pat::PFParticle > > pfFunc_
std::shared_ptr< StringCutObjectSelector< pat::PFParticle > > pfFunc_
std::shared_ptr< StringObjectFunction< pat::Jet > > jetFunc_
double operator()(const reco::Candidate &c) const
std::shared_ptr< StringObjectFunction< pat::GenericParticle > > gpFunc_
std::shared_ptr< StringCutObjectSelector< reco::Candidate > > candFunc_
std::shared_ptr< StringObjectFunction< pat::Tau > > tauFunc_
std::shared_ptr< StringObjectFunction< Obj > > tryGet(const std::string &str)
assert(be >=bs)
bool tryEval(const reco::Candidate &c, const std::shared_ptr< StringCutObjectSelector< Obj > > &func) const
std::shared_ptr< StringCutObjectSelector< pat::Photon > > gamFunc_
std::shared_ptr< StringCutObjectSelector< pat::Jet > > jetFunc_
std::shared_ptr< StringCutObjectSelector< pat::Electron > > eleFunc_
std::shared_ptr< StringObjectFunction< reco::Candidate > > candFunc_
std::shared_ptr< StringObjectFunction< pat::MET > > metFunc_
double tryEval(const reco::Candidate &c, const std::shared_ptr< StringObjectFunction< Obj > > &func) const
bool operator()(const reco::Candidate &c) const
std::shared_ptr< StringCutObjectSelector< pat::MET > > metFunc_
std::shared_ptr< StringCutObjectSelector< pat::Muon > > muFunc_
std::shared_ptr< StringObjectFunction< pat::Electron > > eleFunc_
void throwBadType(const std::type_info &ty1) const
std::shared_ptr< StringObjectFunction< pat::Muon > > muFunc_
std::shared_ptr< StringCutObjectSelector< Obj > > tryGet(const std::string &str)
void throwBadType(const std::type_info &ty1) const
#define str(s)
std::shared_ptr< StringCutObjectSelector< pat::GenericParticle > > gpFunc_