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() [1/2]

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

Definition at line 29 of file ExpressionVar.cc.

References initObjects_().

30  : methods_(methods), retType_(retType) {
31  initObjects_();
32 }
method::TypeCode retType_
Definition: ExpressionVar.h:28
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:25

◆ ExpressionVar() [2/2]

ExpressionVar::ExpressionVar ( const ExpressionVar rhs)

Definition at line 34 of file ExpressionVar.cc.

References initObjects_().

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

◆ ~ExpressionVar()

ExpressionVar::~ExpressionVar ( )
override

Definition at line 38 of file ExpressionVar.cc.

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

38  {
39  for (std::vector<edm::ObjectWithDict>::iterator I = objects_.begin(), E = objects_.end(); I != E; ++I) {
40  delStorage(*I);
41  }
42  objects_.clear();
43 }
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

◆ delStorage()

void ExpressionVar::delStorage ( edm::ObjectWithDict obj)
static

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

Definition at line 45 of file ExpressionVar.cc.

References getGTfromDQMFile::obj, and AlCaHLTBitMon_ParallelJobs::p.

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

45  {
46  if (!obj.address()) {
47  return;
48  }
49  if (obj.typeOf().isPointer() || obj.typeOf().isReference()) {
50  // just delete a void*, as that's what it was
51  void** p = static_cast<void**>(obj.address());
52  delete p;
53  } else {
54  //std::cout << "Calling Destruct on a " <<
55  // obj.typeOf().qualifiedName() << std::endl;
56  obj.typeOf().deallocate(obj.address());
57  }
58 }

◆ initObjects_()

void ExpressionVar::initObjects_ ( )
private

Definition at line 15 of file ExpressionVar.cc.

References Exhume::I.

Referenced by ExpressionVar().

15  {
16  objects_.resize(methods_.size());
17  std::vector<edm::ObjectWithDict>::iterator IO = objects_.begin();
18  for (std::vector<MethodInvoker>::const_iterator I = methods_.begin(), E = methods_.end(); I != E; ++IO, ++I) {
19  if (I->isFunction()) {
20  edm::TypeWithDict retType = I->method().finalReturnType();
21  needsDestructor_.push_back(makeStorage(*IO, retType));
22  } else {
23  *IO = edm::ObjectWithDict();
24  needsDestructor_.push_back(false);
25  }
26  }
27 }
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

◆ isValidReturnType()

bool ExpressionVar::isValidReturnType ( method::TypeCode  retType)
static

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

78  {
79  using namespace method;
80  bool ret = false;
81  switch (retType) {
82  case (doubleType):
83  ret = true;
84  break;
85  case (floatType):
86  ret = true;
87  break;
88  case (intType):
89  ret = true;
90  break;
91  case (uIntType):
92  ret = true;
93  break;
94  case (shortType):
95  ret = true;
96  break;
97  case (uShortType):
98  ret = true;
99  break;
100  case (longType):
101  ret = true;
102  break;
103  case (uLongType):
104  ret = true;
105  break;
106  case (charType):
107  ret = true;
108  break;
109  case (uCharType):
110  ret = true;
111  break;
112  case (boolType):
113  ret = true;
114  break;
115  case (enumType):
116  ret = true;
117  break;
118  case (invalid):
119  default:
120  break;
121  }
122  return ret;
123 }
ret
prodAgent to be discontinued

◆ makeStorage()

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 60 of file ExpressionVar.cc.

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

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

60  {
61  static const edm::TypeWithDict tVoid(edm::TypeWithDict::byName("void"));
62  bool ret = false;
63  if (retType == tVoid) {
65  } else if (retType.isPointer() || retType.isReference()) {
66  // in this case, I have to allocate a void*, not an object!
67  obj = edm::ObjectWithDict(retType, new void*);
68  } else {
69  obj = edm::ObjectWithDict(retType, retType.allocate());
70  ret = retType.isClass();
71  //std::cout << "ExpressionVar: reserved memory at " << obj.address() <<
72  // " for a " << retType.qualifiedName() << " returned by " <<
73  // member.name() << std::endl;
74  }
75  return ret;
76 }
static ObjectWithDict byType(TypeWithDict const &)
ret
prodAgent to be discontinued
void * allocate() const
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
bool isClass() const
bool isPointer() const
bool isReference() const

