test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StringParserTools.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_interface_StringParserTools_h
2 #define PhysicsTools_PatUtils_interface_StringParserTools_h
3 
4 #include <boost/shared_ptr.hpp>
7 
16 
18 
19 public:
21  PATStringObjectFunction(const std::string &string) ;
22 
23  double operator()(const reco::Candidate &c) const ;
24 
25 private:
27  boost::shared_ptr<StringObjectFunction<reco::Candidate> > candFunc_;
28 
29  boost::shared_ptr<StringObjectFunction<pat::Electron> > eleFunc_;
30  boost::shared_ptr<StringObjectFunction<pat::Muon> > muFunc_;
31  boost::shared_ptr<StringObjectFunction<pat::Tau> > tauFunc_;
32  boost::shared_ptr<StringObjectFunction<pat::Photon> > gamFunc_;
33  boost::shared_ptr<StringObjectFunction<pat::Jet> > jetFunc_;
34  boost::shared_ptr<StringObjectFunction<pat::MET> > metFunc_;
35  boost::shared_ptr<StringObjectFunction<pat::GenericParticle> > gpFunc_;
36  boost::shared_ptr<StringObjectFunction<pat::PFParticle> > pfFunc_;
37 
38  template<typename Obj>
39  boost::shared_ptr<StringObjectFunction<Obj> > tryGet(const std::string &str) {
40  try {
41  return boost::shared_ptr<StringObjectFunction<Obj> >(new StringObjectFunction<Obj>(str));
42  } catch (cms::Exception) {
43  return boost::shared_ptr<StringObjectFunction<Obj> >();
44  }
45  }
46 
47  template<typename Obj>
48  double
49  tryEval(const reco::Candidate &c, const boost::shared_ptr<StringObjectFunction<Obj> > &func) const {
50  if (func.get()) return (*func)(static_cast<const Obj &>(c));
51  else throwBadType(typeid(c));
52  assert(false);
53  return 0;
54  }
55 
56  // out of line throw exception
57  void throwBadType(const std::type_info &ty1) const ;
58 
59 };
60 
62 
63 public:
66 
67  bool operator()(const reco::Candidate &c) const ;
68 
69 private:
71  boost::shared_ptr<StringCutObjectSelector<reco::Candidate> > candFunc_;
72 
73  boost::shared_ptr<StringCutObjectSelector<pat::Electron> > eleFunc_;
74  boost::shared_ptr<StringCutObjectSelector<pat::Muon> > muFunc_;
75  boost::shared_ptr<StringCutObjectSelector<pat::Tau> > tauFunc_;
76  boost::shared_ptr<StringCutObjectSelector<pat::Photon> > gamFunc_;
77  boost::shared_ptr<StringCutObjectSelector<pat::Jet> > jetFunc_;
78  boost::shared_ptr<StringCutObjectSelector<pat::MET> > metFunc_;
79  boost::shared_ptr<StringCutObjectSelector<pat::GenericParticle> > gpFunc_;
80  boost::shared_ptr<StringCutObjectSelector<pat::PFParticle> > pfFunc_;
81 
82  template<typename Obj>
83  boost::shared_ptr<StringCutObjectSelector<Obj> > tryGet(const std::string &str) {
84  try {
85  return boost::shared_ptr<StringCutObjectSelector<Obj> >(new StringCutObjectSelector<Obj>(str));
86  } catch (cms::Exception) {
87  return boost::shared_ptr<StringCutObjectSelector<Obj> >();
88  }
89  }
90 
91  template<typename Obj>
92  bool
93  tryEval(const reco::Candidate &c, const boost::shared_ptr<StringCutObjectSelector<Obj> > &func) const {
94  if (func.get()) return (*func)(static_cast<const Obj &>(c));
95  else throwBadType(typeid(c));
96  assert(false);
97  return false;
98  }
99 
100  // out of line throw exception
101  void throwBadType(const std::type_info &ty1) const ;
102 
103 
104 
105 };
106 
107 
108 #endif
void throwBadType(const std::type_info &ty1) const
bool tryEval(const reco::Candidate &c, const boost::shared_ptr< StringCutObjectSelector< Obj > > &func) const
boost::shared_ptr< StringObjectFunction< pat::Jet > > jetFunc_
void throwBadType(const std::type_info &ty1) const
boost::shared_ptr< StringCutObjectSelector< pat::PFParticle > > pfFunc_
boost::shared_ptr< StringObjectFunction< pat::Muon > > muFunc_
assert(m_qm.get())
double tryEval(const reco::Candidate &c, const boost::shared_ptr< StringObjectFunction< Obj > > &func) const
boost::shared_ptr< StringCutObjectSelector< pat::Photon > > gamFunc_
bool operator()(const reco::Candidate &c) const
boost::shared_ptr< StringObjectFunction< Obj > > tryGet(const std::string &str)
boost::shared_ptr< StringCutObjectSelector< pat::Muon > > muFunc_
boost::shared_ptr< StringCutObjectSelector< reco::Candidate > > candFunc_
boost::shared_ptr< StringCutObjectSelector< pat::GenericParticle > > gpFunc_
boost::shared_ptr< StringCutObjectSelector< pat::Jet > > jetFunc_
boost::shared_ptr< StringObjectFunction< pat::Tau > > tauFunc_
boost::shared_ptr< StringObjectFunction< pat::MET > > metFunc_
boost::shared_ptr< StringCutObjectSelector< Obj > > tryGet(const std::string &str)
boost::shared_ptr< StringCutObjectSelector< pat::MET > > metFunc_
boost::shared_ptr< StringObjectFunction< reco::Candidate > > candFunc_
boost::shared_ptr< StringObjectFunction< pat::Electron > > eleFunc_
boost::shared_ptr< StringObjectFunction< pat::PFParticle > > pfFunc_
boost::shared_ptr< StringObjectFunction< pat::Photon > > gamFunc_
boost::shared_ptr< StringCutObjectSelector< pat::Electron > > eleFunc_
boost::shared_ptr< StringObjectFunction< pat::GenericParticle > > gpFunc_
double operator()(const reco::Candidate &c) const
boost::shared_ptr< StringCutObjectSelector< pat::Tau > > tauFunc_