CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
PATStringObjectFunction Class Reference

#include <StringParserTools.h>

Public Member Functions

double operator() (const reco::Candidate &c) const
 
 PATStringObjectFunction ()
 
 PATStringObjectFunction (const std::string &string)
 

Private Member Functions

void throwBadType (const std::type_info &ty1) const
 
template<typename Obj >
double tryEval (const reco::Candidate &c, const boost::shared_ptr< StringObjectFunction< Obj > > &func) const
 
template<typename Obj >
boost::shared_ptr
< StringObjectFunction< Obj > > 
tryGet (const std::string &str)
 

Private Attributes

boost::shared_ptr
< StringObjectFunction
< reco::Candidate > > 
candFunc_
 
boost::shared_ptr
< StringObjectFunction
< pat::Electron > > 
eleFunc_
 
std::string expr_
 
boost::shared_ptr
< StringObjectFunction
< pat::Photon > > 
gamFunc_
 
boost::shared_ptr
< StringObjectFunction
< pat::GenericParticle > > 
gpFunc_
 
boost::shared_ptr
< StringObjectFunction
< pat::Jet > > 
jetFunc_
 
boost::shared_ptr
< StringObjectFunction
< pat::MET > > 
metFunc_
 
boost::shared_ptr
< StringObjectFunction
< pat::Muon > > 
muFunc_
 
boost::shared_ptr
< StringObjectFunction
< pat::PFParticle > > 
pfFunc_
 
boost::shared_ptr
< StringObjectFunction
< pat::Tau > > 
tauFunc_
 

Detailed Description

Definition at line 17 of file StringParserTools.h.

Constructor & Destructor Documentation

PATStringObjectFunction::PATStringObjectFunction ( )
inline

Definition at line 20 of file StringParserTools.h.

20 {}
PATStringObjectFunction::PATStringObjectFunction ( const std::string &  string)

Definition at line 4 of file StringParserTools.cc.

References candFunc_, eleFunc_, gamFunc_, gpFunc_, jetFunc_, metFunc_, muFunc_, pfFunc_, AlCaHLTBitMon_QueryRunRegistry::string, and tauFunc_.

4  :
5  expr_(string)
6 {
7  candFunc_ = tryGet<reco::Candidate>(string);
8  if (!candFunc_.get()) {
9  eleFunc_ = tryGet<pat::Electron>(string);
10  muFunc_ = tryGet<pat::Muon>(string);
11  tauFunc_ = tryGet<pat::Tau>(string);
12  gamFunc_ = tryGet<pat::Photon>(string);
13  jetFunc_ = tryGet<pat::Jet>(string);
14  metFunc_ = tryGet<pat::MET>(string);
15  gpFunc_ = tryGet<pat::GenericParticle>(string);
16  pfFunc_ = tryGet<pat::PFParticle>(string);
17  }
18 }
boost::shared_ptr< StringObjectFunction< pat::Jet > > jetFunc_
boost::shared_ptr< StringObjectFunction< pat::Muon > > muFunc_
boost::shared_ptr< StringObjectFunction< pat::Tau > > tauFunc_
boost::shared_ptr< StringObjectFunction< 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< StringObjectFunction< pat::GenericParticle > > gpFunc_

Member Function Documentation

double PATStringObjectFunction::operator() ( const reco::Candidate c) const

Definition at line 21 of file StringParserTools.cc.

References trackerHits::c, candFunc_, eleFunc_, edm::hlt::Exception, expr_, gamFunc_, gpFunc_, jetFunc_, metFunc_, muFunc_, pfFunc_, and tauFunc_.

