Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:13

0001 #include "PhysicsTools/PatUtils/interface/StringParserTools.h"
0002 #include <typeinfo>
0003 
0004 PATStringObjectFunction::PATStringObjectFunction(const std::string &string) : expr_(string) {
0005   candFunc_ = tryGet<reco::Candidate>(string);
0006   if (!candFunc_.get()) {
0007     eleFunc_ = tryGet<pat::Electron>(string);
0008     muFunc_ = tryGet<pat::Muon>(string);
0009     tauFunc_ = tryGet<pat::Tau>(string);
0010     gamFunc_ = tryGet<pat::Photon>(string);
0011     jetFunc_ = tryGet<pat::Jet>(string);
0012     metFunc_ = tryGet<pat::MET>(string);
0013     gpFunc_ = tryGet<pat::GenericParticle>(string);
0014     pfFunc_ = tryGet<pat::PFParticle>(string);
0015   }
0016 }
0017 
0018 double PATStringObjectFunction::operator()(const reco::Candidate &c) const {
0019   if (candFunc_.get())
0020     return (*candFunc_)(c);
0021   const std::type_info &type = typeid(c);
0022   if (type == typeid(pat::Electron))
0023     return tryEval<pat::Electron>(c, eleFunc_);
0024   else if (type == typeid(pat::Muon))
0025     return tryEval<pat::Muon>(c, muFunc_);
0026   else if (type == typeid(pat::Tau))
0027     return tryEval<pat::Tau>(c, tauFunc_);
0028   else if (type == typeid(pat::Photon))
0029     return tryEval<pat::Photon>(c, gamFunc_);
0030   else if (type == typeid(pat::Jet))
0031     return tryEval<pat::Jet>(c, jetFunc_);
0032   else if (type == typeid(pat::MET))
0033     return tryEval<pat::MET>(c, metFunc_);
0034   else if (type == typeid(pat::GenericParticle))
0035     return tryEval<pat::GenericParticle>(c, gpFunc_);
0036   else if (type == typeid(pat::PFParticle))
0037     return tryEval<pat::PFParticle>(c, pfFunc_);
0038   else
0039     throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type "
0040                                        << type.name() << "\n";
0041 }
0042 
0043 void PATStringObjectFunction::throwBadType(const std::type_info &ty) const {
0044   throw cms::Exception("Type Error") << "Expression '" << expr_ << "' can't be evaluated on an object of type "
0045                                      << ty.name() << "\n(hint: use c++filt to demangle the type name)\n";
0046 }
0047 
0048 PATStringCutObjectSelector::PATStringCutObjectSelector(const std::string &string) : expr_(string) {
0049   candFunc_ = tryGet<reco::Candidate>(string);
0050   if (!candFunc_.get()) {
0051     eleFunc_ = tryGet<pat::Electron>(string);
0052     muFunc_ = tryGet<pat::Muon>(string);
0053     tauFunc_ = tryGet<pat::Tau>(string);
0054     gamFunc_ = tryGet<pat::Photon>(string);
0055     jetFunc_ = tryGet<pat::Jet>(string);
0056     metFunc_ = tryGet<pat::MET>(string);
0057     gpFunc_ = tryGet<pat::GenericParticle>(string);
0058     pfFunc_ = tryGet<pat::PFParticle>(string);
0059   }
0060 }
0061 
0062 bool PATStringCutObjectSelector::operator()(const reco::Candidate &c) const {
0063   if (candFunc_.get())
0064     return (*candFunc_)(c);
0065   const std::type_info &type = typeid(c);
0066   if (type == typeid(pat::Electron))
0067     return tryEval<pat::Electron>(c, eleFunc_);
0068   else if (type == typeid(pat::Muon))
0069     return tryEval<pat::Muon>(c, muFunc_);
0070   else if (type == typeid(pat::Tau))
0071     return tryEval<pat::Tau>(c, tauFunc_);
0072   else if (type == typeid(pat::Photon))
0073     return tryEval<pat::Photon>(c, gamFunc_);
0074   else if (type == typeid(pat::Jet))
0075     return tryEval<pat::Jet>(c, jetFunc_);
0076   else if (type == typeid(pat::MET))
0077     return tryEval<pat::MET>(c, metFunc_);
0078   else if (type == typeid(pat::GenericParticle))
0079     return tryEval<pat::GenericParticle>(c, gpFunc_);
0080   else if (type == typeid(pat::PFParticle))
0081     return tryEval<pat::PFParticle>(c, pfFunc_);
0082   else
0083     throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type "
0084                                        << type.name() << "\n";
0085 }
0086 
0087 void PATStringCutObjectSelector::throwBadType(const std::type_info &ty) const {
0088   throw cms::Exception("Type Error") << "Expression '" << expr_ << "' can't be evaluated on an object of type "
0089                                      << ty.name() << "\n(hint: use c++filt to demangle the type name)\n";
0090 }