◆ objToDouble()

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 142 of file ExpressionVar.cc.

References generateTowerEtThresholdLUT::addr, cms::cuda::assert(), reco::method::boolType, reco::method::charType, reco::method::doubleType, reco::method::enumType, reco::method::floatType, reco::method::intType, reco::method::longType, AlcaSiPixelAliHarvester0T_cff::method, getGTfromDQMFile::obj, runTheMatrix::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().

142  {
143  using namespace method;
144  void* addr = obj.address();
145  double ret = 0.0;
146  switch (type) {
147  case doubleType:
148  ret = *static_cast<double*>(addr);
149  break;
150  case floatType:
151  ret = *static_cast<float*>(addr);
152  break;
153  case intType:
154  ret = *static_cast<int*>(addr);
155  break;
156  case uIntType:
157  ret = *static_cast<unsigned int*>(addr);
158  break;
159  case shortType:
160  ret = *static_cast<short*>(addr);
161  break;
162  case uShortType:
163  ret = *static_cast<unsigned short*>(addr);
164  break;
165  case longType:
166  ret = *static_cast<long*>(addr);
167  break;
168  case uLongType:
169  ret = *static_cast<unsigned long*>(addr);
170  break;
171  case charType:
172  ret = *static_cast<char*>(addr);
173  break;
174  case uCharType:
175  ret = *static_cast<unsigned char*>(addr);
176  break;
177  case boolType:
178  ret = *static_cast<bool*>(addr);
179  break;
180  case enumType:
181  ret = *static_cast<int*>(addr);
182  break;
183  default:
184  //FIXME: Error not caught in production build!
185  assert(false && "objToDouble: invalid type!");
186  break;
187  };
188  return ret;
189 }
ret
prodAgent to be discontinued
assert(be >=bs)

◆ value()

double ExpressionVar::value ( const edm::ObjectWithDict obj) const
overridevirtual

Implements reco::parser::ExpressionBase.

Definition at line 125 of file ExpressionVar.cc.

References Exhume::I, methods_, needsDestructor_, getGTfromDQMFile::obj, objects_, objToDouble(), runTheMatrix::ret, 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(), Types.string::configValue(), Types.FileInPath::configValue(), Mixins.UsingBlock::dumpPython(), Mixins.UsingBlock::insertInto(), Types.int32::insertInto(), Types.uint32::insertInto(), Types.int64::insertInto(), Types.uint64::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(), and Types.vstring::insertInto().

125  {
127  std::vector<edm::ObjectWithDict>::iterator IO = objects_.begin();
128  for (std::vector<MethodInvoker>::const_iterator I = methods_.begin(), E = methods_.end(); I != E; ++I, ++IO) {
129  val = I->invoke(val, *IO);
130  }
131  double ret = objToDouble(val, retType_);
132  std::vector<bool>::const_reverse_iterator RIB = needsDestructor_.rbegin();
133  for (std::vector<edm::ObjectWithDict>::reverse_iterator RI = objects_.rbegin(), RE = objects_.rend(); RI != RE;
134  ++RIB, ++RI) {
135  if (*RIB) {
136  RI->destruct(false);
137  }
138  }
139  return ret;
140 }
ret
prodAgent to be discontinued
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

◆ methods_

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

Definition at line 25 of file ExpressionVar.h.

Referenced by value().

◆ needsDestructor_

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

Definition at line 27 of file ExpressionVar.h.

Referenced by value().

◆ objects_

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

Definition at line 26 of file ExpressionVar.h.

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

◆ retType_

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

Definition at line 28 of file ExpressionVar.h.

Referenced by value().