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) {}

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.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, jets_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().

◆ 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.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, TkAlMuonSelectors_cfi::cut, helper::Parser::makeSelector(), and convertSQLiteXML::ok.

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

◆ clearCut()

void helper::ScannerBase::clearCut ( )

Clear the default cut.

Definition at line 88 of file ScannerHelpers.cc.

88 { cuts_[0].reset(); }

◆ clearExpressions()

void helper::ScannerBase::clearExpressions ( )
inline

Clear all the expressions.

Definition at line 55 of file ScannerHelpers.h.

55 { exprs_.clear(); }

References exprs_.

◆ clearExtraCuts()

void helper::ScannerBase::clearExtraCuts ( )

Clear all extra cuts ;.

Definition at line 90 of file ScannerHelpers.cc.

90 { cuts_.resize(1); }

◆ 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.

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 }

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

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

◆ 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.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, get, compare::hist, and getGTfromDQMFile::obj.

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

◆ 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.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, get, compare::hist, and getGTfromDQMFile::obj.

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

◆ 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.

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 }

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

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

◆ 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.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, get, compare::hist, and getGTfromDQMFile::obj.

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

◆ numberOfExpressions()

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

Number of valid expressions.

Definition at line 57 of file ScannerHelpers.h.

57 { return exprs_.size(); }

References exprs_.

◆ numberOfExtraCuts()

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

Number of extra cuts.

Definition at line 68 of file ScannerHelpers.h.

68 { return cuts_.size() - 1; }

References cuts_.

◆ 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.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, gather_cfg::cout, cppFunctionSkipper::exception, get, getGTfromDQMFile::obj, runTheMatrix::ret, mps_setup::stdout, and heppy_batch::val.

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

◆ setCut()

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

◆ setIgnoreExceptions()

void helper::ScannerBase::setIgnoreExceptions ( bool  ignoreThem)
inline

◆ 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.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, get, 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().

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.

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
helper::ScannerBase::objType_
edm::TypeWithDict objType_
Definition: ScannerHelpers.h:103
TkAlMuonSelectors_cfi.cut
cut
Definition: TkAlMuonSelectors_cfi.py:5
edm::ObjectWithDict
Definition: ObjectWithDict.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
helper::ScannerBase::cuts_
std::vector< reco::parser::SelectorPtr > cuts_
The first one is the default cut, the others are the extra ones.
Definition: ScannerHelpers.h:107
compare.hist
hist
Definition: compare.py:376
helper::Parser::makeSelector
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)
Definition: ScannerHelpers.cc:25
helper::Parser::makeExpression
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)
Definition: ScannerHelpers.cc:8
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
electrons_cff.objType
objType
Definition: electrons_cff.py:491
mps_setup.stdout
stdout
Definition: mps_setup.py:250
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
helper::ScannerBase::ignoreExceptions_
bool ignoreExceptions_
See setIgnoreExceptions to find out what this means.
Definition: ScannerHelpers.h:110
get
#define get
heppy_batch.val
val
Definition: heppy_batch.py:351
jets_cff.expr
expr
Definition: jets_cff.py:449
relativeConstraints.value
value
Definition: relativeConstraints.py:53
helper::ScannerBase::exprs_
std::vector< reco::parser::ExpressionPtr > exprs_
Definition: ScannerHelpers.h:104