CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/PhysicsTools/PatUtils/interface/StringParserTools.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_PatUtils_interface_StringParserTools_h
00002 #define PhysicsTools_PatUtils_interface_StringParserTools_h
00003 
00004 #include <boost/shared_ptr.hpp>
00005 #include "CommonTools/Utils/interface/StringObjectFunction.h"
00006 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00007 
00008 #include "DataFormats/PatCandidates/interface/Electron.h"
00009 #include "DataFormats/PatCandidates/interface/Muon.h"
00010 #include "DataFormats/PatCandidates/interface/Tau.h"
00011 #include "DataFormats/PatCandidates/interface/Photon.h"
00012 #include "DataFormats/PatCandidates/interface/Jet.h"
00013 #include "DataFormats/PatCandidates/interface/MET.h"
00014 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
00015 #include "DataFormats/PatCandidates/interface/PFParticle.h"
00016 
00017 class PATStringObjectFunction {
00018 
00019 public:
00020     PATStringObjectFunction() {}
00021     PATStringObjectFunction(const std::string &string) ;
00022 
00023     double operator()(const reco::Candidate &c) const ;
00024 
00025 private:
00026     std::string expr_;
00027     boost::shared_ptr<StringObjectFunction<reco::Candidate> > candFunc_; 
00028 
00029     boost::shared_ptr<StringObjectFunction<pat::Electron> >         eleFunc_;
00030     boost::shared_ptr<StringObjectFunction<pat::Muon> >              muFunc_;
00031     boost::shared_ptr<StringObjectFunction<pat::Tau> >              tauFunc_;
00032     boost::shared_ptr<StringObjectFunction<pat::Photon> >           gamFunc_;
00033     boost::shared_ptr<StringObjectFunction<pat::Jet> >              jetFunc_;
00034     boost::shared_ptr<StringObjectFunction<pat::MET> >              metFunc_;
00035     boost::shared_ptr<StringObjectFunction<pat::GenericParticle> >   gpFunc_;
00036     boost::shared_ptr<StringObjectFunction<pat::PFParticle> >        pfFunc_;
00037 
00038     template<typename Obj> 
00039     boost::shared_ptr<StringObjectFunction<Obj> > tryGet(const std::string &str) {
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     }
00046 
00047     template<typename Obj>
00048     double
00049     tryEval(const reco::Candidate &c, const boost::shared_ptr<StringObjectFunction<Obj> > &func) const {
00050         if (func.get()) return (*func)(static_cast<const Obj &>(c));
00051         else throwBadType(typeid(c));
00052         assert(false);
00053         return 0; 
00054     }
00055 
00056     // out of line throw exception
00057     void throwBadType(const std::type_info &ty1) const ;
00058     
00059 };
00060 
00061 class PATStringCutObjectSelector {
00062 
00063 public:
00064     PATStringCutObjectSelector() {}
00065     PATStringCutObjectSelector(const std::string &string) ;
00066 
00067     bool operator()(const reco::Candidate &c) const ;
00068 
00069 private:
00070     std::string expr_;
00071     boost::shared_ptr<StringCutObjectSelector<reco::Candidate> > candFunc_; 
00072 
00073     boost::shared_ptr<StringCutObjectSelector<pat::Electron> >         eleFunc_;
00074     boost::shared_ptr<StringCutObjectSelector<pat::Muon> >              muFunc_;
00075     boost::shared_ptr<StringCutObjectSelector<pat::Tau> >              tauFunc_;
00076     boost::shared_ptr<StringCutObjectSelector<pat::Photon> >           gamFunc_;
00077     boost::shared_ptr<StringCutObjectSelector<pat::Jet> >              jetFunc_;
00078     boost::shared_ptr<StringCutObjectSelector<pat::MET> >              metFunc_;
00079     boost::shared_ptr<StringCutObjectSelector<pat::GenericParticle> >   gpFunc_;
00080     boost::shared_ptr<StringCutObjectSelector<pat::PFParticle> >        pfFunc_;
00081 
00082     template<typename Obj> 
00083     boost::shared_ptr<StringCutObjectSelector<Obj> > tryGet(const std::string &str) {
00084         try {
00085             return boost::shared_ptr<StringCutObjectSelector<Obj> >(new StringCutObjectSelector<Obj>(str));
00086         } catch (cms::Exception) { 
00087             return boost::shared_ptr<StringCutObjectSelector<Obj> >();
00088         }
00089     }
00090 
00091     template<typename Obj>
00092     bool
00093     tryEval(const reco::Candidate &c, const boost::shared_ptr<StringCutObjectSelector<Obj> > &func) const {
00094         if (func.get()) return (*func)(static_cast<const Obj &>(c));
00095         else throwBadType(typeid(c));
00096         assert(false);
00097         return false;
00098     }
00099 
00100     // out of line throw exception
00101     void throwBadType(const std::type_info &ty1) const ;
00102 
00103     
00104     
00105 };
00106 
00107 
00108 #endif