CMS 3D CMS Logo

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 std::shared_ptr< StringObjectFunction< Obj > > &func) const
 
template<typename Obj >
std::shared_ptr< StringObjectFunction< Obj > > tryGet (const std::string &str)
 

Private Attributes

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

Detailed Description

Definition at line 16 of file StringParserTools.h.

Constructor & Destructor Documentation

◆ PATStringObjectFunction() [1/2]

PATStringObjectFunction::PATStringObjectFunction ( )
inline

Definition at line 18 of file StringParserTools.h.

18 {}

◆ PATStringObjectFunction() [2/2]

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

Member Function Documentation

◆ operator()()

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

Definition at line 18 of file StringParserTools.cc.

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

18  {
19  if (candFunc_.get())
20  return (*candFunc_)(c);
21  const std::type_info &type = typeid(c);
22  if (type == typeid(pat::Electron))
23  return tryEval<pat::Electron>(c, eleFunc_);
24  else if (type == typeid(pat::Muon))
25  return tryEval<pat::Muon>(c, muFunc_);
26  else if (type == typeid(pat::Tau))
27  return tryEval<pat::Tau>(c, tauFunc_);
28  else if (type == typeid(pat::Photon))
29  return tryEval<pat::Photon>(c, gamFunc_);
30  else if (type == typeid(pat::Jet))
31  return tryEval<pat::Jet>(c, jetFunc_);
32  else if (type == typeid(pat::MET))
33  return tryEval<pat::MET>(c, metFunc_);
34  else if (type == typeid(pat::GenericParticle))
35  return tryEval<pat::GenericParticle>(c, gpFunc_);
36  else if (type == typeid(pat::PFParticle))
37  return tryEval<pat::PFParticle>(c, pfFunc_);
38  else
39  throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type "
40  << type.name() << "\n";
41 }
Analysis-level MET class.
Definition: MET.h:40
std::shared_ptr< StringObjectFunction< pat::Photon > > gamFunc_
Analysis-level Photon class.
Definition: Photon.h:46
std::shared_ptr< StringObjectFunction< pat::PFParticle > > pfFunc_
std::shared_ptr< StringObjectFunction< pat::Jet > > jetFunc_
std::shared_ptr< StringObjectFunction< pat::GenericParticle > > gpFunc_
std::shared_ptr< StringObjectFunction< pat::Tau > > tauFunc_
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
std::shared_ptr< StringObjectFunction< reco::Candidate > > candFunc_
std::shared_ptr< StringObjectFunction< pat::MET > > metFunc_
Analysis-level tau class.
Definition: Tau.h:53
std::shared_ptr< StringObjectFunction< pat::Electron > > eleFunc_
Analysis-level electron class.
Definition: Electron.h:51
Analysis-level calorimeter jet class.
Definition: Jet.h:77
Analysis-level class for reconstructed particles.
Definition: PFParticle.h:32
std::shared_ptr< StringObjectFunction< pat::Muon > > muFunc_
Analysis-level muon class.
Definition: Muon.h:51

◆ throwBadType()

void PATStringObjectFunction::throwBadType ( const std::type_info &  ty1) const
private

Definition at line 43 of file StringParserTools.cc.

References Exception, and expr_.

Referenced by tryEval().

43  {
44  throw cms::Exception("Type Error") << "Expression '" << expr_ << "' can't be evaluated on an object of type "
45  << ty.name() << "\n(hint: use c++filt to demangle the type name)\n";
46 }

◆ tryEval()

template<typename Obj >
double PATStringObjectFunction::tryEval ( const reco::Candidate c,
const std::shared_ptr< StringObjectFunction< Obj > > &  func 
) const
inlineprivate

Definition at line 46 of file StringParserTools.h.

References cms::cuda::assert(), HltBtagPostValidation_cff::c, EcalMonitorTask_cff::func, and throwBadType().

46  {
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  }
assert(be >=bs)
void throwBadType(const std::type_info &ty1) const

◆ tryGet()

template<typename Obj >
std::shared_ptr<StringObjectFunction<Obj> > PATStringObjectFunction::tryGet ( const std::string &  str)
inlineprivate

Definition at line 37 of file StringParserTools.h.

References str.

37  {
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  }
#define str(s)

Member Data Documentation

◆ candFunc_

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

Definition at line 25 of file StringParserTools.h.

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

◆ eleFunc_

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

Definition at line 27 of file StringParserTools.h.

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

◆ expr_

std::string PATStringObjectFunction::expr_
private

Definition at line 24 of file StringParserTools.h.

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

◆ gamFunc_

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

Definition at line 30 of file StringParserTools.h.

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

◆ gpFunc_

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

Definition at line 33 of file StringParserTools.h.

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

◆ jetFunc_

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

Definition at line 31 of file StringParserTools.h.

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

◆ metFunc_

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

Definition at line 32 of file StringParserTools.h.

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

◆ muFunc_

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

Definition at line 28 of file StringParserTools.h.

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

◆ pfFunc_

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

Definition at line 34 of file StringParserTools.h.

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

◆ tauFunc_

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

Definition at line 29 of file StringParserTools.h.

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