CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
helper::ScannerBase Class Reference

#include <ScannerHelpers.h>

Public Member Functions

bool addExpression (const char *expr)
 
bool addExtraCut (const char *cut)
 Add one extra cut that can be evaluated separately (as if it was an expression) More...
 
void clearCut ()
 Clear the default cut. More...
 
void clearExpressions ()
 Clear all the expressions. More...
 
void clearExtraCuts ()
 Clear all extra cuts ;. More...
 
double eval (const void *obj, size_t iexpr=0) const
 
void fill1D (const void *obj, TH1 *hist) const
 
void fill2D (const void *obj, TH2 *hist2d) const
 
void fillGraph (const void *obj, TGraph *graph) const
 
void fillProf (const void *obj, TProfile *prof) const
 
size_t numberOfExpressions () const
 Number of valid expressions. More...
 
size_t numberOfExtraCuts () const
 Number of extra cuts. More...
 
void print (const void *obj) const
 
 ScannerBase ()
 Empty constructor, necessary for Reflex, DO NOT USE. More...
 
 ScannerBase (const Reflex::Type &objType)
 Constructor taking as argument the type of the individual object passed to the scanner. More...
 
bool setCut (const char *cut)
 Set the default cut that is applied to the events. More...
 
void setIgnoreExceptions (bool ignoreThem)
 
bool test (const void *obj, size_t icut=0) const
 

Private Attributes

std::vector
< reco::parser::SelectorPtr
cuts_
 The first one is the default cut, the others are the extra ones. More...
 
std::vector
< reco::parser::ExpressionPtr
exprs_
 
bool ignoreExceptions_
 See setIgnoreExceptions to find out what this means. More...
 
Reflex::Type objType_
 

Detailed Description

Class helper::ScannerBase: tool to print or histogram proprieties of an object using Reflex, The class is generic, but each instance is restricted to the Reflex type of the objects to inspect, fixed at construction time.

Definition at line 45 of file ScannerHelpers.h.

Constructor & Destructor Documentation

helper::ScannerBase::ScannerBase ( )
inline

Empty constructor, necessary for Reflex, DO NOT USE.

Definition at line 48 of file ScannerHelpers.h.

48 {}
helper::ScannerBase::ScannerBase ( const Reflex::Type &  objType)
inline

Constructor taking as argument the type of the individual object passed to the scanner.

Definition at line 50 of file ScannerHelpers.h.

50 : objType_(objType), cuts_(1), ignoreExceptions_(false) {}
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
Reflex::Type objType_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.

Member Function Documentation

bool helper::ScannerBase::addExpression ( const char *  expr)

Add an expression to be evaluated on the objects Returns false if the parsing failed

Definition at line 68 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, helper::Parser::makeExpression(), and convertSQLiteXML::ok.

Referenced by fwlite::Scanner< Collection >::draw(), fwlite::Scanner< Collection >::draw2D(), fwlite::Scanner< Collection >::drawGraph(), fwlite::Scanner< Collection >::drawProf(), fwlite::Scanner< Collection >::fillDataSet(), and fwlite::Scanner< Collection >::scan().

68  {
69  bool ok = true;
71  if (exprs_.back().get() == 0) {
72  std::cerr << "Failed to parse expression " << expr << std::endl;
73  exprs_.pop_back();
74  ok = false;
75  }
76  return ok;
77 }
std::vector< reco::parser::ExpressionPtr > exprs_
Reflex::Type objType_
static reco::parser::ExpressionPtr makeExpression(const std::string &expr, const Reflex::Type &type)
Parse an expression for a given object type (using lazy parsing when resolving methods) ...
bool helper::ScannerBase::addExtraCut ( const char *  cut)

Add one extra cut that can be evaluated separately (as if it was an expression)

Definition at line 102 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, helper::Parser::makeSelector(), and convertSQLiteXML::ok.

Referenced by fwlite::Scanner< Collection >::fillDataSet().

