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.

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 }

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

Member Function Documentation

◆ operator()()

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

Definition at line 18 of file StringParserTools.cc.

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 }

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

◆ throwBadType()

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

Definition at line 43 of file StringParserTools.cc.

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 }

References Exception, and expr_.

Referenced by tryEval().

◆ 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.

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  }

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

◆ tryGet()

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

Definition at line 37 of file StringParserTools.h.

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  }

References str.

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().

StringObjectFunction
Definition: StringObjectFunction.h:16
pat::Tau
Analysis-level tau class.
Definition: Tau.h:53
pat::Photon
Analysis-level Photon class.
Definition: Photon.h:46
cms::cuda::assert
assert(be >=bs)
PATStringObjectFunction::pfFunc_
std::shared_ptr< StringObjectFunction< pat::PFParticle > > pfFunc_
Definition: StringParserTools.h:34
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
pat::PFParticle
Analysis-level class for reconstructed particles.
Definition: PFParticle.h:32
PATStringObjectFunction::jetFunc_
std::shared_ptr< StringObjectFunction< pat::Jet > > jetFunc_
Definition: StringParserTools.h:31
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
pat::Jet
Analysis-level calorimeter jet class.
Definition: Jet.h:77
PATStringObjectFunction::tauFunc_
std::shared_ptr< StringObjectFunction< pat::Tau > > tauFunc_
Definition: StringParserTools.h:29
str
#define str(s)
Definition: TestProcessor.cc:52
PATStringObjectFunction::eleFunc_
std::shared_ptr< StringObjectFunction< pat::Electron > > eleFunc_
Definition: StringParserTools.h:27
pat::GenericParticle
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed)
Definition: GenericParticle.h:38
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
pat::MET
Analysis-level MET class.
Definition: MET.h:40
PATStringObjectFunction::metFunc_
std::shared_ptr< StringObjectFunction< pat::MET > > metFunc_
Definition: StringParserTools.h:32
PATStringObjectFunction::expr_
std::string expr_
Definition: StringParserTools.h:24
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
PATStringObjectFunction::throwBadType
void throwBadType(const std::type_info &ty1) const
Definition: StringParserTools.cc:43
Exception
Definition: hltDiff.cc:245
PATStringObjectFunction::gamFunc_
std::shared_ptr< StringObjectFunction< pat::Photon > > gamFunc_
Definition: StringParserTools.h:30
cms::Exception
Definition: Exception.h:70
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
PATStringObjectFunction::muFunc_
std::shared_ptr< StringObjectFunction< pat::Muon > > muFunc_
Definition: StringParserTools.h:28