CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions
helper::Parser Class Reference

#include <ScannerHelpers.h>

Public Member Functions

 Parser ()
 Empty constructor, necessary for Root, useless. More...
 

Static Public Member Functions

static edm::TypeWithDict elementType (const edm::TypeWithDict &wrapperType)
 Perform the type deduction form edm::Wrapper<C> to C::value_type and resolves typedefs. More...
 
static double eval (const reco::parser::ExpressionPtr &sel, const edm::TypeWithDict type, const void *obj)
 Make a edm::ObjectWithDict(type, obj) and pass it to the expression. More...
 
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) More...
 
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) More...
 
static bool test (const reco::parser::SelectorPtr &sel, const edm::TypeWithDict type, const void *obj)
 Make a edm::ObjectWithDict(type, obj) and pass it to the selector. More...
 

Detailed Description

Class helper::Parser has collection of useful static methods related to StringParser that can be exported to CINT via dictionaries. It's mosly meant to be used through the helper::ScannerBase class.

Definition at line 23 of file ScannerHelpers.h.

Constructor & Destructor Documentation

◆ Parser()

helper::Parser::Parser ( )
inline

Empty constructor, necessary for Root, useless.

Definition at line 26 of file ScannerHelpers.h.

26 {}

Member Function Documentation

◆ elementType()

edm::TypeWithDict helper::Parser::elementType ( const edm::TypeWithDict wrapperType)
static

Perform the type deduction form edm::Wrapper<C> to C::value_type and resolves typedefs.

Definition at line 42 of file ScannerHelpers.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, universalConfigTemplate::collection, edm::TypeWithDict::name(), and edm::TypeWithDict::templateArgumentAt().

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

42  {
44  // now search for value_type
45  edm::TypeWithDict objtype = collection.nestedType("value_type");
46  if (bool(objtype)) {
47  return objtype;
48  }
49  std::cerr << "Can't get a type out of " << wrapperType.name() << std::endl;
50  return edm::TypeWithDict();
51 }
TypeWithDict templateArgumentAt(size_t index) const
std::string name() const

◆ eval()

double helper::Parser::eval ( const reco::parser::ExpressionPtr sel,
const edm::TypeWithDict  type,
const void *  obj 
)
static

Make a edm::ObjectWithDict(type, obj) and pass it to the expression.

Definition at line 60 of file ScannerHelpers.cc.

References jetsAK8_cff::expr, and getGTfromDQMFile::obj.

60  {
61  if (expr.get() == nullptr)
62  return 0;
63  edm::ObjectWithDict obj(type, const_cast<void *>(ptr));
64  return expr->value(obj);
65 }

◆ makeExpression()

reco::parser::ExpressionPtr helper::Parser::makeExpression ( const std::string &  expr,
const edm::TypeWithDict type 
)
static

Parse an expression for a given object type (using lazy parsing when resolving methods)

NOTA BENE: <0> for cuts, <1> for expresions (why? boh!)

Definition at line 8 of file ScannerHelpers.cc.

References reco::parser::baseExceptionWhat(), EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, MillePedeFileConverter_cfg::e, jetsAK8_cff::expr, parse(), and runTheMatrix::ret.

Referenced by helper::ScannerBase::addExpression().

8  {
10 
11  using namespace boost::spirit::classic;
12  reco::parser::Grammar grammar(ret, type, true);
13  const char *startingFrom = expr.c_str();
14  try {
15  parse(startingFrom,
16  grammar.use_parser<1>() >> end_p,
17  space_p);
18  } catch (reco::parser::BaseException &e) {
19  std::cerr << "Expression parser error:" << reco::parser::baseExceptionWhat(e) << " (char " << e.where - startingFrom
20  << ")" << std::endl;
21  }
22  return ret;
23 }
vector< string > parse(string line, const string &delimiter)
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:33
ret
prodAgent to be discontinued
std::shared_ptr< ExpressionBase > ExpressionPtr
const char * baseExceptionWhat(const BaseException &e)
returns the appropriate &#39;what&#39; message for the exception
Definition: Exception.h:36

◆ makeSelector()

reco::parser::SelectorPtr helper::Parser::makeSelector ( const std::string &  expr,
const edm::TypeWithDict type 
)
static

Parse an expression for a given object type (using lazy parsing when resolving methods)

NOTA BENE: <0> for cuts, <1> for expresions (why? boh!)

Definition at line 25 of file ScannerHelpers.cc.

References reco::parser::baseExceptionWhat(), EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, MillePedeFileConverter_cfg::e, jetsAK8_cff::expr, parse(), and runTheMatrix::ret.

Referenced by helper::ScannerBase::addExtraCut(), and helper::ScannerBase::setCut().

25  {
27 
28  using namespace boost::spirit::classic;
29  reco::parser::Grammar grammar(ret, type, true);
30  const char *startingFrom = expr.c_str();
31  try {
32  parse(startingFrom,
33  grammar.use_parser<0>() >> end_p,
34  space_p);
35  } catch (reco::parser::BaseException &e) {
36  std::cerr << "Selector parser error:" << reco::parser::baseExceptionWhat(e) << " (char " << e.where - startingFrom
37  << ")" << std::endl;
38  }
39  return ret;
40 }
vector< string > parse(string line, const string &delimiter)
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:33
ret
prodAgent to be discontinued
const char * baseExceptionWhat(const BaseException &e)
returns the appropriate &#39;what&#39; message for the exception
Definition: Exception.h:36
std::shared_ptr< SelectorBase > SelectorPtr
Definition: SelectorPtr.h:18

◆ test()

bool helper::Parser::test ( const reco::parser::SelectorPtr sel,
const edm::TypeWithDict  type,
const void *  obj 
)
static

Make a edm::ObjectWithDict(type, obj) and pass it to the selector.

Definition at line 53 of file ScannerHelpers.cc.

References getGTfromDQMFile::obj, and EgammaValidation_Wenu_cff::sel.

Referenced by edmIntegrityCheck.IntegrityCheck::report(), and edmIntegrityCheck.IntegrityCheck::structured().

53  {
54  if (sel.get() == nullptr)
55  return false;
56  edm::ObjectWithDict obj(type, const_cast<void *>(ptr));
57  return (*sel)(obj);
58 }