1 |
#include "PhysicsTools/PatUtils/interface/StringParserTools.h"
|
2 |
#include <typeinfo>
|
3 |
|
4 |
PATStringObjectFunction::PATStringObjectFunction(const std::string &string) :
|
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 |
}
|
19 |
|
20 |
double
|
21 |
PATStringObjectFunction::operator()(const reco::Candidate &c) const {
|
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 |
}
|
34 |
|
35 |
void
|
36 |
PATStringObjectFunction::throwBadType(const std::type_info &ty) const {
|
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 |
}
|
39 |
|
40 |
PATStringCutObjectSelector::PATStringCutObjectSelector(const std::string &string) :
|
41 |
expr_(string)
|
42 |
{
|
43 |
candFunc_ = tryGet<reco::Candidate>(string);
|
44 |
if (!candFunc_.get()) {
|
45 |
eleFunc_ = tryGet<pat::Electron>(string);
|
46 |
muFunc_ = tryGet<pat::Muon>(string);
|
47 |
tauFunc_ = tryGet<pat::Tau>(string);
|
48 |
gamFunc_ = tryGet<pat::Photon>(string);
|
49 |
jetFunc_ = tryGet<pat::Jet>(string);
|
50 |
metFunc_ = tryGet<pat::MET>(string);
|
51 |
gpFunc_ = tryGet<pat::GenericParticle>(string);
|
52 |
pfFunc_ = tryGet<pat::PFParticle>(string);
|
53 |
}
|
54 |
}
|
55 |
|
56 |
bool
|
57 |
PATStringCutObjectSelector::operator()(const reco::Candidate &c) const {
|
58 |
if (candFunc_.get()) return (*candFunc_)(c);
|
59 |
const std::type_info &type = typeid(c);
|
60 |
if (type == typeid(pat::Electron )) return tryEval<pat::Electron >(c, eleFunc_);
|
61 |
else if (type == typeid(pat::Muon )) return tryEval<pat::Muon >(c, muFunc_);
|
62 |
else if (type == typeid(pat::Tau )) return tryEval<pat::Tau >(c, tauFunc_);
|
63 |
else if (type == typeid(pat::Photon )) return tryEval<pat::Photon >(c, gamFunc_);
|
64 |
else if (type == typeid(pat::Jet )) return tryEval<pat::Jet >(c, jetFunc_);
|
65 |
else if (type == typeid(pat::MET )) return tryEval<pat::MET >(c, metFunc_);
|
66 |
else if (type == typeid(pat::GenericParticle)) return tryEval<pat::GenericParticle>(c, gpFunc_);
|
67 |
else if (type == typeid(pat::PFParticle )) return tryEval<pat::PFParticle >(c, pfFunc_);
|
68 |
else throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type " << type.name() << "\n";
|
69 |
}
|
70 |
|
71 |
void
|
72 |
PATStringCutObjectSelector::throwBadType(const std::type_info &ty) const {
|
73 |
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";
|
74 |
}
|