CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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

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 ()
 
- Public Member Functions inherited from reco::parser::ExpressionBase
virtual ~ExpressionBase ()
 

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

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

Definition at line 10 of file ExpressionVar.cc.

References initObjects_().

10  :
11  methods_(methods), retType_(retType) {
12  initObjects_();
13 }
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:43
method::TypeCode retType_
Definition: ExpressionVar.h:46
ExpressionVar::~ExpressionVar ( )

Definition at line 20 of file ExpressionVar.cc.

References delStorage(), and objects_.

20  {
21  for(std::vector<Reflex::Object>::iterator it = objects_.begin(); it != objects_.end(); ++it) {
22  delStorage(*it);
23  }
24  objects_.clear();
25 }
static void delStorage(Reflex::Object &obj)
std::vector< Reflex::Object > objects_
Definition: ExpressionVar.h:44
ExpressionVar::ExpressionVar ( const ExpressionVar var)

Definition at line 15 of file ExpressionVar.cc.

References initObjects_().

15  :
16  methods_(other.methods_), retType_(other.retType_) {
17  initObjects_();
18 }
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:43
method::TypeCode retType_
Definition: ExpressionVar.h:46

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

28  {
29  if (obj.Address() != 0) {
30  if (obj.TypeOf().IsPointer() || obj.TypeOf().IsReference()) {
31  // just delete a void *, as that's what it was
32  void **p = static_cast<void **>(obj.Address());
33  delete p;
34  } else {
35  //std::cout << "Calling Destruct on a " << obj.TypeOf().Name(QUALIFIED) << std::endl;
36  obj.TypeOf().Deallocate(obj.Address());
37  }
38  }
39 }
void ExpressionVar::initObjects_ ( )
private

Definition at line 41 of file ExpressionVar.cc.

References makeStorage(), methods_, needsDestructor_, and objects_.

Referenced by ExpressionVar().

41  {
42  objects_.resize(methods_.size());
43  std::vector<MethodInvoker>::const_iterator it = methods_.begin(), ed = methods_.end();
44  std::vector<Reflex::Object>::iterator itobj = objects_.begin();
45  for (; it != ed; ++it, ++itobj) {
46  needsDestructor_.push_back(makeStorage(*itobj, it->method()));
47  }
48 }
std::vector< bool > needsDestructor_
Definition: ExpressionVar.h:45
std::vector< Reflex::Object > objects_
Definition: ExpressionVar.h:44
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:43
static bool makeStorage(Reflex::Object &obj, const Reflex::Member &member)
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().

76 {
77  using namespace method;
78  bool ret = false;
79  switch(retType) {
80  case(doubleType) : ret = true; break;
81  case(floatType ) : ret = true; break;
82  case(intType ) : ret = true; break;
83  case(uIntType ) : ret = true; break;
84  case(shortType ) : ret = true; break;
85  case(uShortType) : ret = true; break;
86  case(longType ) : ret = true; break;
87  case(uLongType ) : ret = true; break;
88  case(charType ) : ret = true; break;
89  case(uCharType ) : ret = true; break;
90  case(boolType ) : ret = true; break;
91  case(enumType ) : ret = true; break;
92  case(invalid):
93  default:
94  break;
95  }
96  return ret;
97 }
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().

51  {
52  bool ret = false;
53  static Type tVoid = Type::ByName("void");
54  if (member.IsFunctionMember()) {
55  Reflex::Type retType = member.TypeOf().ReturnType();
56  //remove any typedefs if any. If we do not do this it appears that we get a memory leak
57  // because typedefs do not have 'destructors'
58  retType = retType.FinalType();
59  if (retType == tVoid) {
60  obj = Reflex::Object(tVoid);
61  } else if (retType.IsPointer() || retType.IsReference()) {
62  // in this case, I have to allocate a void *, not an object!
63  obj = Reflex::Object(retType, new void *);
64  } else {
65  obj = Reflex::Object(retType, retType.Allocate());
66  ret = retType.IsClass();
67  //std::cout << "ExpressionVar: reserved memory at " << obj.Address() << " for a " << retType.Name(QUALIFIED) << " returned by " << member.Name() << std::endl;
68  }
69  } else { // no alloc, we don't need it
70  obj = Reflex::Object();
71  }
72  return ret;
73 }
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(), and value().

