CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

PATStringObjectFunction Class Reference

#include <StringParserTools.h>

List of all members.

Public Member Functions

double operator() (const reco::Candidate &c) const
 PATStringObjectFunction ()
 PATStringObjectFunction (const std::string &string)

Private Member Functions

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

Private Attributes

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

Detailed Description

Definition at line 17 of file StringParserTools.h.


Constructor & Destructor Documentation

PATStringObjectFunction::PATStringObjectFunction ( ) [inline]

Definition at line 20 of file StringParserTools.h.

{}
PATStringObjectFunction::PATStringObjectFunction ( const std::string &  string)

Definition at line 4 of file StringParserTools.cc.

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

                                                                        :
    expr_(string)
{
   candFunc_ = tryGet<reco::Candidate>(string);
   if (!candFunc_.get()) {
       eleFunc_ = tryGet<pat::Electron>(string);
       muFunc_  = tryGet<pat::Muon>(string);
       tauFunc_ = tryGet<pat::Tau>(string);
       gamFunc_ = tryGet<pat::Photon>(string);
       jetFunc_ = tryGet<pat::Jet>(string);
       metFunc_ = tryGet<pat::MET>(string);
       gpFunc_  = tryGet<pat::GenericParticle>(string);
       pfFunc_  = tryGet<pat::PFParticle>(string);
   } 
}

Member Function Documentation

double PATStringObjectFunction::operator() ( const reco::Candidate c) const

Definition at line 21 of file StringParserTools.cc.

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

                                                                 {
    if (candFunc_.get()) return (*candFunc_)(c);
    const std::type_info &type = typeid(c);
    if      (type == typeid(pat::Electron       )) return tryEval<pat::Electron       >(c, eleFunc_);
    else if (type == typeid(pat::Muon           )) return tryEval<pat::Muon           >(c,  muFunc_);
    else if (type == typeid(pat::Tau            )) return tryEval<pat::Tau            >(c, tauFunc_);
    else if (type == typeid(pat::Photon         )) return tryEval<pat::Photon         >(c, gamFunc_);
    else if (type == typeid(pat::Jet            )) return tryEval<pat::Jet            >(c, jetFunc_);
    else if (type == typeid(pat::MET            )) return tryEval<pat::MET            >(c, metFunc_);
    else if (type == typeid(pat::GenericParticle)) return tryEval<pat::GenericParticle>(c,  gpFunc_);
    else if (type == typeid(pat::PFParticle     )) return tryEval<pat::PFParticle     >(c,  pfFunc_);
    else throw cms::Exception("Type Error") << "Cannot evaluate '" << expr_ << "' on an object of unsupported type " << type.name() << "\n"; 
}
void PATStringObjectFunction::throwBadType ( const std::type_info &  ty1) const [private]

Definition at line 36 of file StringParserTools.cc.

References Exception, and expr_.

Referenced by tryEval().

                                                                   {
    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";
}
template<typename Obj >
double PATStringObjectFunction::tryEval ( const reco::Candidate c,
const boost::shared_ptr< StringObjectFunction< Obj > > &  func 
) const [inline, private]

Definition at line 49 of file StringParserTools.h.

References trackerHits::c, and throwBadType().

                                                                                                   {
        if (func.get()) return (*func)(static_cast<const Obj &>(c));
        else throwBadType(typeid(c));
        assert(false);
        return 0; 
    }
template<typename Obj >
boost::shared_ptr<StringObjectFunction<Obj> > PATStringObjectFunction::tryGet ( const std::string &  str) [inline, private]

Definition at line 39 of file StringParserTools.h.

                                                                             {
        try {
            return boost::shared_ptr<StringObjectFunction<Obj> >(new StringObjectFunction<Obj>(str));
        } catch (cms::Exception) { 
            return boost::shared_ptr<StringObjectFunction<Obj> >();
        }
    }

Member Data Documentation

Definition at line 27 of file StringParserTools.h.

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

Definition at line 29 of file StringParserTools.h.

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

std::string PATStringObjectFunction::expr_ [private]

Definition at line 26 of file StringParserTools.h.

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

Definition at line 32 of file StringParserTools.h.

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

Definition at line 35 of file StringParserTools.h.

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

Definition at line 33 of file StringParserTools.h.

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

Definition at line 34 of file StringParserTools.h.

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

Definition at line 30 of file StringParserTools.h.

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

Definition at line 36 of file StringParserTools.h.

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

Definition at line 31 of file StringParserTools.h.

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