21  {
22  if (candFunc_.get()) return (*candFunc_)(c);
23  const std::type_info &type = typeid(c);
24  if (type == typeid(pat::Electron )) return tryEval<pat::Electron >(c, eleFunc_);
25  else if (type == typeid(pat::Muon )) return tryEval<pat::Muon >(c, muFunc_);
26  else if (type == typeid(pat::Tau )) return tryEval<pat::Tau >(c, tauFunc_);
27  else if (type == typeid(pat::Photon )) return tryEval<pat::Photon >(c, gamFunc_);
28  else if (type == typeid(pat::Jet )) return tryEval<pat::Jet >(c, jetFunc_);
29  else if (type == typeid(pat::MET )) return tryEval<pat::MET >(c, metFunc_);
30  else if (type == typeid(pat::GenericParticle)) return tryEval<pat::GenericParticle>(c, gpFunc_);
31  else if (type == typeid(pat::PFParticle )) return tryEval<pat::PFParticle >(c, pfFunc_);
32  else throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type " << type.name() << "\n";
33 }
type
Definition: HCALResponse.h:21
Analysis-level MET class.
Definition: MET.h:42
Analysis-level Photon class.
Definition: Photon.h:47
boost::shared_ptr< StringObjectFunction< pat::Jet > > jetFunc_
boost::shared_ptr< StringObjectFunction< pat::Muon > > muFunc_
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
boost::shared_ptr< StringObjectFunction< pat::Tau > > tauFunc_
boost::shared_ptr< StringObjectFunction< pat::MET > > metFunc_
Analysis-level tau class.
Definition: Tau.h:56
boost::shared_ptr< StringObjectFunction< reco::Candidate > > candFunc_
boost::shared_ptr< StringObjectFunction< pat::Electron > > eleFunc_
boost::shared_ptr< StringObjectFunction< pat::PFParticle > > pfFunc_
Analysis-level electron class.
Definition: Electron.h:52
Analysis-level calorimeter jet class.
Definition: Jet.h:73
Analysis-level class for reconstructed particles.
Definition: PFParticle.h:35
boost::shared_ptr< StringObjectFunction< pat::Photon > > gamFunc_
boost::shared_ptr< StringObjectFunction< pat::GenericParticle > > gpFunc_
Analysis-level muon class.
Definition: Muon.h:50
void PATStringObjectFunction::throwBadType ( const std::type_info &  ty1) const
private

Definition at line 36 of file StringParserTools.cc.

References edm::hlt::Exception, and expr_.

Referenced by tryEval().

36  {
37  throw cms::Exception("Type Error") << "Expression '" << expr_ << "' can't be evaluated on an object of type " << ty.name() << "\n(hint: use c++filt to demangle the type name)\n";
38 }
template<typename Obj >
double PATStringObjectFunction::tryEval ( const reco::Candidate c,
const boost::shared_ptr< StringObjectFunction< Obj > > &  func 
) const
inlineprivate

Definition at line 49 of file StringParserTools.h.

References trackerHits::c, and throwBadType().

49  {
50  if (func.get()) return (*func)(static_cast<const Obj &>(c));
51  else throwBadType(typeid(c));
52  assert(false);
53  return 0;
54  }
void throwBadType(const std::type_info &ty1) const
template<typename Obj >
boost::shared_ptr<StringObjectFunction<Obj> > PATStringObjectFunction::tryGet ( const std::string &  str)
inlineprivate

Definition at line 39 of file StringParserTools.h.

39  {
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  }

Member Data Documentation

boost::shared_ptr<StringObjectFunction<reco::Candidate> > PATStringObjectFunction::candFunc_
private

Definition at line 27 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().

boost::shared_ptr<StringObjectFunction<pat::Electron> > PATStringObjectFunction::eleFunc_
private

Definition at line 29 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().

std::string PATStringObjectFunction::expr_
private

Definition at line 26 of file StringParserTools.h.

Referenced by operator()(), and throwBadType().

boost::shared_ptr<StringObjectFunction<pat::Photon> > PATStringObjectFunction::gamFunc_
private

Definition at line 32 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().

boost::shared_ptr<StringObjectFunction<pat::GenericParticle> > PATStringObjectFunction::gpFunc_
private

Definition at line 35 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().

boost::shared_ptr<StringObjectFunction<pat::Jet> > PATStringObjectFunction::jetFunc_
private

Definition at line 33 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().

boost::shared_ptr<StringObjectFunction<pat::MET> > PATStringObjectFunction::metFunc_
private

Definition at line 34 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().

boost::shared_ptr<StringObjectFunction<pat::Muon> > PATStringObjectFunction::muFunc_
private

Definition at line 30 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().

boost::shared_ptr<StringObjectFunction<pat::PFParticle> > PATStringObjectFunction::pfFunc_
private

Definition at line 36 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().

boost::shared_ptr<StringObjectFunction<pat::Tau> > PATStringObjectFunction::tauFunc_
private

Definition at line 31 of file StringParserTools.h.

Referenced by operator()(), and PATStringObjectFunction().