116  {
117  using namespace method;
118  void * addr = obj.Address();
119  double ret = 0;
120  switch(type) {
121  case(doubleType) : ret = * static_cast<double *>(addr); break;
122  case(floatType ) : ret = * static_cast<float *>(addr); break;
123  case(intType ) : ret = * static_cast<int *>(addr); break;
124  case(uIntType ) : ret = * static_cast<unsigned int *>(addr); break;
125  case(shortType ) : ret = * static_cast<short *>(addr); break;
126  case(uShortType) : ret = * static_cast<unsigned short *>(addr); break;
127  case(longType ) : ret = * static_cast<long *>(addr); break;
128  case(uLongType ) : ret = * static_cast<unsigned long *>(addr); break;
129  case(charType ) : ret = * static_cast<char *>(addr); break;
130  case(uCharType ) : ret = * static_cast<unsigned char *>(addr); break;
131  case(boolType ) : ret = * static_cast<bool *>(addr); break;
132  case(enumType ) : ret = * static_cast<int *>(addr); break;
133  default:
134  assert(false);
135  };
136  return ret;
137 }
type
Definition: HCALResponse.h:22
void ExpressionVar::trueDelete ( Reflex::Object &  o)
staticprivate

Definition at line 139 of file ExpressionVar.cc.

References match().

139  {
140  static std::map<void *, Reflex::NewDelFunctions *> deleters_;
141  void * reflexTypeId = obj.TypeOf().Id();
142  std::map<void *, Reflex::NewDelFunctions *>::iterator match = deleters_.find(reflexTypeId);
143  if (match == deleters_.end()) {
144  Reflex::NewDelFunctions *ptr;
145  Reflex::Object newDel(Reflex::Type::ByTypeInfo(typeid(ptr)), &ptr);
146  obj.Invoke("__getNewDelFunctions", &newDel);
147  match = deleters_.insert(std::make_pair(reflexTypeId, ptr)).first;
148  }
149  (*match->second->fDelete)(obj.Address());
150 }
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
double ExpressionVar::value ( const Reflex::Object &  o) const
virtual

Implements reco::parser::ExpressionBase.

Definition at line 99 of file ExpressionVar.cc.

References end, methods_, needsDestructor_, python.connectstrParser::o, objects_, objToDouble(), run_regression::ret, and retType_.

Referenced by Vispa.Views.PropertyView.FileProperty::buttonClicked(), Types.string::configValue(), Types.FileInPath::configValue(), Mixins.UsingBlock::dumpPython(), Types.int32::insertInto(), Types.uint32::insertInto(), Types.int64::insertInto(), Types.uint64::insertInto(), Mixins.UsingBlock::insertInto(), Types.double::insertInto(), Types.bool::insertInto(), Types.string::insertInto(), Types.FileInPath::insertInto(), Types.vint32::insertInto(), Types.vuint32::insertInto(), Types.vint64::insertInto(), Types.vuint64::insertInto(), Types.vdouble::insertInto(), Types.vbool::insertInto(), Types.vstring::insertInto(), and Vispa.Views.PropertyView.FileProperty::labelDoubleClicked().

99  {
100  Object ro = o;
101  std::vector<MethodInvoker>::const_iterator itm, end = methods_.end();
102  std::vector<Reflex::Object>::iterator ito;
103  for(itm = methods_.begin(), ito = objects_.begin(); itm != end; ++itm, ++ito) {
104  ro = itm->invoke(ro, *ito);
105  }
106  double ret = objToDouble(ro, retType_);
107  std::vector<Reflex::Object>::reverse_iterator rito, rend = objects_.rend();;
108  std::vector<bool>::const_reverse_iterator ritb;
109  for(rito = objects_.rbegin(), ritb = needsDestructor_.rbegin(); rito != rend; ++rito, ++ritb) {
110  if (*ritb) rito->TypeOf().Destruct(rito->Address(), false);
111  }
112  return ret;
113 }
std::vector< bool > needsDestructor_
Definition: ExpressionVar.h:45
std::vector< Reflex::Object > objects_
Definition: ExpressionVar.h:44
#define end
Definition: vmac.h:38
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:43
static double objToDouble(const Reflex::Object &obj, method::TypeCode type)
method::TypeCode retType_
Definition: ExpressionVar.h:46

Member Data Documentation

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_
mutableprivate

Definition at line 45 of file ExpressionVar.h.

Referenced by initObjects_(), and value().

std::vector<Reflex::Object> reco::parser::ExpressionVar::objects_
mutableprivate

Definition at line 44 of file ExpressionVar.h.

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

method::TypeCode reco::parser::ExpressionVar::retType_
private

Definition at line 46 of file ExpressionVar.h.

Referenced by value().