test
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 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::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...
 
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.

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

References ecal_dqm_sourceclient-live_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().

64  {
65  bool ok = true;
67  if (exprs_.back().get() == 0) {
68  std::cerr << "Failed to parse expression " << expr << std::endl;
69  exprs_.pop_back();
70  ok = false;
71  }
72  return ok;
73 }
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 98 of file ScannerHelpers.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, helper::Parser::makeSelector(), and convertSQLiteXML::ok.

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

98  {
99  bool ok = true;
101  if (!cuts_.back().get()) {
102  std::cerr << "Failed to add cut \"" << cut << "\"" << std::endl;
103  ok = false;
104  cuts_.pop_back();
105  }
106  return ok;
107 }
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 87 of file ScannerHelpers.cc.

87  {
88  cuts_[0].reset();
89 }
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 92 of file ScannerHelpers.cc.

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

References ecal_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, getGTfromDQMFile::obj, and relativeConstraints::value.

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

124  {
125  try {
126  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
127  if (exprs_.size() > iexpr) return exprs_[iexpr]->value(obj);
128  } catch (std::exception &ex) {
129  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
130  }
131  return 0;
132 }
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 182 of file ScannerHelpers.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, and getGTfromDQMFile::obj.

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

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

References ecal_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, and getGTfromDQMFile::obj.

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

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

References ecal_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, and getGTfromDQMFile::obj.

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

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

References ecal_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, and getGTfromDQMFile::obj.

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

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

References ecal_dqm_sourceclient-live_cfg::cerr, gather_cfg::cout, cppFunctionSkipper::exception, getGTfromDQMFile::obj, and runTheMatrix::ret.

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

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

Set the default cut that is applied to the events.

Definition at line 76 of file ScannerHelpers.cc.

References ecal_dqm_sourceclient-live_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().

76  {
77  bool ok = true;
79  if (strlen(cut) && !cuts_[0].get()) {
80  std::cerr << "Failed to set cut \"" << cut << "\"" << std::endl;
81  ok = false;
82  }
83  return ok;
84 }
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.

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

References ecal_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, and getGTfromDQMFile::obj.

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

111  {
112  if (icut >= cuts_.size()) return false;
113  if (cuts_[icut].get() == 0) return true;
114  try {
115  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
116  return (*cuts_[icut])(obj);
117  } catch (std::exception &ex) {
118  if (!ignoreExceptions_) std::cerr << "Caught exception " << ex.what() << std::endl;
119  return false;
120  }
121 }
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.

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().

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

Definition at line 103 of file ScannerHelpers.h.