CMS 3D CMS Logo

PATStringObjectFunction Class Reference

#include <PhysicsTools/PatUtils/interface/StringParserTools.h>

List of all members.

Public Member Functions

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

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.

00020 {}

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

00004                                                                         :
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 }


Member Function Documentation

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

Definition at line 21 of file StringParserTools.cc.

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

00021                                                                  {
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 }

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

00036                                                                    {
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 }

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 stor::func(), and throwBadType().

00049                                                                                                    {
00050         if (func.get()) return (*func)(static_cast<const Obj &>(c));
00051         else throwBadType(typeid(c));
00052     }

template<typename Obj>
boost::shared_ptr<StringObjectFunction<Obj> > PATStringObjectFunction::tryGet ( const std::string &  str  )  [inline, private]

Definition at line 39 of file StringParserTools.h.

00039                                                                              {
00040         try {
00041             return boost::shared_ptr<StringObjectFunction<Obj> >(new StringObjectFunction<Obj>(str));
00042         } catch (cms::Exception) { 
00043             return boost::shared_ptr<StringObjectFunction<Obj> >();
00044         }
00045     }


Member Data Documentation

boost::shared_ptr<StringObjectFunction<reco::Candidate> > PATStringObjectFunction::candFunc_ [private]

Definition at line 27 of file StringParserTools.h.

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

boost::shared_ptr<StringObjectFunction<pat::Electron> > PATStringObjectFunction::eleFunc_ [private]

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

boost::shared_ptr<StringObjectFunction<pat::Photon> > PATStringObjectFunction::gamFunc_ [private]

Definition at line 32 of file StringParserTools.h.

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

boost::shared_ptr<StringObjectFunction<pat::GenericParticle> > PATStringObjectFunction::gpFunc_ [private]

Definition at line 35 of file StringParserTools.h.

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

boost::shared_ptr<StringObjectFunction<pat::Jet> > PATStringObjectFunction::jetFunc_ [private]

Definition at line 33 of file StringParserTools.h.

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

boost::shared_ptr<StringObjectFunction<pat::MET> > PATStringObjectFunction::metFunc_ [private]

Definition at line 34 of file StringParserTools.h.

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

boost::shared_ptr<StringObjectFunction<pat::Muon> > PATStringObjectFunction::muFunc_ [private]

Definition at line 30 of file StringParserTools.h.

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

boost::shared_ptr<StringObjectFunction<pat::PFParticle> > PATStringObjectFunction::pfFunc_ [private]

Definition at line 36 of file StringParserTools.h.

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

boost::shared_ptr<StringObjectFunction<pat::Tau> > PATStringObjectFunction::tauFunc_ [private]

Definition at line 31 of file StringParserTools.h.

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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:29:28 2009 for CMSSW by  doxygen 1.5.4