CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
reco::parser::ExpressionVar Class 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 &)
 
double value (const edm::ObjectWithDict &) const override
 
 ~ExpressionVar () override
 
- Public Member Functions inherited from reco::parser::ExpressionBase
virtual ~ExpressionBase ()
 

Static Public Member Functions

static void delStorage (edm::ObjectWithDict &)
 
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 23 of file ExpressionVar.h.

Constructor & Destructor Documentation

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

Definition at line 31 of file ExpressionVar.cc.

References initObjects_().

33  : methods_(methods)
34  , retType_(retType)
35 {
36  initObjects_();
37 }
method::TypeCode retType_
Definition: ExpressionVar.h:28
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:25
ExpressionVar::ExpressionVar ( const ExpressionVar rhs)

Definition at line 39 of file ExpressionVar.cc.

References initObjects_().

40  : methods_(rhs.methods_)
41  , retType_(rhs.retType_)
42 {
43  initObjects_();
44 }
method::TypeCode retType_
Definition: ExpressionVar.h:28
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:25
ExpressionVar::~ExpressionVar ( )
override

Definition at line 46 of file ExpressionVar.cc.

References delStorage(), Exhume::I, and objects_.

47 {
48  for (std::vector<edm::ObjectWithDict>::iterator I = objects_.begin(),
49  E = objects_.end(); I != E; ++I) {
50  delStorage(*I);
51  }
52  objects_.clear();
53 }
std::vector< edm::ObjectWithDict > objects_
Definition: ExpressionVar.h:26
const std::complex< double > I
Definition: I.h:8
static void delStorage(edm::ObjectWithDict &)

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

57 {
58  if (!obj.address()) {
59  return;
60  }
61  if (obj.typeOf().isPointer() || obj.typeOf().isReference()) {
62  // just delete a void*, as that's what it was
63  void** p = static_cast<void**>(obj.address());
64  delete p;
65  }
66  else {
67  //std::cout << "Calling Destruct on a " <<
68  // obj.typeOf().qualifiedName() << std::endl;
69  obj.typeOf().deallocate(obj.address());
70  }
71 }
void * address() const
TypeWithDict typeOf() const
void deallocate(void *address) const
bool isReference() const
bool isPointer() const
void ExpressionVar::initObjects_ ( )
private

Definition at line 15 of file ExpressionVar.cc.

References Exhume::I.

Referenced by ExpressionVar().

16 {
17  objects_.resize(methods_.size());
18  std::vector<edm::ObjectWithDict>::iterator IO = objects_.begin();
19  for (std::vector<MethodInvoker>::const_iterator I = methods_.begin(), E = methods_.end(); I != E; ++IO, ++I) {
20  if (I->isFunction()) {
21  edm::TypeWithDict retType = I->method().finalReturnType();
22  needsDestructor_.push_back(makeStorage(*IO, retType));
23  }
24  else {
25  *IO = edm::ObjectWithDict();
26  needsDestructor_.push_back(false);
27  }
28  }
29 }
static bool makeStorage(edm::ObjectWithDict &obj, const edm::TypeWithDict &retType)
std::vector< edm::ObjectWithDict > objects_
Definition: ExpressionVar.h:26
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:25
const std::complex< double > I
Definition: I.h:8
std::vector< bool > needsDestructor_
Definition: ExpressionVar.h:27
bool ExpressionVar::isValidReturnType ( method::TypeCode  retType)
static

Definition at line 96 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, AlcaSiPixelAliHarvester0T_cff::method, 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().

97 {
98  using namespace method;
99  bool ret = false;
100  switch (retType) {
101  case (doubleType) :
102  ret = true;
103  break;
104  case (floatType) :
105  ret = true;
106  break;
107  case (intType) :
108  ret = true;
109  break;
110  case (uIntType) :
111  ret = true;
112  break;
113  case (shortType) :
114  ret = true;
115  break;
116  case (uShortType) :
117  ret = true;
118  break;
119  case (longType) :
120  ret = true;
121  break;
122  case (uLongType) :
123  ret = true;
124  break;
125  case (charType) :
126  ret = true;
127  break;
128  case (uCharType) :
129  ret = true;
130  break;
131  case (boolType) :
132  ret = true;
133  break;
134  case (enumType) :
135  ret = true;
136  break;
137  case (invalid):
138  default:
139  break;
140  }
141  return ret;
142 }
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 74 of file ExpressionVar.cc.

References edm::TypeWithDict::allocate(), edm::TypeWithDict::byName(), edm::ObjectWithDict::byType(), edm::TypeWithDict::isClass(), edm::TypeWithDict::isPointer(), and edm::TypeWithDict::isReference().

