Evaluate an object's method or datamember (or chain of them) to get a number. More...
#include <ExpressionVar.h>
Public Member Functions | |
ExpressionVar (const std::vector< MethodInvoker > &methods, method::TypeCode retType) | |
ExpressionVar (const ExpressionVar &var) | |
virtual double | value (const edm::ObjectWithDict &o) const |
~ExpressionVar () | |
Static Public Member Functions | |
static void | delStorage (edm::ObjectWithDict &obj) |
static bool | isValidReturnType (method::TypeCode) |
static bool | makeStorage (edm::ObjectWithDict &obj, const edm::TypeWithDict &retType) |
static double | objToDouble (const edm::ObjectWithDict &obj, method::TypeCode type) |
Private Member Functions | |
void | initObjects_ () |
Private Attributes | |
std::vector< MethodInvoker > | methods_ |
std::vector< bool > | needsDestructor_ |
std::vector< edm::ObjectWithDict > | objects_ |
method::TypeCode | retType_ |
Evaluate an object's method or datamember (or chain of them) to get a number.
Definition at line 21 of file ExpressionVar.h.
reco::parser::ExpressionVar::ExpressionVar | ( | const std::vector< MethodInvoker > & | methods, |
method::TypeCode | retType | ||
) |
ExpressionVar::~ExpressionVar | ( | ) |
Definition at line 21 of file ExpressionVar.cc.
References delStorage(), and objects_.
{ for(std::vector<edm::ObjectWithDict>::iterator it = objects_.begin(); it != objects_.end(); ++it) { delStorage(*it); } objects_.clear(); }
ExpressionVar::ExpressionVar | ( | const ExpressionVar & | var | ) |
Definition at line 16 of file ExpressionVar.cc.
References initObjects_().
: methods_(other.methods_), retType_(other.retType_) { initObjects_(); }
void ExpressionVar::delStorage | ( | edm::ObjectWithDict & | obj | ) | [static] |
delete an objecty, if needed this method is used also from the LazyInvoker code
Definition at line 29 of file ExpressionVar.cc.
References edm::ObjectWithDict::address(), AlCaHLTBitMon_ParallelJobs::p, and edm::ObjectWithDict::typeOf().
Referenced by ~ExpressionVar(), and reco::parser::SingleInvoker::~SingleInvoker().
{ if (obj.address() != 0) { if (obj.typeOf().isPointer() || obj.typeOf().isReference()) { // just delete a void *, as that's what it was void **p = static_cast<void **>(obj.address()); delete p; } else { //std::cout << "Calling Destruct on a " << obj.typeOf().qualifiedName() << std::endl; obj.typeOf().deallocate(obj.address()); } } }
void ExpressionVar::initObjects_ | ( | ) | [private] |
Definition at line 42 of file ExpressionVar.cc.
References makeStorage(), methods_, needsDestructor_, and objects_.
Referenced by ExpressionVar().
{ objects_.resize(methods_.size()); std::vector<MethodInvoker>::const_iterator it = methods_.begin(), ed = methods_.end(); std::vector<edm::ObjectWithDict>::iterator itobj = objects_.begin(); for (; it != ed; ++it, ++itobj) { if(it->isFunction()) { edm::TypeWithDict retType = it->method().finalReturnType(); needsDestructor_.push_back(makeStorage(*itobj, retType)); } else { *itobj = edm::ObjectWithDict(); needsDestructor_.push_back(false); } } }
bool ExpressionVar::isValidReturnType | ( | method::TypeCode | retType | ) | [static] |
Definition at line 74 of file ExpressionVar.cc.
References reco::method::boolType, reco::method::charType, reco::method::doubleType, reco::method::enumType, reco::method::floatType, reco::method::intType, align::invalid, reco::method::longType, PFRecoTauDiscriminationAgainstElectronMVA2_cfi::method, run_regression::ret, reco::method::shortType, reco::method::uCharType, reco::method::uIntType, reco::method::uLongType, and reco::method::uShortType.
Referenced by reco::parser::ExpressionVarSetter::push(), and reco::parser::SingleInvoker::retToDouble().
{ using namespace method; bool ret = false; switch(retType) { case(doubleType) : ret = true; break; case(floatType ) : ret = true; break; case(intType ) : ret = true; break; case(uIntType ) : ret = true; break; case(shortType ) : ret = true; break; case(uShortType) : ret = true; break; case(longType ) : ret = true; break; case(uLongType ) : ret = true; break; case(charType ) : ret = true; break; case(uCharType ) : ret = true; break; case(boolType ) : ret = true; break; case(enumType ) : ret = true; break; case(invalid): default: break; } return ret; }
bool ExpressionVar::makeStorage | ( | edm::ObjectWithDict & | obj, |
const edm::TypeWithDict & | retType | ||
) | [static] |
allocate an object to hold the result of a given member (if needed) this method is used also from the LazyInvoker code returns true if objects returned from this will require a destructor
Definition at line 58 of file ExpressionVar.cc.
References edm::TypeWithDict::allocate(), edm::TypeWithDict::byName(), edm::ObjectWithDict::byType(), edm::TypeWithDict::isClass(), edm::TypeWithDict::isPointer(), edm::TypeWithDict::isReference(), and run_regression::ret.
Referenced by initObjects_(), and reco::parser::SingleInvoker::SingleInvoker().
{ bool ret = false; static edm::TypeWithDict tVoid(edm::TypeWithDict::byName("void")); if (retType == tVoid) { obj = edm::ObjectWithDict::byType(tVoid); } else if (retType.isPointer() || retType.isReference()) { // in this case, I have to allocate a void *, not an object! obj = edm::ObjectWithDict(retType, new void *); } else { obj = edm::ObjectWithDict(retType, retType.allocate()); ret = retType.isClass(); //std::cout << "ExpressionVar: reserved memory at " << obj.address() << " for a " << retType.qualifiedName() << " returned by " << member.name() << std::endl; } return ret; }
double ExpressionVar::objToDouble | ( | const edm::ObjectWithDict & | obj, |
method::TypeCode | type | ||
) | [static] |
performs the needed conversion from void * to double this method is used also from the ExpressionLazyVar code
Definition at line 115 of file ExpressionVar.cc.
References edm::ObjectWithDict::address(), reco::method::boolType, reco::method::charType, reco::method::doubleType, reco::method::enumType, reco::method::floatType, reco::method::intType, reco::method::longType, PFRecoTauDiscriminationAgainstElectronMVA2_cfi::method, run_regression::ret, reco::method::shortType, reco::method::uCharType, reco::method::uIntType, reco::method::uLongType, and reco::method::uShortType.
Referenced by reco::parser::SingleInvoker::retToDouble(), and value().
{ using namespace method; void * addr = obj.address(); double ret = 0; switch(type) { case(doubleType) : ret = * static_cast<double *>(addr); break; case(floatType ) : ret = * static_cast<float *>(addr); break; case(intType ) : ret = * static_cast<int *>(addr); break; case(uIntType ) : ret = * static_cast<unsigned int *>(addr); break; case(shortType ) : ret = * static_cast<short *>(addr); break; case(uShortType) : ret = * static_cast<unsigned short *>(addr); break; case(longType ) : ret = * static_cast<long *>(addr); break; case(uLongType ) : ret = * static_cast<unsigned long *>(addr); break; case(charType ) : ret = * static_cast<char *>(addr); break; case(uCharType ) : ret = * static_cast<unsigned char *>(addr); break; case(boolType ) : ret = * static_cast<bool *>(addr); break; case(enumType ) : ret = * static_cast<int *>(addr); break; default: assert(false); }; return ret; }
double ExpressionVar::value | ( | const edm::ObjectWithDict & | o | ) | const [virtual] |
Implements reco::parser::ExpressionBase.
Definition at line 98 of file ExpressionVar.cc.
References end, methods_, needsDestructor_, python::connectstrParser::o, objects_, objToDouble(), run_regression::ret, and retType_.
{ edm::ObjectWithDict ro = o; std::vector<MethodInvoker>::const_iterator itm, end = methods_.end(); std::vector<edm::ObjectWithDict>::iterator ito; for(itm = methods_.begin(), ito = objects_.begin(); itm != end; ++itm, ++ito) { ro = itm->invoke(ro, *ito); } double ret = objToDouble(ro, retType_); std::vector<edm::ObjectWithDict>::reverse_iterator rito, rend = objects_.rend();; std::vector<bool>::const_reverse_iterator ritb; for(rito = objects_.rbegin(), ritb = needsDestructor_.rbegin(); rito != rend; ++rito, ++ritb) { if (*ritb) rito->typeOf().destruct(rito->address(), false); } return ret; }
std::vector<MethodInvoker> reco::parser::ExpressionVar::methods_ [private] |
Definition at line 43 of file ExpressionVar.h.
Referenced by initObjects_(), and value().
std::vector<bool> reco::parser::ExpressionVar::needsDestructor_ [mutable, private] |
Definition at line 45 of file ExpressionVar.h.
Referenced by initObjects_(), and value().
std::vector<edm::ObjectWithDict> reco::parser::ExpressionVar::objects_ [mutable, private] |
Definition at line 44 of file ExpressionVar.h.
Referenced by initObjects_(), value(), and ~ExpressionVar().
Definition at line 46 of file ExpressionVar.h.
Referenced by value().