CMS 3D CMS Logo

ScannerHelpers.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_FWLite_ScannerHelpers_h
2 #define PhysicsTools_FWLite_ScannerHelpers_h
3 
4 #include <string>
6 #include <TH1.h>
7 #include <TH2.h>
8 #include <TProfile.h>
9 #include <TGraph.h>
10 
11 // AFAIK These includes are needed to build the dictionary
12 // but must be kept hidden if CINT sees this class
13 #if !defined(__CINT__) && !defined(__MAKECINT__)
18 #endif
19 
20 namespace helper {
23  class Parser {
24  public:
26  Parser() {}
32  static edm::TypeWithDict elementType(const edm::TypeWithDict &wrapperType);
33 
34  //--- we define also dictionaries for these two trivial functions that should be callable even by CINT
35  // because otherwise sometimes CINT crashes even on the creation and destruction of edm::ObjectWithDict
37  static bool test(const reco::parser::SelectorPtr &sel, const edm::TypeWithDict type, const void *obj);
39  static double eval(const reco::parser::ExpressionPtr &sel, const edm::TypeWithDict type, const void *obj);
40  };
41 
44  class ScannerBase {
45  public:
50 
53  bool addExpression(const char *expr);
55  void clearExpressions() { exprs_.clear(); }
57  size_t numberOfExpressions() const { return exprs_.size(); }
58 
60  bool setCut(const char *cut);
62  void clearCut();
64  bool addExtraCut(const char *cut);
66  void clearExtraCuts();
68  size_t numberOfExtraCuts() const { return cuts_.size() - 1; }
69 
72  bool test(const void *obj, size_t icut = 0) const;
73 
76  double eval(const void *obj, size_t iexpr = 0) const;
77 
80  void print(const void *obj) const;
81 
84  void fill1D(const void *obj, TH1 *hist) const;
85 
88  void fill2D(const void *obj, TH2 *hist2d) const;
89 
92  void fillGraph(const void *obj, TGraph *graph) const;
93 
96  void fillProf(const void *obj, TProfile *prof) const;
97 
100  void setIgnoreExceptions(bool ignoreThem) { ignoreExceptions_ = ignoreThem; }
101 
102  private:
104  std::vector<reco::parser::ExpressionPtr> exprs_;
105 
107  std::vector<reco::parser::SelectorPtr> cuts_;
108 
111  };
112 } // namespace helper
113 
114 #endif
void fill2D(const void *obj, TH2 *hist2d) const
Definition: helper.py:1
void fillGraph(const void *obj, TGraph *graph) const
void clearExtraCuts()
Clear all extra cuts ;.
void setIgnoreExceptions(bool ignoreThem)
std::shared_ptr< ExpressionBase > ExpressionPtr
void clearExpressions()
Clear all the expressions.
bool test(const void *obj, size_t icut=0) const
static bool test(const reco::parser::SelectorPtr &sel, const edm::TypeWithDict type, const void *obj)
Make a edm::ObjectWithDict(type, obj) and pass it to the selector.
bool addExtraCut(const char *cut)
Add one extra cut that can be evaluated separately (as if it was an expression)
size_t numberOfExtraCuts() const
Number of extra cuts.
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
double eval(const void *obj, size_t iexpr=0) const
std::vector< reco::parser::ExpressionPtr > exprs_
ScannerBase(const edm::TypeWithDict &objType)
Constructor taking as argument the type of the individual object passed to the scanner.
ScannerBase()
Empty constructor, necessary for Root, DO NOT USE.
void fill1D(const void *obj, TH1 *hist) const
void fillProf(const void *obj, TProfile *prof) const
void clearCut()
Clear the default cut.
bool addExpression(const char *expr)
__shared__ Hist hist
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
static edm::TypeWithDict elementType(const edm::TypeWithDict &wrapperType)
Perform the type deduction form edm::Wrapper<C> to C::value_type and resolves typedefs.
bool setCut(const char *cut)
Set the default cut that is applied to the events.
static reco::parser::ExpressionPtr makeExpression(const std::string &expr, const edm::TypeWithDict &type)
Parse an expression for a given object type (using lazy parsing when resolving methods) ...
static double eval(const reco::parser::ExpressionPtr &sel, const edm::TypeWithDict type, const void *obj)
Make a edm::ObjectWithDict(type, obj) and pass it to the expression.
void print(const void *obj) const
static reco::parser::SelectorPtr makeSelector(const std::string &expr, const edm::TypeWithDict &type)
Parse an expression for a given object type (using lazy parsing when resolving methods) ...
edm::TypeWithDict objType_
Parser()
Empty constructor, necessary for Root, useless.
size_t numberOfExpressions() const
Number of valid expressions.
std::shared_ptr< SelectorBase > SelectorPtr
Definition: SelectorPtr.h:18