CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions

helper::Parser Class Reference

#include <ScannerHelpers.h>

List of all members.

Public Member Functions

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

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

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


Constructor & Destructor Documentation

helper::Parser::Parser ( ) [inline]

Empty constructor, necessary for Root, useless.

Definition at line 27 of file ScannerHelpers.h.

{}

Member Function Documentation

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

References dtNoiseDBValidation_cfg::cerr, runEdmFileComparison::collection, edm::TypeWithDict::isTypedef(), edm::TypeWithDict::name(), edm::TypeWithDict::nestedType(), edm::Scoped, edm::TypeWithDict::templateArgumentAt(), and edm::TypeWithDict::toType().

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

                                                            {
    edm::TypeWithDict collection = wrapperType.templateArgumentAt(0);
    while (collection.isTypedef()) collection = collection.toType();
    // now search for value_type
    edm::TypeWithDict objtype = collection.nestedType("value_type");
    if(bool(objtype)) {
      while (objtype.isTypedef()) objtype = objtype.toType();
      return objtype;
    }
    std::cerr << "Can't get a type out of " << wrapperType.name(edm::TypeNameHandling::Scoped) << std::endl;
    return edm::TypeWithDict();
}
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 59 of file ScannerHelpers.cc.

References getGTfromDQMFile::obj.

                                                                                                    {
    if (expr.get() == 0) return 0;
    edm::ObjectWithDict obj(type, const_cast<void *>(ptr));
    return expr->value(obj);
}
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 9 of file ScannerHelpers.cc.

References reco::parser::baseExceptionWhat(), dtNoiseDBValidation_cfg::cerr, alignCSCRings::e, triggerExpression::parse(), and run_regression::ret.

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

                                                                               {
    reco::parser::ExpressionPtr ret;

    using namespace boost::spirit::classic;
    reco::parser::Grammar grammar(ret, type, true);
    const char* startingFrom = expr.c_str();
    try {
        parse(startingFrom, grammar.use_parser<1>() >> end_p, space_p).full; 
    } catch(reco::parser::BaseException&e){
        std::cerr << "Expression parser error:"<<reco::parser::baseExceptionWhat(e)<<" (char "<<e.where-startingFrom<<")" << std::endl;
    }
    return ret;
}
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 24 of file ScannerHelpers.cc.

References reco::parser::baseExceptionWhat(), dtNoiseDBValidation_cfg::cerr, alignCSCRings::e, triggerExpression::parse(), and run_regression::ret.

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

                                                                             {
    reco::parser::SelectorPtr ret;

    using namespace boost::spirit::classic;
    reco::parser::Grammar grammar(ret, type, true);
    const char* startingFrom = expr.c_str();
    try {
        parse(startingFrom, grammar.use_parser<0>() >> end_p, space_p).full; 
    } catch(reco::parser::BaseException&e){
        std::cerr << "Selector parser error:"<<reco::parser::baseExceptionWhat(e)<<" (char "<<e.where-startingFrom<<")" << std::endl;
    }
    return ret;
}
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.

                                                                                                 {
    if (sel.get() == 0) return false;edm::ObjectWithDict obj(type, const_cast<void *>(ptr));
    return (*sel)(obj);
}