#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) | |
void | clearCut () |
Clear the default cut. | |
void | clearExpressions () |
Clear all the expressions. | |
void | clearExtraCuts () |
Clear all extra cuts ;. | |
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. | |
size_t | numberOfExtraCuts () const |
Number of extra cuts. | |
void | print (const void *obj) const |
ScannerBase (const Reflex::Type &objType) | |
Constructor taking as argument the type of the individual object passed to the scanner. | |
ScannerBase () | |
Empty constructor, necessary for Reflex, DO NOT USE. | |
bool | setCut (const char *cut) |
Set the default cut that is applied to the events. | |
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. | |
std::vector < reco::parser::ExpressionPtr > | exprs_ |
bool | ignoreExceptions_ |
See setIgnoreExceptions to find out what this means. | |
Reflex::Type | objType_ |
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.
helper::ScannerBase::ScannerBase | ( | ) | [inline] |
Empty constructor, necessary for Reflex, DO NOT USE.
Definition at line 48 of file ScannerHelpers.h.
{}
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.
: objType_(objType), cuts_(1), ignoreExceptions_(false) {}
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 ExpressReco_HICollisions_FallBack::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().
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 ExpressReco_HICollisions_FallBack::cerr, helper::Parser::makeSelector(), and convertSQLiteXML::ok.
Referenced by fwlite::Scanner< Collection >::fillDataSet().
void helper::ScannerBase::clearCut | ( | ) |
void helper::ScannerBase::clearExpressions | ( | ) | [inline] |
Clear all the expressions.
Definition at line 56 of file ScannerHelpers.h.
References exprs_.
{ exprs_.clear(); }
void helper::ScannerBase::clearExtraCuts | ( | ) |
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 ExpressReco_HICollisions_FallBack::cerr, exception, VarParsing::obj, and relativeConstraints::value.
Referenced by fwlite::Scanner< Collection >::draw2D(), and fwlite::Scanner< Collection >::fillDataSet().
{ try { Reflex::Object obj(objType_, const_cast<void *>(ptr)); if (exprs_.size() > iexpr) return exprs_[iexpr]->value(obj); } catch (std::exception &ex) { if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl; } return 0; }
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 ExpressReco_HICollisions_FallBack::cerr, exception, and VarParsing::obj.
Referenced by fwlite::Scanner< Collection >::draw().
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 ExpressReco_HICollisions_FallBack::cerr, exception, and VarParsing::obj.
Referenced by fwlite::Scanner< Collection >::draw2D().
{ Reflex::Object obj(objType_, const_cast<void *>(ptr)); if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) { try { if (exprs_.size() >= 2) hist->Fill(exprs_[0]->value(obj), exprs_[1]->value(obj)); } catch (std::exception &ex) { if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl; } } }
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 ExpressReco_HICollisions_FallBack::cerr, exception, and VarParsing::obj.
Referenced by fwlite::Scanner< Collection >::drawGraph().
{ Reflex::Object obj(objType_, const_cast<void *>(ptr)); if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) { try { if (exprs_.size() >= 2) graph->SetPoint(graph->GetN(), exprs_[0]->value(obj), exprs_[1]->value(obj)); } catch (std::exception &ex) { if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl; } } }
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 ExpressReco_HICollisions_FallBack::cerr, exception, and VarParsing::obj.
Referenced by fwlite::Scanner< Collection >::drawProf().
{ Reflex::Object obj(objType_, const_cast<void *>(ptr)); if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) { try { if (exprs_.size() >= 2) hist->Fill(exprs_[0]->value(obj), exprs_[1]->value(obj)); } catch (std::exception &ex) { if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl; } } }
size_t helper::ScannerBase::numberOfExpressions | ( | ) | const [inline] |
Number of valid expressions.
Definition at line 58 of file ScannerHelpers.h.
References exprs_.
{ return exprs_.size(); }
size_t helper::ScannerBase::numberOfExtraCuts | ( | ) | const [inline] |
Number of extra cuts.
Definition at line 69 of file ScannerHelpers.h.
References cuts_.
{ return cuts_.size()-1; }
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 ExpressReco_HICollisions_FallBack::cerr, exception, VarParsing::obj, and runTheMatrix::ret.
Referenced by fwlite::Scanner< Collection >::scan().
{ Reflex::Object obj(objType_, const_cast<void *>(ptr)); if ((cuts_[0].get() == 0) || (*cuts_[0])(obj)) { for (std::vector<reco::parser::ExpressionPtr>::const_iterator it = exprs_.begin(), ed = exprs_.end(); it != ed; ++it) { if (ptr == 0 || it->get() == 0) { printf(" : %8s", "#ERR"); } else { try { double val = (*it)->value(obj); // 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) // So we have to go the ugly way char buff[255]; int len = sprintf(buff," : % 8.6g",val); // this is usually ok, and should be 3+8 chars long if (len == 3+8) { printf(buff); } else { if (strchr(buff,'e')) { printf((len == 3+13 ? " : % .0e" : " : % .1e"),val); } else { printf("%11.11s",buff); } } } catch (std::exception &ex) { printf(" : %8s", "EXCEPT"); if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl; } } } for (std::vector<reco::parser::SelectorPtr>::const_iterator it = cuts_.begin()+1, ed = cuts_.end(); it != ed; ++it) { if (ptr == 0 || it->get() == 0) { printf(" : %8s", "#ERR"); } else { try { int ret = (*it)->operator()(obj); printf(" : %8d", ret); } catch (std::exception &ex) { printf(" : %8s", "EXCEPT"); if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl; } } } fflush(stdout); } }
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 ExpressReco_HICollisions_FallBack::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().
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().
{ ignoreExceptions_ = ignoreThem; }
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 ExpressReco_HICollisions_FallBack::cerr, 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().
{ if (icut >= cuts_.size()) return false; if (cuts_[icut].get() == 0) return true; try { Reflex::Object obj(objType_, const_cast<void *>(ptr)); return (*cuts_[icut])(obj); } catch (std::exception &ex) { if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl; return false; } }
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.