Referenced by reco::parser::SingleInvoker::SingleInvoker().

76 {
77  static const edm::TypeWithDict tVoid(edm::TypeWithDict::byName("void"));
78  bool ret = false;
79  if (retType == tVoid) {
80  obj = edm::ObjectWithDict::byType(tVoid);
81  }
82  else if (retType.isPointer() || retType.isReference()) {
83  // in this case, I have to allocate a void*, not an object!
84  obj = edm::ObjectWithDict(retType, new void*);
85  }
86  else {
87  obj = edm::ObjectWithDict(retType, retType.allocate());
88  ret = retType.isClass();
89  //std::cout << "ExpressionVar: reserved memory at " << obj.address() <<
90  // " for a " << retType.qualifiedName() << " returned by " <<
91  // member.name() << std::endl;
92  }
93  return ret;
94 }
static ObjectWithDict byType(TypeWithDict const &)
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:59
bool isClass() const
bool isReference() const
bool isPointer() const
void * allocate() 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 162 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, AlcaSiPixelAliHarvester0T_cff::method, reco::method::shortType, reco::method::uCharType, reco::method::uIntType, reco::method::uLongType, and reco::method::uShortType.

Referenced by reco::parser::SingleInvoker::retToDouble(), and value().

164 {
165  using namespace method;
166  void* addr = obj.address();
167  double ret = 0.0;
168  switch (type) {
169  case doubleType:
170  ret = *static_cast<double*>(addr);
171  break;
172  case floatType:
173  ret = *static_cast<float*>(addr);
174  break;
175  case intType:
176  ret = *static_cast<int*>(addr);
177  break;
178  case uIntType:
179  ret = *static_cast<unsigned int*>(addr);
180  break;
181  case shortType:
182  ret = *static_cast<short*>(addr);
183  break;
184  case uShortType:
185  ret = *static_cast<unsigned short*>(addr);
186  break;
187  case longType:
188  ret = *static_cast<long*>(addr);
189  break;
190  case uLongType:
191  ret = *static_cast<unsigned long*>(addr);
192  break;
193  case charType:
194  ret = *static_cast<char*>(addr);
195  break;
196  case uCharType:
197  ret = *static_cast<unsigned char*>(addr);
198  break;
199  case boolType:
200  ret = *static_cast<bool*>(addr);
201  break;
202  case enumType:
203  ret = *static_cast<int*>(addr);
204  break;
205  default:
206  //FIXME: Error not caught in production build!
207  assert(false && "objToDouble: invalid type!");
208  break;
209  };
210  return ret;
211 }
type
Definition: HCALResponse.h:21
void * address() const
double ExpressionVar::value ( const edm::ObjectWithDict obj) const
overridevirtual

Implements reco::parser::ExpressionBase.

Definition at line 144 of file ExpressionVar.cc.

References Exhume::I, methods_, needsDestructor_, objects_, objToDouble(), retType_, and heppy_batch::val.

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(), Types.double::insertInto(), Mixins.UsingBlock::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().

145 {
147  std::vector<edm::ObjectWithDict>::iterator IO = objects_.begin();
148  for (std::vector<MethodInvoker>::const_iterator I = methods_.begin(), E = methods_.end(); I != E; ++I, ++IO) {
149  val = I->invoke(val, *IO);
150  }
151  double ret = objToDouble(val, retType_);
152  std::vector<bool>::const_reverse_iterator RIB = needsDestructor_.rbegin();
153  for (std::vector<edm::ObjectWithDict>::reverse_iterator RI = objects_.rbegin(), RE = objects_.rend(); RI != RE; ++RIB, ++RI) {
154  if (*RIB) {
155  RI->destruct(false);
156  }
157  }
158  return ret;
159 }
std::vector< edm::ObjectWithDict > objects_
Definition: ExpressionVar.h:26
static double objToDouble(const edm::ObjectWithDict &obj, method::TypeCode type)
method::TypeCode retType_
Definition: ExpressionVar.h:28
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:25
const std::complex< double > I
Definition: I.h:8
std::vector< bool > needsDestructor_
Definition: ExpressionVar.h:27

Member Data Documentation

std::vector<MethodInvoker> reco::parser::ExpressionVar::methods_
private

Definition at line 25 of file ExpressionVar.h.

Referenced by value().

std::vector<bool> reco::parser::ExpressionVar::needsDestructor_
mutableprivate

Definition at line 27 of file ExpressionVar.h.

Referenced by value().

std::vector<edm::ObjectWithDict> reco::parser::ExpressionVar::objects_
mutableprivate

Definition at line 26 of file ExpressionVar.h.

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

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

Definition at line 28 of file ExpressionVar.h.

Referenced by value().