CMS 3D CMS Logo

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 "PhysicsTools/Utilities/interface/StringObjectFunction.h"
00006 #include "PhysicsTools/Utilities/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     }
00053 
00054     // out of line throw exception
00055     void throwBadType(const std::type_info &ty1) const ;
00056     
00057 };
00058 
00059 class PATStringCutObjectSelector {
00060 
00061 public:
00062     PATStringCutObjectSelector() {}
00063     PATStringCutObjectSelector(const std::string &string) ;
00064 
00065     bool operator()(const reco::Candidate &c) const ;
00066 
00067 private:
00068     std::string expr_;
00069     boost::shared_ptr<StringCutObjectSelector<reco::Candidate> > candFunc_; 
00070 
00071     boost::shared_ptr<StringCutObjectSelector<pat::Electron> >         eleFunc_;
00072     boost::shared_ptr<StringCutObjectSelector<pat::Muon> >              muFunc_;
00073     boost::shared_ptr<StringCutObjectSelector<pat::Tau> >              tauFunc_;
00074     boost::shared_ptr<StringCutObjectSelector<pat::Photon> >           gamFunc_;
00075     boost::shared_ptr<StringCutObjectSelector<pat::Jet> >              jetFunc_;
00076     boost::shared_ptr<StringCutObjectSelector<pat::MET> >              metFunc_;
00077     boost::shared_ptr<StringCutObjectSelector<pat::GenericParticle> >   gpFunc_;
00078     boost::shared_ptr<StringCutObjectSelector<pat::PFParticle> >        pfFunc_;
00079 
00080     template<typename Obj> 
00081     boost::shared_ptr<StringCutObjectSelector<Obj> > tryGet(const std::string &str) {
00082         try {
00083             return boost::shared_ptr<StringCutObjectSelector<Obj> >(new StringCutObjectSelector<Obj>(str));
00084         } catch (cms::Exception) { 
00085             return boost::shared_ptr<StringCutObjectSelector<Obj> >();
00086         }
00087     }
00088 
00089     template<typename Obj>
00090     bool
00091     tryEval(const reco::Candidate &c, const boost::shared_ptr<StringCutObjectSelector<Obj> > &func) const {
00092         if (func.get()) return (*func)(static_cast<const Obj &>(c));
00093         else throwBadType(typeid(c));
00094     }
00095 
00096     // out of line throw exception
00097     void throwBadType(const std::type_info &ty1) const ;
00098 
00099     
00100     
00101 };
00102 
00103 
00104 #endif

Generated on Tue Jun 9 17:41:48 2009 for CMSSW by  doxygen 1.5.4