CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/PhysicsTools/FWLite/interface/ScannerHelpers.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_FWLite_ScannerHelpers_h
00002 #define PhysicsTools_FWLite_ScannerHelpers_h
00003 
00004 #include <string>
00005 #include <Reflex/Type.h>
00006 #include <TH1.h>
00007 #include <TH2.h>
00008 #include <TProfile.h>
00009 #include <TGraph.h>
00010 
00011 
00012 // AFAIK These includes are needed to build the dictionary
00013 // but must be kept hidden if CINT sees this class
00014 #if !defined(__CINT__) && !defined(__MAKECINT__)
00015 #include "CommonTools/Utils/src/ExpressionPtr.h"
00016 #include "CommonTools/Utils/src/SelectorPtr.h"
00017 #include "CommonTools/Utils/src/ExpressionBase.h"
00018 #include "CommonTools/Utils/src/SelectorBase.h"
00019 #endif
00020 
00021 namespace helper {
00024     class Parser {
00025         public:
00027             Parser() {}
00029             static reco::parser::ExpressionPtr  makeExpression(const std::string &expr, const Reflex::Type &type) ;
00031             static reco::parser::SelectorPtr    makeSelector(const std::string &expr, const Reflex::Type &type) ;
00033             static Reflex::Type elementType(const Reflex::Type &wrapperType) ;
00034 
00035             //--- we define also dictionaries for these two trivial functions that should be callable even by CINT
00036             //    because otherwise sometimes CINT crashes even on the creation and destruction of Reflex::Object
00038             static bool   test(const reco::parser::SelectorPtr &sel, const Reflex::Type type, const void * obj);
00040             static double eval(const reco::parser::ExpressionPtr &sel, const Reflex::Type type, const void * obj);
00041     };
00042 
00045     class ScannerBase {
00046         public:
00048             ScannerBase() {}
00050             ScannerBase(const Reflex::Type &objType) : objType_(objType), cuts_(1), ignoreExceptions_(false) {}
00051 
00054             bool addExpression(const char *expr) ;
00056             void clearExpressions() { exprs_.clear(); }
00058             size_t numberOfExpressions() const { return exprs_.size(); }
00059 
00061             bool setCut(const char *cut) ;
00063             void clearCut() ;
00065             bool addExtraCut(const char *cut) ;
00067             void clearExtraCuts();
00069             size_t numberOfExtraCuts() const { return cuts_.size()-1; }
00070 
00073             bool   test(const void *obj, size_t icut  = 0) const ;
00074 
00077             double eval(const void *obj, size_t iexpr = 0) const;
00078 
00081             void   print(const void *obj) const ;
00082             
00085             void fill1D(const void *obj, TH1 *hist) const ;
00086 
00089             void fill2D(const void *obj, TH2 *hist2d) const ;
00090 
00093             void fillGraph(const void *obj, TGraph *graph) const ;
00094 
00097             void fillProf(const void *obj, TProfile *prof) const ;
00098 
00101             void setIgnoreExceptions(bool ignoreThem) { ignoreExceptions_ = ignoreThem; }
00102         private:
00103             Reflex::Type objType_;
00104             std::vector<reco::parser::ExpressionPtr> exprs_;
00105 
00107             std::vector<reco::parser::SelectorPtr>   cuts_;
00108 
00110             bool ignoreExceptions_;
00111     };
00112 }
00113 
00114 #endif