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
helper::ScannerBase::objType_
edm::TypeWithDict objType_
Definition: ScannerHelpers.h:103
helper::ScannerBase::numberOfExpressions
size_t numberOfExpressions() const
Number of valid expressions.
Definition: ScannerHelpers.h:57
funct::false
false
Definition: Factorize.h:29
TkAlMuonSelectors_cfi.cut
cut
Definition: TkAlMuonSelectors_cfi.py:5
helper::ScannerBase
Definition: ScannerHelpers.h:44
TypeWithDict.h
ExpressionBase.h
helper::Parser::elementType
static edm::TypeWithDict elementType(const edm::TypeWithDict &wrapperType)
Perform the type deduction form edm::Wrapper<C> to C::value_type and resolves typedefs.
Definition: ScannerHelpers.cc:42
helper::ScannerBase::addExpression
bool addExpression(const char *expr)
Definition: ScannerHelpers.cc:67
helper::ScannerBase::cuts_
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
Definition: ScannerHelpers.h:107
helper::Parser::eval
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.
Definition: ScannerHelpers.cc:60
helper::ScannerBase::ScannerBase
ScannerBase(const edm::TypeWithDict &objType)
Constructor taking as argument the type of the individual object passed to the scanner.
Definition: ScannerHelpers.h:49
helper::ScannerBase::print
void print(const void *obj) const
Definition: ScannerHelpers.cc:130
SelectorPtr.h
compare.hist
hist
Definition: compare.py:376
helper::ScannerBase::addExtraCut
bool addExtraCut(const char *cut)
Add one extra cut that can be evaluated separately (as if it was an expression)
Definition: ScannerHelpers.cc:92
helper::Parser::makeSelector
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)
Definition: ScannerHelpers.cc:25
helper::Parser::makeExpression
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)
Definition: ScannerHelpers.cc:8
helper::ScannerBase::fillProf
void fillProf(const void *obj, TProfile *prof) const
Definition: ScannerHelpers.cc:218
helper::ScannerBase::clearCut
void clearCut()
Clear the default cut.
Definition: ScannerHelpers.cc:88
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::TypeWithDict
Definition: TypeWithDict.h:38
electrons_cff.objType
objType
Definition: electrons_cff.py:514
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
helper::Parser::Parser
Parser()
Empty constructor, necessary for Root, useless.
Definition: ScannerHelpers.h:26
helper::ScannerBase::fill1D
void fill1D(const void *obj, TH1 *hist) const
Definition: ScannerHelpers.cc:179
helper
Definition: helper.py:1
helper::ScannerBase::ignoreExceptions_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
Definition: ScannerHelpers.h:110
helper::ScannerBase::fillGraph
void fillGraph(const void *obj, TGraph *graph) const
Definition: ScannerHelpers.cc:205
helper::ScannerBase::setCut
bool setCut(const char *cut)
Set the default cut that is applied to the events.
Definition: ScannerHelpers.cc:78
reco::parser::ExpressionPtr
std::shared_ptr< ExpressionBase > ExpressionPtr
Definition: ExpressionBase.h:25
helper::Parser::test
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.
Definition: ScannerHelpers.cc:53
helper::ScannerBase::clearExtraCuts
void clearExtraCuts()
Clear all extra cuts ;.
Definition: ScannerHelpers.cc:90
helper::ScannerBase::eval
double eval(const void *obj, size_t iexpr=0) const
Definition: ScannerHelpers.cc:118
helper::Parser
Definition: ScannerHelpers.h:23
ExpressionPtr.h
jets_cff.expr
expr
Definition: jets_cff.py:489
helper::ScannerBase::ScannerBase
ScannerBase()
Empty constructor, necessary for Root, DO NOT USE.
Definition: ScannerHelpers.h:47
reco::parser::SelectorPtr
std::shared_ptr< SelectorBase > SelectorPtr
Definition: SelectorPtr.h:18
helper::ScannerBase::test
bool test(const void *obj, size_t icut=0) const
Definition: ScannerHelpers.cc:103
helper::ScannerBase::numberOfExtraCuts
size_t numberOfExtraCuts() const
Number of extra cuts.
Definition: ScannerHelpers.h:68
helper::ScannerBase::setIgnoreExceptions
void setIgnoreExceptions(bool ignoreThem)
Definition: ScannerHelpers.h:100
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
helper::ScannerBase::exprs_
std::vector< reco::parser::ExpressionPtr > exprs_
Definition: ScannerHelpers.h:104
helper::ScannerBase::fill2D
void fill2D(const void *obj, TH2 *hist2d) const
Definition: ScannerHelpers.cc:192
helper::ScannerBase::clearExpressions
void clearExpressions()
Clear all the expressions.
Definition: ScannerHelpers.h:55
SelectorBase.h