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 | 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 edm::ObjectWithDict &o) const
 
 ~ExpressionVar ()
 
- Public Member Functions inherited from reco::parser::ExpressionBase
virtual ~ExpressionBase ()
 

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< MethodInvokermethods_
 
std::vector< bool > needsDestructor_
 
std::vector< edm::ObjectWithDictobjects_
 
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 11 of file ExpressionVar.cc.

References initObjects_().

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

Definition at line 21 of file ExpressionVar.cc.

References delStorage(), and objects_.

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

Definition at line 16 of file ExpressionVar.cc.

References initObjects_().

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

Member Function Documentation

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(), edm::TypeWithDict::deallocate(), edm::TypeWithDict::isPointer(), edm::TypeWithDict::isReference(), AlCaHLTBitMon_ParallelJobs::p, and edm::ObjectWithDict::typeOf().

Referenced by ~ExpressionVar(), and reco::parser::SingleInvoker::~SingleInvoker().

29  {
30  if (obj.address() != 0) {
31  if (obj.typeOf().isPointer() || obj.typeOf().isReference()) {
32  // just delete a void *, as that's what it was
33  void **p = static_cast<void **>(obj.address());
34  delete p;
35  } else {
36  //std::cout << "Calling Destruct on a " << obj.typeOf().qualifiedName() << std::endl;
37  obj.typeOf().deallocate(obj.address());
38  }
39  }
40 }
void * address() const
TypeWithDict const & typeOf() const
bool isReference() const
bool isPointer() const
void deallocate(void *obj) const
Definition: TypeWithDict.h:155
void ExpressionVar::initObjects_ ( )
private

Definition at line 42 of file ExpressionVar.cc.

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

Referenced by ExpressionVar().

42  {
43  objects_.resize(methods_.size());
44  std::vector<MethodInvoker>::const_iterator it = methods_.begin(), ed = methods_.end();
45  std::vector<edm::ObjectWithDict>::iterator itobj = objects_.begin();
46  for (; it != ed; ++it, ++itobj) {
47  if(it->isFunction()) {
48  edm::TypeWithDict retType = it->method().finalReturnType();
49  needsDestructor_.push_back(makeStorage(*itobj, retType));
50  } else {
51  *itobj = edm::ObjectWithDict();
52  needsDestructor_.push_back(false);
53  }
54  }
55 }
static bool makeStorage(edm::ObjectWithDict &obj, const edm::TypeWithDict &retType)
std::vector< bool > needsDestructor_
Definition: ExpressionVar.h:45
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:43
std::vector< edm::ObjectWithDict > objects_
Definition: ExpressionVar.h:44
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, PFRecoTauDiscriminationAgainstElectronMVA3GBR_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().

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

58  {
59  bool ret = false;
60  static const edm::TypeWithDict tVoid(edm::TypeWithDict::byName("void"));
61  if (retType == tVoid) {
62  obj = edm::ObjectWithDict::byType(tVoid);
63  } else if (retType.isPointer() || retType.isReference()) {
64  // in this case, I have to allocate a void *, not an object!
65  obj = edm::ObjectWithDict(retType, new void *);
66  } else {
67  obj = edm::ObjectWithDict(retType, retType.allocate());
68  ret = retType.isClass();
69  //std::cout << "ExpressionVar: reserved memory at " << obj.address() << " for a " << retType.qualifiedName() << " returned by " << member.name() << std::endl;
70  }
71  return ret;
72 }
static ObjectWithDict byType(TypeWithDict const &type)
static TypeWithDict byName(std::string const &className)
bool isClass() const
void * allocate() const
Definition: TypeWithDict.h:151
bool isReference() const
bool isPointer() const
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, PFRecoTauDiscriminationAgainstElectronMVA3GBR_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().

115  {
116  using namespace method;
117  void * addr = obj.address();
118  double ret = 0;
119  switch(type) {
120  case(doubleType) : ret = * static_cast<double *>(addr); break;
121  case(floatType ) : ret = * static_cast<float *>(addr); break;
122  case(intType ) : ret = * static_cast<int *>(addr); break;
123  case(uIntType ) : ret = * static_cast<unsigned int *>(addr); break;
124  case(shortType ) : ret = * static_cast<short *>(addr); break;
125  case(uShortType) : ret = * static_cast<unsigned short *>(addr); break;
126  case(longType ) : ret = * static_cast<long *>(addr); break;
127  case(uLongType ) : ret = * static_cast<unsigned long *>(addr); break;
128  case(charType ) : ret = * static_cast<char *>(addr); break;
129  case(uCharType ) : ret = * static_cast<unsigned char *>(addr); break;
130  case(boolType ) : ret = * static_cast<bool *>(addr); break;
131  case(enumType ) : ret = * static_cast<int *>(addr); break;
132  default:
133  assert(false);
134  };
135  return ret;
136 }
type
Definition: HCALResponse.h:21
void * address() const
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_.

Referenced by Types.int32::__nonzero__(), Types.uint32::__nonzero__(), Types.int64::__nonzero__(), Types.uint64::__nonzero__(), Types.double::__nonzero__(), Types.bool::__nonzero__(), Types.string::__nonzero__(), average.Average::average(), 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().

98  {
100  std::vector<MethodInvoker>::const_iterator itm, end = methods_.end();
101  std::vector<edm::ObjectWithDict>::iterator ito;
102  for(itm = methods_.begin(), ito = objects_.begin(); itm != end; ++itm, ++ito) {
103  ro = itm->invoke(ro, *ito);
104  }
105  double ret = objToDouble(ro, retType_);
106  std::vector<edm::ObjectWithDict>::reverse_iterator rito, rend = objects_.rend();;
107  std::vector<bool>::const_reverse_iterator ritb;
108  for(rito = objects_.rbegin(), ritb = needsDestructor_.rbegin(); rito != rend; ++rito, ++ritb) {
109  if (*ritb) rito->typeOf().destruct(rito->address(), false);
110  }
111  return ret;
112 }
std::vector< bool > needsDestructor_
Definition: ExpressionVar.h:45
static double objToDouble(const edm::ObjectWithDict &obj, method::TypeCode type)
#define end
Definition: vmac.h:37
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:43
std::vector< edm::ObjectWithDict > objects_
Definition: ExpressionVar.h:44
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<edm::ObjectWithDict> 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().