CMS 3D CMS Logo

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 Root, DO NOT USE. More...
 
 ScannerBase (const edm::TypeWithDict &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::SelectorPtrcuts_
 The first one is the default cut, the others are the extra ones. More...
 
std::vector< reco::parser::ExpressionPtrexprs_
 
bool ignoreExceptions_
 See setIgnoreExceptions to find out what this means. More...
 
edm::TypeWithDict objType_
 

Detailed Description

Class helper::ScannerBase: tool to print or histogram proprieties of an object using the dictionary, The class is generic, but each instance is restricted to the 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 Root, DO NOT USE.

Definition at line 48 of file ScannerHelpers.h.

48 {}
helper::ScannerBase::ScannerBase ( const edm::TypeWithDict objType)
inline

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

Definition at line 50 of file ScannerHelpers.h.

References jets_cff::expr.

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.
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
edm::TypeWithDict objType_

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 65 of file ScannerHelpers.cc.

References MessageLogger_cfi::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().

65  {
66  bool ok = true;
68  if (exprs_.back().get() == nullptr) {
69  std::cerr << "Failed to parse expression " << expr << std::endl;
70  exprs_.pop_back();
71  ok = false;
72  }
73  return ok;
74 }
std::vector< reco::parser::ExpressionPtr > exprs_
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) ...
edm::TypeWithDict objType_
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 99 of file ScannerHelpers.cc.

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

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