102  {
103  bool ok = true;
105  if (!cuts_.back().get()) {
106  std::cerr << "Failed to add cut \"" << cut << "\"" << std::endl;
107  ok = false;
108  cuts_.pop_back();
109  }
110  return ok;
111 }
static reco::parser::SelectorPtr makeSelector(const std::string &expr, const Reflex::Type &type)
Parse an expression for a given object type (using lazy parsing when resolving methods) ...
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
Reflex::Type objType_
tuple cut
Definition: align_tpl.py:88
void helper::ScannerBase::clearCut ( )

Clear the default cut.

Definition at line 91 of file ScannerHelpers.cc.

91  {
92  cuts_[0].reset();
93 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
void helper::ScannerBase::clearExpressions ( )
inline

Clear all the expressions.

Definition at line 56 of file ScannerHelpers.h.

References exprs_.

56 { exprs_.clear(); }
std::vector< reco::parser::ExpressionPtr > exprs_
void helper::ScannerBase::clearExtraCuts ( )

Clear all extra cuts ;.

Definition at line 96 of file ScannerHelpers.cc.

96  {
97  cuts_.resize(1);
98 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
double helper::ScannerBase::eval ( const void *  obj,
size_t  iexpr = 0 
) const

Evaluate one of the expressions set in this scanner Obj must point to an object of the type used to construct this ScannerBase

Definition at line 128 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, cmsCodeRules.cppFunctionSkipper::exception, VarParsing::obj, and relativeConstraints::value.

Referenced by fwlite::Scanner< Collection >::draw2D(), and fwlite::Scanner< Collection >::fillDataSet().

128  {
129  try {
130  Reflex::Object obj(objType_, const_cast<void *>(ptr));
131  if (exprs_.size() > iexpr) return exprs_[iexpr]->value(obj);
132  } catch (std::exception &ex) {
133  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
134  }
135  return 0;
136 }
std::vector< reco::parser::ExpressionPtr > exprs_
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
Reflex::Type objType_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
void helper::ScannerBase::fill1D ( const void *  obj,
TH1 *  hist 
) const

Fill the histogram with the first expression evaluated on the object, if it passes the default cut Obj must point to an object of the type used to construct this ScannerBase

Definition at line 186 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, cmsCodeRules.cppFunctionSkipper::exception, and VarParsing::obj.

Referenced by fwlite::Scanner< Collection >::draw().

186  {
187  Reflex::Object obj(objType_, const_cast<void *>(ptr));
188  if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) {
189  try {
190  if (!exprs_.empty()) hist->Fill(exprs_[0]->value(obj));
191  } catch (std::exception &ex) {
192  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
193  }
194  }
195 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
std::vector< reco::parser::ExpressionPtr > exprs_
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
Reflex::Type objType_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
void helper::ScannerBase::fill2D ( const void *  obj,
TH2 *  hist2d 
) const

Fill the histogram with (x,y) equal to the first and second expressions evaluated on the object, if it passes the default cut Obj must point to an object of the type used to construct this ScannerBase

Definition at line 198 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, cmsCodeRules.cppFunctionSkipper::exception, and VarParsing::obj.

Referenced by fwlite::Scanner< Collection >::draw2D().

198  {
199  Reflex::Object obj(objType_, const_cast<void *>(ptr));
200  if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) {
201  try {
202  if (exprs_.size() >= 2) hist->Fill(exprs_[0]->value(obj), exprs_[1]->value(obj));
203  } catch (std::exception &ex) {
204  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
205  }
206  }
207 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
std::vector< reco::parser::ExpressionPtr > exprs_
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
Reflex::Type objType_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
void helper::ScannerBase::fillGraph ( const void *  obj,
TGraph *  graph 
) const

Fill the graph with (x,y) equal to the first and second expressions evaluated on the object, if it passes the default cut Obj must point to an object of the type used to construct this ScannerBase

Definition at line 210 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, cmsCodeRules.cppFunctionSkipper::exception, and VarParsing::obj.

Referenced by fwlite::Scanner< Collection >::drawGraph().

210  {
211  Reflex::Object obj(objType_, const_cast<void *>(ptr));
212  if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) {
213  try {
214  if (exprs_.size() >= 2) graph->SetPoint(graph->GetN(), exprs_[0]->value(obj), exprs_[1]->value(obj));
215  } catch (std::exception &ex) {
216  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
217  }
218  }
219 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
std::vector< reco::parser::ExpressionPtr > exprs_
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
Reflex::Type objType_
Definition: adjgraph.h:15
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
void helper::ScannerBase::fillProf ( const void *  obj,
TProfile *  prof 
) const

Fill the profile histogram with (x,y) equal to the first and second expressions evaluated on the object, if it passes the default cut Obj must point to an object of the type used to construct this ScannerBase

Definition at line 223 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, cmsCodeRules.cppFunctionSkipper::exception, and VarParsing::obj.

Referenced by fwlite::Scanner< Collection >::drawProf().

223  {
224  Reflex::Object obj(objType_, const_cast<void *>(ptr));
225  if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) {
226  try {
227  if (exprs_.size() >= 2) hist->Fill(exprs_[0]->value(obj), exprs_[1]->value(obj));
228  } catch (std::exception &ex) {
229  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
230  }
231  }
232 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
std::vector< reco::parser::ExpressionPtr > exprs_
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
Reflex::Type objType_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
size_t helper::ScannerBase::numberOfExpressions ( ) const
inline

Number of valid expressions.

Definition at line 58 of file ScannerHelpers.h.

References exprs_.

58 { return exprs_.size(); }
std::vector< reco::parser::ExpressionPtr > exprs_
size_t helper::ScannerBase::numberOfExtraCuts ( ) const
inline

Number of extra cuts.

Definition at line 69 of file ScannerHelpers.h.

References cuts_.

69 { return cuts_.size()-1; }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
void helper::ScannerBase::print ( const void *  obj) const

Print out in a single row all the expressions for this object Obj must point to an object of the type used to construct this ScannerBase

Definition at line 139 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, cmsCodeRules.cppFunctionSkipper::exception, VarParsing::obj, and runTheMatrix::ret.

Referenced by fwlite::Scanner< Collection >::scan().

139  {
140  Reflex::Object obj(objType_, const_cast<void *>(ptr));
141  if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) {
142  for (std::vector<reco::parser::ExpressionPtr>::const_iterator it = exprs_.begin(), ed = exprs_.end(); it != ed; ++it) {
143  if (ptr == 0 || it->get() == 0) {
144  printf(" : %8s", "#ERR");
145  } else {
146  try {
147  double val = (*it)->value(obj);
148  // I found no easy ways to enforce a fixed width from printf that works also with leading zeroes or large exponents (e.g. 1e15 or 1e101)
149  // So we have to go the ugly way
150  char buff[255];
151  int len = sprintf(buff," : % 8.6g",val); // this is usually ok, and should be 3+8 chars long
152  if (len == 3+8) {
153  printf(buff);
154  } else {
155  if (strchr(buff,'e')) {
156  printf((len == 3+13 ? " : % .0e" : " : % .1e"),val);
157  } else {
158  printf("%11.11s",buff);
159  }
160  }
161  } catch (std::exception &ex) {
162  printf(" : %8s", "EXCEPT");
163  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
164  }
165  }
166  }
167  for (std::vector<reco::parser::SelectorPtr>::const_iterator it = cuts_.begin()+1, ed = cuts_.end(); it != ed; ++it) {
168  if (ptr == 0 || it->get() == 0) {
169  printf(" : %8s", "#ERR");
170  } else {
171  try {
172  int ret = (*it)->operator()(obj);
173  printf(" : %8d", ret);
174  } catch (std::exception &ex) {
175  printf(" : %8s", "EXCEPT");
176  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
177  }
178  }
179  }
180  fflush(stdout);
181  }
182 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
std::vector< reco::parser::ExpressionPtr > exprs_
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
Reflex::Type objType_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
bool helper::ScannerBase::setCut ( const char *  cut)

Set the default cut that is applied to the events.

Definition at line 80 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, helper::Parser::makeSelector(), and convertSQLiteXML::ok.

Referenced by fwlite::Scanner< Collection >::count(), fwlite::Scanner< Collection >::draw(), fwlite::Scanner< Collection >::draw2D(), fwlite::Scanner< Collection >::drawGraph(), fwlite::Scanner< Collection >::drawProf(), fwlite::Scanner< Collection >::fillDataSet(), fwlite::ObjectCountSelector< Collection >::ObjectCountSelector(), fwlite::Scanner< Collection >::scan(), and fwlite::ObjectCountSelector< Collection >::setCut().

80  {
81  bool ok = true;
83  if (strlen(cut) && !cuts_[0].get()) {
84  std::cerr << "Failed to set cut \"" << cut << "\"" << std::endl;
85  ok = false;
86  }
87  return ok;
88 }
static reco::parser::SelectorPtr makeSelector(const std::string &expr, const Reflex::Type &type)
Parse an expression for a given object type (using lazy parsing when resolving methods) ...
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
Reflex::Type objType_
tuple cut
Definition: align_tpl.py:88
void helper::ScannerBase::setIgnoreExceptions ( bool  ignoreThem)
inline

If set to true, exceptions are silently ignored: test will return 'false', and 'eval' will return 0. If left to the default value, false, for each exception a printout is done.

Definition at line 101 of file ScannerHelpers.h.

References ignoreExceptions_.

Referenced by fwlite::Scanner< Collection >::count(), fwlite::Scanner< Collection >::draw(), fwlite::Scanner< Collection >::draw2D(), fwlite::Scanner< Collection >::drawGraph(), fwlite::Scanner< Collection >::drawProf(), fwlite::Scanner< Collection >::fillDataSet(), fwlite::ObjectCountSelector< Collection >::ObjectCountSelector(), fwlite::Scanner< Collection >::scan(), and fwlite::ObjectCountSelector< Collection >::setIgnoreExceptions().

101 { ignoreExceptions_ = ignoreThem; }
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
bool helper::ScannerBase::test ( const void *  obj,
size_t  icut = 0 
) const

Check if the object passes the default cut (icut=0) or any extra cut (icut = 1 .. numberOfExtraCuts) Obj must point to an object of the type used to construct this ScannerBase

Definition at line 115 of file ScannerHelpers.cc.

References benchmark_cfg::cerr, cmsCodeRules.cppFunctionSkipper::exception, and VarParsing::obj.

Referenced by fwlite::ObjectCountSelector< Collection >::accept(), fwlite::Scanner< Collection >::count(), fwlite::Scanner< Collection >::draw2D(), fwlite::Scanner< Collection >::fillDataSet(), and fwlite::Scanner< Collection >::scan().

115  {
116  if (icut >= cuts_.size()) return false;
117  if (cuts_[icut].get() == 0) return true;
118  try {
119  Reflex::Object obj(objType_, const_cast<void *>(ptr));
120  return (*cuts_[icut])(obj);
121  } catch (std::exception &ex) {
122  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
123  return false;
124  }
125 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
Reflex::Type objType_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.

Member Data Documentation

std::vector<reco::parser::SelectorPtr> helper::ScannerBase::cuts_
private

The first one is the default cut, the others are the extra ones.

Definition at line 107 of file ScannerHelpers.h.

Referenced by numberOfExtraCuts().

std::vector<reco::parser::ExpressionPtr> helper::ScannerBase::exprs_
private

Definition at line 104 of file ScannerHelpers.h.

Referenced by clearExpressions(), and numberOfExpressions().

bool helper::ScannerBase::ignoreExceptions_
private

See setIgnoreExceptions to find out what this means.

Definition at line 110 of file ScannerHelpers.h.

Referenced by setIgnoreExceptions().

Reflex::Type helper::ScannerBase::objType_
private

Definition at line 103 of file ScannerHelpers.h.