CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes

reco::parser::ExpressionVar Struct Reference

Evaluate an object's method or datamember (or chain of them) to get a number. More...

#include <ExpressionVar.h>

Inheritance diagram for reco::parser::ExpressionVar:
reco::parser::ExpressionBase

List of all members.

Public Member Functions

 ExpressionVar (const std::vector< MethodInvoker > &methods, method::TypeCode retType)
 ExpressionVar (const ExpressionVar &var)
virtual double value (const Reflex::Object &o) const
 ~ExpressionVar ()

Static Public Member Functions

static void delStorage (Reflex::Object &obj)
static bool isValidReturnType (method::TypeCode)
static bool makeStorage (Reflex::Object &obj, const Reflex::Member &member)
static double objToDouble (const Reflex::Object &obj, method::TypeCode type)

Private Member Functions

void initObjects_ ()

Static Private Member Functions

static void trueDelete (Reflex::Object &o)

Private Attributes

std::vector< MethodInvokermethods_
std::vector< bool > needsDestructor_
std::vector< Reflex::Object > objects_
method::TypeCode retType_

Detailed Description

Evaluate an object's method or datamember (or chain of them) to get a number.

Definition at line 21 of file ExpressionVar.h.


Constructor & Destructor Documentation

reco::parser::ExpressionVar::ExpressionVar ( const std::vector< MethodInvoker > &  methods,
method::TypeCode  retType 
)
ExpressionVar::~ExpressionVar ( )

Definition at line 20 of file ExpressionVar.cc.

References delStorage(), and objects_.

                              {
    for(std::vector<Reflex::Object>::iterator it = objects_.begin(); it != objects_.end(); ++it) {
        delStorage(*it);
    }
    objects_.clear();
}
ExpressionVar::ExpressionVar ( const ExpressionVar var)

Definition at line 15 of file ExpressionVar.cc.

References initObjects_().

                                                       :
  methods_(other.methods_), retType_(other.retType_) { 
    initObjects_();
}

Member Function Documentation

void ExpressionVar::delStorage ( Reflex::Object &  obj) [static]

delete an objecty, if needed this method is used also from the LazyInvoker code

Definition at line 28 of file ExpressionVar.cc.

References AlCaHLTBitMon_ParallelJobs::p.

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().Name(QUALIFIED) << std::endl;
            obj.TypeOf().Deallocate(obj.Address());
        }
    }
}
void ExpressionVar::initObjects_ ( ) [private]

Definition at line 41 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<Reflex::Object>::iterator itobj = objects_.begin();
    for (; it != ed; ++it, ++itobj) {
        needsDestructor_.push_back(makeStorage(*itobj, it->method()));
    }
}
bool ExpressionVar::isValidReturnType ( method::TypeCode  retType) [static]

Definition at line 75 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 ( Reflex::Object &  obj,
const Reflex::Member &  member 
) [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 51 of file ExpressionVar.cc.

References run_regression::ret.

Referenced by initObjects_(), and reco::parser::SingleInvoker::SingleInvoker().

                                                                        {
    bool ret = false;
    static Type tVoid = Type::ByName("void");
    if (member.IsFunctionMember()) {
        Reflex::Type retType = member.TypeOf().ReturnType();
        //remove any typedefs if any. If we do not do this it appears that we get a memory leak
        // because typedefs do not have 'destructors'
        retType = retType.FinalType();
        if (retType == tVoid) {
            obj = Reflex::Object(tVoid);
        } else if (retType.IsPointer() || retType.IsReference()) {
            // in this case, I have to allocate a void *, not an object!
            obj = Reflex::Object(retType, new void *);
        } else {
            obj = Reflex::Object(retType, retType.Allocate());
            ret = retType.IsClass();
            //std::cout << "ExpressionVar: reserved memory at "  << obj.Address() << " for a " << retType.Name(QUALIFIED) << " returned by " << member.Name() << std::endl;
        }
    } else { // no alloc, we don't need it
        obj = Reflex::Object();
    }
    return ret;
}
double ExpressionVar::objToDouble ( const Reflex::Object &  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 116 of file ExpressionVar.cc.

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

                                                                       {
  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;
}
void ExpressionVar::trueDelete ( Reflex::Object &  o) [static, private]

Definition at line 139 of file ExpressionVar.cc.

References match().

                                                 {
     static std::map<void *, Reflex::NewDelFunctions *> deleters_;
     void * reflexTypeId = obj.TypeOf().Id();
     std::map<void *, Reflex::NewDelFunctions *>::iterator match = deleters_.find(reflexTypeId);
     if (match == deleters_.end()) {
         Reflex::NewDelFunctions *ptr;
         Reflex::Object newDel(Reflex::Type::ByTypeInfo(typeid(ptr)), &ptr);
         obj.Invoke("__getNewDelFunctions", &newDel);
         match = deleters_.insert(std::make_pair(reflexTypeId, ptr)).first;   
     }
     (*match->second->fDelete)(obj.Address());
}
virtual double reco::parser::ExpressionVar::value ( const Reflex::Object &  o) const [virtual]

Member Data Documentation

Definition at line 43 of file ExpressionVar.h.

Referenced by initObjects_().

std::vector<bool> reco::parser::ExpressionVar::needsDestructor_ [mutable, private]

Definition at line 45 of file ExpressionVar.h.

Referenced by initObjects_().

std::vector<Reflex::Object> reco::parser::ExpressionVar::objects_ [mutable, private]

Definition at line 44 of file ExpressionVar.h.

Referenced by initObjects_(), and ~ExpressionVar().

Definition at line 46 of file ExpressionVar.h.