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 44 of file ScannerHelpers.h.

Constructor & Destructor Documentation

◆ ScannerBase() [1/2]

helper::ScannerBase::ScannerBase ( )
inline

Empty constructor, necessary for Root, DO NOT USE.

Definition at line 47 of file ScannerHelpers.h.

47 {}

◆ ScannerBase() [2/2]

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 49 of file ScannerHelpers.h.

49 : 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

◆ addExpression()

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

References DMR_cfg::cerr, electrons_cff::expr, 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().

67  {
68  bool ok = true;
70  if (exprs_.back().get() == nullptr) {
71  std::cerr << "Failed to parse expression " << expr << std::endl;
72  exprs_.pop_back();
73  ok = false;
74  }
75  return ok;
76 }
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_

◆ addExtraCut()

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

References DMR_cfg::cerr, TkAlMuonSelectors_cfi::cut, helper::Parser::makeSelector(), and convertSQLiteXML::ok.

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

92  {
93  bool ok = true;
95  if (!cuts_.back().get()) {
96  std::cerr << "Failed to add cut \"" << cut << "\"" << std::endl;
97  ok = false;
98  cuts_.pop_back();
99  }
100  return ok;
101 }
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_

◆ clearCut()

void helper::ScannerBase::clearCut ( )

Clear the default cut.

Definition at line 88 of file ScannerHelpers.cc.

88 { cuts_[0].reset(); }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.

◆ clearExpressions()

void helper::ScannerBase::clearExpressions ( )
inline

Clear all the expressions.

Definition at line 55 of file ScannerHelpers.h.

References exprs_.

55 { exprs_.clear(); }
std::vector< reco::parser::ExpressionPtr > exprs_

◆ clearExtraCuts()

void helper::ScannerBase::clearExtraCuts ( )

Clear all extra cuts ;.

Definition at line 90 of file ScannerHelpers.cc.

90 { cuts_.resize(1); }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.

◆ eval()

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

References DMR_cfg::cerr, cppFunctionSkipper::exception, getGTfromDQMFile::obj, and relativeConstraints::value.

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

118  {
119  try {
120  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
121  if (exprs_.size() > iexpr)
122  return exprs_[iexpr]->value(obj);
123  } catch (std::exception &ex) {
124  if (!ignoreExceptions_)
125  std::cerr << "Caught exception " << ex.what() << std::endl;
126  }
127  return 0;
128 }
std::vector< reco::parser::ExpressionPtr > exprs_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
edm::TypeWithDict objType_

◆ fill1D()

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

References DMR_cfg::cerr, cppFunctionSkipper::exception, compareTotals::hist, and getGTfromDQMFile::obj.

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

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

◆ fill2D()

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

References DMR_cfg::cerr, cppFunctionSkipper::exception, compareTotals::hist, and getGTfromDQMFile::obj.

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

192  {
193  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
194  if ((cuts_[0].get() == nullptr) || (*cuts_[0])(obj)) {
195  try {
196  if (exprs_.size() >= 2)
197  hist->Fill(exprs_[0]->value(obj), exprs_[1]->value(obj));
198  } catch (std::exception &ex) {
199  if (!ignoreExceptions_)
200  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_

◆ fillGraph()

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

References DMR_cfg::cerr, cppFunctionSkipper::exception, and getGTfromDQMFile::obj.

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

205  {
206  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
207  if ((cuts_[0].get() == nullptr) || (*cuts_[0])(obj)) {
208  try {
209  if (exprs_.size() >= 2)
210  graph->SetPoint(graph->GetN(), exprs_[0]->value(obj), exprs_[1]->value(obj));
211  } catch (std::exception &ex) {
212  if (!ignoreExceptions_)
213  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_

◆ fillProf()

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

References DMR_cfg::cerr, cppFunctionSkipper::exception, compareTotals::hist, and getGTfromDQMFile::obj.

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

218  {
219  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
220  if ((cuts_[0].get() == nullptr) || (*cuts_[0])(obj)) {
221  try {
222  if (exprs_.size() >= 2)
223  hist->Fill(exprs_[0]->value(obj), exprs_[1]->value(obj));
224  } catch (std::exception &ex) {
225  if (!ignoreExceptions_)
226  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_

◆ numberOfExpressions()

size_t helper::ScannerBase::numberOfExpressions ( ) const
inline

Number of valid expressions.

Definition at line 57 of file ScannerHelpers.h.

References exprs_.

57 { return exprs_.size(); }
std::vector< reco::parser::ExpressionPtr > exprs_

◆ numberOfExtraCuts()

size_t helper::ScannerBase::numberOfExtraCuts ( ) const
inline

Number of extra cuts.

Definition at line 68 of file ScannerHelpers.h.

References cuts_.

68 { return cuts_.size() - 1; }
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.

◆ print()

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

References DMR_cfg::cerr, gather_cfg::cout, cppFunctionSkipper::exception, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, getGTfromDQMFile::obj, runTheMatrix::ret, mps_setup::stdout, and heppy_batch::val.

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

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

◆ setCut()

bool helper::ScannerBase::setCut ( const char *  cut)

Set the default cut that is applied to the events.

Definition at line 78 of file ScannerHelpers.cc.

References DMR_cfg::cerr, TkAlMuonSelectors_cfi::cut, 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().

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

◆ setIgnoreExceptions()

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

100 { ignoreExceptions_ = ignoreThem; }
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.

◆ test()

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

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

103  {
104  if (icut >= cuts_.size())
105  return false;
106  if (cuts_[icut].get() == nullptr)
107  return true;
108  try {
109  edm::ObjectWithDict obj(objType_, const_cast<void *>(ptr));
110  return (*cuts_[icut])(obj);
111  } catch (std::exception &ex) {
112  if (!ignoreExceptions_)
113  std::cerr << "Caught exception " << ex.what() << std::endl;
114  return false;
115  }
116 }
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

◆ cuts_

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

◆ exprs_

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

Definition at line 104 of file ScannerHelpers.h.

Referenced by clearExpressions(), and numberOfExpressions().

◆ ignoreExceptions_

bool helper::ScannerBase::ignoreExceptions_
private

See setIgnoreExceptions to find out what this means.

Definition at line 110 of file ScannerHelpers.h.

Referenced by setIgnoreExceptions().

◆ objType_

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

Definition at line 103 of file ScannerHelpers.h.