99  {
100  bool ok = true;
102  if (!cuts_.back().get()) {
103  std::cerr << "Failed to add cut \"" << cut << "\"" << std::endl;
104  ok = false;
105  cuts_.pop_back();
106  }
107  return ok;
108 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
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_
void helper::ScannerBase::clearCut ( )

Clear the default cut.

Definition at line 88 of file ScannerHelpers.cc.

88  {
89  cuts_[0].reset();
90 }
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.

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

Clear all extra cuts ;.

Definition at line 93 of file ScannerHelpers.cc.

93  {
94  cuts_.resize(1);
95 }
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 125 of file ScannerHelpers.cc.

References MessageLogger_cfi::cerr, cppFunctionSkipper::exception, hgcalPlots::obj, and relativeConstraints::value.

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

125  {
126  try {
127  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
128  if (exprs_.size() > iexpr) return exprs_[iexpr]->value(obj);
129  } catch (std::exception &ex) {
130  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
131  }
132  return 0;
133 }
std::vector< reco::parser::ExpressionPtr > exprs_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
edm::TypeWithDict objType_
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 183 of file ScannerHelpers.cc.

References MessageLogger_cfi::cerr, cppFunctionSkipper::exception, and hgcalPlots::obj.

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

183  {
184  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
185  if ((cuts_[0].get() == nullptr) || (*cuts_[0])(obj)) {
186  try {
187  if (!exprs_.empty()) hist->Fill(exprs_[0]->value(obj));
188  } catch (std::exception &ex) {
189  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
190  }
191  }
192 }
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.
edm::TypeWithDict objType_
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 195 of file ScannerHelpers.cc.

References MessageLogger_cfi::cerr, cppFunctionSkipper::exception, and hgcalPlots::obj.

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

195  {
196  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
197  if ((cuts_[0].get() == nullptr) || (*cuts_[0])(obj)) {
198  try {
199  if (exprs_.size() >= 2) hist->Fill(exprs_[0]->value(obj), exprs_[1]->value(obj));
200  } catch (std::exception &ex) {
201  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
202  }
203  }
204 }
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.
edm::TypeWithDict objType_
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 207 of file ScannerHelpers.cc.

References MessageLogger_cfi::cerr, cppFunctionSkipper::exception, and hgcalPlots::obj.

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

207  {
208  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
209  if ((cuts_[0].get() == nullptr) || (*cuts_[0])(obj)) {
210  try {
211  if (exprs_.size() >= 2) graph->SetPoint(graph->GetN(), exprs_[0]->value(obj), exprs_[1]->value(obj));
212  } catch (std::exception &ex) {
213  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
214  }
215  }
216 }
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.
edm::TypeWithDict objType_
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 220 of file ScannerHelpers.cc.

References MessageLogger_cfi::cerr, cppFunctionSkipper::exception, and hgcalPlots::obj.

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

220  {
221  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
222  if ((cuts_[0].get() == nullptr) || (*cuts_[0])(obj)) {
223  try {
224  if (exprs_.size() >= 2) hist->Fill(exprs_[0]->value(obj), exprs_[1]->value(obj));
225  } catch (std::exception &ex) {
226  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
227  }
228  }
229 }
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.
edm::TypeWithDict objType_
size_t helper::ScannerBase::numberOfExpressions ( ) const
inline

Number of valid expressions.

Definition at line 58 of file ScannerHelpers.h.

References TkAlMuonSelectors_cfi::cut.

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 helper::Parser::eval(), create_public_lumi_plots::hist, hgcalPlots::obj, edm::print(), and helper::Parser::test().

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 136 of file ScannerHelpers.cc.

References MessageLogger_cfi::cerr, gather_cfg::cout, cppFunctionSkipper::exception, hgcalPlots::obj, mps_setup::stdout, and heppy_batch::val.

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

136  {
137  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
138  if ((cuts_[0].get() == nullptr) || (*cuts_[0])(obj)) {
139  for (std::vector<reco::parser::ExpressionPtr>::const_iterator it = exprs_.begin(), ed = exprs_.end(); it != ed; ++it) {
140  if (ptr == nullptr || it->get() == nullptr) {
141  printf(" : %8s", "#ERR");
142  } else {
143  try {
144  double val = (*it)->value(obj);
145  // 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)
146  // So we have to go the ugly way
147  char buff[255];
148  int len = sprintf(buff," : % 8.6g",val); // this is usually ok, and should be 3+8 chars long
149  if (len == 3+8) {
150  std::cout << buff;
151  } else {
152  if (strchr(buff,'e')) {
153  printf((len == 3+13 ? " : % .0e" : " : % .1e"),val);
154  } else {
155  printf("%11.11s",buff);
156  }
157  }
158  } catch (std::exception &ex) {
159  printf(" : %8s", "EXCEPT");
160  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
161  }
162  }
163  }
164  for (std::vector<reco::parser::SelectorPtr>::const_iterator it = cuts_.begin()+1, ed = cuts_.end(); it != ed; ++it) {
165  if (ptr == nullptr || it->get() == nullptr) {
166  printf(" : %8s", "#ERR");
167  } else {
168  try {
169  int ret = (*it)->operator()(obj);
170  printf(" : %8d", ret);
171  } catch (std::exception &ex) {
172  printf(" : %8s", "EXCEPT");
173  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
174  }
175  }
176  }
177  fflush(stdout);
178  }
179 }
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.
edm::TypeWithDict objType_
bool helper::ScannerBase::setCut ( const char *  cut)

Set the default cut that is applied to the events.

Definition at line 77 of file ScannerHelpers.cc.

References MessageLogger_cfi::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(), and fwlite::Scanner< Collection >::scan().

77  {
78  bool ok = true;
80  if (strlen(cut) && !cuts_[0].get()) {
81  std::cerr << "Failed to set cut \"" << cut << "\"" << std::endl;
82  ok = false;
83  }
84  return ok;
85 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
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_
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.

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(), and fwlite::Scanner< Collection >::scan().

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 112 of file ScannerHelpers.cc.

References MessageLogger_cfi::cerr, cppFunctionSkipper::exception, and hgcalPlots::obj.

Referenced by fwlite::Scanner< Collection >::count(), fwlite::Scanner< Collection >::draw2D(), fwlite::Scanner< Collection >::fillDataSet(), edmIntegrityCheck.IntegrityCheck::report(), fwlite::Scanner< Collection >::scan(), and edmIntegrityCheck.IntegrityCheck::structured().

112  {
113  if (icut >= cuts_.size()) return false;
114  if (cuts_[icut].get() == nullptr) return true;
115  try {
116  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
117  return (*cuts_[icut])(obj);
118  } catch (std::exception &ex) {
119  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
120  return false;
121  }
122 }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
edm::TypeWithDict objType_

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.

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

Definition at line 104 of file ScannerHelpers.h.

bool helper::ScannerBase::ignoreExceptions_
private

See setIgnoreExceptions to find out what this means.

Definition at line 110 of file ScannerHelpers.h.

edm::TypeWithDict helper::ScannerBase::objType_
private

Definition at line 103 of file ScannerHelpers.h.