CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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.

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 }

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

Member Function Documentation

◆ operator()()

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

Definition at line 62 of file StringParserTools.cc.

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 }

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

◆ throwBadType()

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

Definition at line 87 of file StringParserTools.cc.

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 }

References Exception, and expr_.

Referenced by tryEval().

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

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  }

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

◆ tryGet()

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

Definition at line 80 of file StringParserTools.h.

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  }

References str.

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

PATStringCutObjectSelector::candFunc_
std::shared_ptr< StringCutObjectSelector< reco::Candidate > > candFunc_
Definition: StringParserTools.h:68
PATStringCutObjectSelector::pfFunc_
std::shared_ptr< StringCutObjectSelector< pat::PFParticle > > pfFunc_
Definition: StringParserTools.h:77
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)
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
pat::PFParticle
Analysis-level class for reconstructed particles.
Definition: PFParticle.h:32
PATStringCutObjectSelector::tauFunc_
std::shared_ptr< StringCutObjectSelector< pat::Tau > > tauFunc_
Definition: StringParserTools.h:72
PATStringCutObjectSelector::jetFunc_
std::shared_ptr< StringCutObjectSelector< pat::Jet > > jetFunc_
Definition: StringParserTools.h:74
pat::Jet
Analysis-level calorimeter jet class.
Definition: Jet.h:77
str
#define str(s)
Definition: TestProcessor.cc:51
PATStringCutObjectSelector::eleFunc_
std::shared_ptr< StringCutObjectSelector< pat::Electron > > eleFunc_
Definition: StringParserTools.h:70
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
PATStringCutObjectSelector::metFunc_
std::shared_ptr< StringCutObjectSelector< pat::MET > > metFunc_
Definition: StringParserTools.h:75
pat::MET
Analysis-level MET class.
Definition: MET.h:40
PATStringCutObjectSelector::gamFunc_
std::shared_ptr< StringCutObjectSelector< pat::Photon > > gamFunc_
Definition: StringParserTools.h:73
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
PATStringCutObjectSelector::gpFunc_
std::shared_ptr< StringCutObjectSelector< pat::GenericParticle > > gpFunc_
Definition: StringParserTools.h:76
PATStringCutObjectSelector::throwBadType
void throwBadType(const std::type_info &ty1) const
Definition: StringParserTools.cc:87
StringCutObjectSelector
Definition: StringCutObjectSelector.h:16
Exception
Definition: hltDiff.cc:246
PATStringCutObjectSelector::muFunc_
std::shared_ptr< StringCutObjectSelector< pat::Muon > > muFunc_
Definition: StringParserTools.h:71
cms::Exception
Definition: Exception.h:70
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
PATStringCutObjectSelector::expr_
std::string expr_
Definition: StringParserTools.h:67