CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PATStringCutObjectSelector Class Reference

#include <StringParserTools.h>

Public Member Functions

bool operator() (const reco::Candidate &c) const
 
 PATStringCutObjectSelector ()
 
 PATStringCutObjectSelector (const std::string &string)
 

Private Member Functions

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

Private Attributes

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

Detailed Description

Definition at line 59 of file StringParserTools.h.

Constructor & Destructor Documentation

◆ PATStringCutObjectSelector() [1/2]

PATStringCutObjectSelector::PATStringCutObjectSelector ( )
inline

Definition at line 61 of file StringParserTools.h.

61 {}

◆ PATStringCutObjectSelector() [2/2]

PATStringCutObjectSelector::PATStringCutObjectSelector ( const std::string &  string)

Definition at line 48 of file StringParserTools.cc.

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

48  : expr_(string) {
49  candFunc_ = tryGet<reco::Candidate>(string);
50  if (!candFunc_.get()) {
51  eleFunc_ = tryGet<pat::Electron>(string);
52  muFunc_ = tryGet<pat::Muon>(string);
53  tauFunc_ = tryGet<pat::Tau>(string);
54  gamFunc_ = tryGet<pat::Photon>(string);
55  jetFunc_ = tryGet<pat::Jet>(string);
56  metFunc_ = tryGet<pat::MET>(string);
57  gpFunc_ = tryGet<pat::GenericParticle>(string);
58  pfFunc_ = tryGet<pat::PFParticle>(string);
59  }
60 }
std::shared_ptr< StringCutObjectSelector< pat::Tau > > tauFunc_
std::shared_ptr< StringCutObjectSelector< pat::PFParticle > > pfFunc_
std::shared_ptr< StringCutObjectSelector< reco::Candidate > > candFunc_
std::shared_ptr< StringCutObjectSelector< pat::Photon > > gamFunc_
std::shared_ptr< StringCutObjectSelector< pat::Jet > > jetFunc_
std::shared_ptr< StringCutObjectSelector< pat::Electron > > eleFunc_
std::shared_ptr< StringCutObjectSelector< pat::MET > > metFunc_
std::shared_ptr< StringCutObjectSelector< pat::Muon > > muFunc_
std::shared_ptr< StringCutObjectSelector< pat::GenericParticle > > gpFunc_

Member Function Documentation

◆ operator()()

bool PATStringCutObjectSelector::operator() ( const reco::Candidate c) const

Definition at line 62 of file StringParserTools.cc.

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

62  {
63  if (candFunc_.get())
64  return (*candFunc_)(c);
65  const std::type_info &type = typeid(c);
66  if (type == typeid(pat::Electron))
67  return tryEval<pat::Electron>(c, eleFunc_);
68  else if (type == typeid(pat::Muon))
69  return tryEval<pat::Muon>(c, muFunc_);
70  else if (type == typeid(pat::Tau))
71  return tryEval<pat::Tau>(c, tauFunc_);
72  else if (type == typeid(pat::Photon))
73  return tryEval<pat::Photon>(c, gamFunc_);
74  else if (type == typeid(pat::Jet))
75  return tryEval<pat::Jet>(c, jetFunc_);
76  else if (type == typeid(pat::MET))
77  return tryEval<pat::MET>(c, metFunc_);
78  else if (type == typeid(pat::GenericParticle))
79  return tryEval<pat::GenericParticle>(c, gpFunc_);
80  else if (type == typeid(pat::PFParticle))
81  return tryEval<pat::PFParticle>(c, pfFunc_);
82  else
83  throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type "
84  << type.name() << "\n";
85 }
std::shared_ptr< StringCutObjectSelector< pat::Tau > > tauFunc_
Analysis-level MET class.
Definition: MET.h:40
Analysis-level Photon class.
Definition: Photon.h:46
std::shared_ptr< StringCutObjectSelector< pat::PFParticle > > pfFunc_
std::shared_ptr< StringCutObjectSelector< reco::Candidate > > candFunc_
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
std::shared_ptr< StringCutObjectSelector< pat::Photon > > gamFunc_
std::shared_ptr< StringCutObjectSelector< pat::Jet > > jetFunc_
std::shared_ptr< StringCutObjectSelector< pat::Electron > > eleFunc_
Analysis-level tau class.
Definition: Tau.h:53
std::shared_ptr< StringCutObjectSelector< pat::MET > > metFunc_
std::shared_ptr< StringCutObjectSelector< pat::Muon > > muFunc_
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
Analysis-level muon class.
Definition: Muon.h:51
std::shared_ptr< StringCutObjectSelector< pat::GenericParticle > > gpFunc_

◆ throwBadType()

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

Definition at line 87 of file StringParserTools.cc.

References Exception, and expr_.

Referenced by tryEval().

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

◆ tryEval()

template<typename Obj >
bool PATStringCutObjectSelector::tryEval ( const reco::Candidate c,
const std::shared_ptr< StringCutObjectSelector< Obj > > &  func 
) const
inlineprivate

Definition at line 89 of file StringParserTools.h.

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

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

◆ tryGet()

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

Definition at line 80 of file StringParserTools.h.

References str.

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

Member Data Documentation

◆ candFunc_

std::shared_ptr<StringCutObjectSelector<reco::Candidate> > PATStringCutObjectSelector::candFunc_
private

Definition at line 68 of file StringParserTools.h.

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

◆ eleFunc_

std::shared_ptr<StringCutObjectSelector<pat::Electron> > PATStringCutObjectSelector::eleFunc_
private

Definition at line 70 of file StringParserTools.h.

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

◆ expr_

std::string PATStringCutObjectSelector::expr_
private

Definition at line 67 of file StringParserTools.h.

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

◆ gamFunc_

std::shared_ptr<StringCutObjectSelector<pat::Photon> > PATStringCutObjectSelector::gamFunc_
private

Definition at line 73 of file StringParserTools.h.

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

◆ gpFunc_

std::shared_ptr<StringCutObjectSelector<pat::GenericParticle> > PATStringCutObjectSelector::gpFunc_
private

Definition at line 76 of file StringParserTools.h.

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

◆ jetFunc_

std::shared_ptr<StringCutObjectSelector<pat::Jet> > PATStringCutObjectSelector::jetFunc_
private

Definition at line 74 of file StringParserTools.h.

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

◆ metFunc_

std::shared_ptr<StringCutObjectSelector<pat::MET> > PATStringCutObjectSelector::metFunc_
private

Definition at line 75 of file StringParserTools.h.

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

◆ muFunc_

std::shared_ptr<StringCutObjectSelector<pat::Muon> > PATStringCutObjectSelector::muFunc_
private

Definition at line 71 of file StringParserTools.h.

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

◆ pfFunc_

std::shared_ptr<StringCutObjectSelector<pat::PFParticle> > PATStringCutObjectSelector::pfFunc_
private

Definition at line 77 of file StringParserTools.h.

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

◆ tauFunc_

std::shared_ptr<StringCutObjectSelector<pat::Tau> > PATStringCutObjectSelector::tauFunc_
private

Definition at line 72 of file StringParserTools.h.

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