Go to the documentation of this file.00001 #include "PhysicsTools/PatUtils/interface/StringParserTools.h"
00002 #include <typeinfo>
00003
00004 PATStringObjectFunction::PATStringObjectFunction(const std::string &string) :
00005 expr_(string)
00006 {
00007 candFunc_ = tryGet<reco::Candidate>(string);
00008 if (!candFunc_.get()) {
00009 eleFunc_ = tryGet<pat::Electron>(string);
00010 muFunc_ = tryGet<pat::Muon>(string);
00011 tauFunc_ = tryGet<pat::Tau>(string);
00012 gamFunc_ = tryGet<pat::Photon>(string);
00013 jetFunc_ = tryGet<pat::Jet>(string);
00014 metFunc_ = tryGet<pat::MET>(string);
00015 gpFunc_ = tryGet<pat::GenericParticle>(string);
00016 pfFunc_ = tryGet<pat::PFParticle>(string);
00017 }
00018 }
00019
00020 double
00021 PATStringObjectFunction::operator()(const reco::Candidate &c) const {
00022 if (candFunc_.get()) return (*candFunc_)(c);
00023 const std::type_info &type = typeid(c);
00024 if (type == typeid(pat::Electron )) return tryEval<pat::Electron >(c, eleFunc_);
00025 else if (type == typeid(pat::Muon )) return tryEval<pat::Muon >(c, muFunc_);
00026 else if (type == typeid(pat::Tau )) return tryEval<pat::Tau >(c, tauFunc_);
00027 else if (type == typeid(pat::Photon )) return tryEval<pat::Photon >(c, gamFunc_);
00028 else if (type == typeid(pat::Jet )) return tryEval<pat::Jet >(c, jetFunc_);
00029 else if (type == typeid(pat::MET )) return tryEval<pat::MET >(c, metFunc_);
00030 else if (type == typeid(pat::GenericParticle)) return tryEval<pat::GenericParticle>(c, gpFunc_);
00031 else if (type == typeid(pat::PFParticle )) return tryEval<pat::PFParticle >(c, pfFunc_);
00032 else throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type " << type.name() << "\n";
00033 }
00034
00035 void
00036 PATStringObjectFunction::throwBadType(const std::type_info &ty) const {
00037 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";
00038 }
00039
00040 PATStringCutObjectSelector::PATStringCutObjectSelector(const std::string &string) :
00041 expr_(string)
00042 {
00043 candFunc_ = tryGet<reco::Candidate>(string);
00044 if (!candFunc_.get()) {
00045 eleFunc_ = tryGet<pat::Electron>(string);
00046 muFunc_ = tryGet<pat::Muon>(string);
00047 tauFunc_ = tryGet<pat::Tau>(string);
00048 gamFunc_ = tryGet<pat::Photon>(string);
00049 jetFunc_ = tryGet<pat::Jet>(string);
00050 metFunc_ = tryGet<pat::MET>(string);
00051 gpFunc_ = tryGet<pat::GenericParticle>(string);
00052 pfFunc_ = tryGet<pat::PFParticle>(string);
00053 }
00054 }
00055
00056 bool
00057 PATStringCutObjectSelector::operator()(const reco::Candidate &c) const {
00058 if (candFunc_.get()) return (*candFunc_)(c);
00059 const std::type_info &type = typeid(c);
00060 if (type == typeid(pat::Electron )) return tryEval<pat::Electron >(c, eleFunc_);
00061 else if (type == typeid(pat::Muon )) return tryEval<pat::Muon >(c, muFunc_);
00062 else if (type == typeid(pat::Tau )) return tryEval<pat::Tau >(c, tauFunc_);
00063 else if (type == typeid(pat::Photon )) return tryEval<pat::Photon >(c, gamFunc_);
00064 else if (type == typeid(pat::Jet )) return tryEval<pat::Jet >(c, jetFunc_);
00065 else if (type == typeid(pat::MET )) return tryEval<pat::MET >(c, metFunc_);
00066 else if (type == typeid(pat::GenericParticle)) return tryEval<pat::GenericParticle>(c, gpFunc_);
00067 else if (type == typeid(pat::PFParticle )) return tryEval<pat::PFParticle >(c, pfFunc_);
00068 else throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type " << type.name() << "\n";
00069 }
00070
00071 void
00072 PATStringCutObjectSelector::throwBadType(const std::type_info &ty) const {
00073 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";
00074 }