CMS 3D CMS Logo

ExpressionVar.cc
Go to the documentation of this file.
3 
8 
9 #include <cassert>
10 #include <map>
11 
12 using namespace reco::parser;
13 using namespace std;
14 
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 }
28 
29 ExpressionVar::ExpressionVar(const vector<MethodInvoker>& methods, method::TypeCode retType)
30  : methods_(methods), retType_(retType) {
31  initObjects_();
32 }
33 
34 ExpressionVar::ExpressionVar(const ExpressionVar& rhs) : methods_(rhs.methods_), retType_(rhs.retType_) {
35  initObjects_();
36 }
37 
39  for (std::vector<edm::ObjectWithDict>::iterator I = objects_.begin(), E = objects_.end(); I != E; ++I) {
40  delStorage(*I);
41  }
42  objects_.clear();
43 }
44 
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 }
59 
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 }
77 
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 }
124 
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 }
141 
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 }
190 
191 ExpressionLazyVar::ExpressionLazyVar(const std::vector<LazyInvoker>& methods) : methods_(methods) {}
192 
194 
197  std::vector<LazyInvoker>::const_iterator I = methods_.begin();
198  std::vector<LazyInvoker>::const_iterator E = methods_.end() - 1;
199  for (; I < E; ++I) {
200  val = I->invoke(val, objects_);
201  }
202  double ret = I->invokeLast(val, objects_);
203  for (std::vector<edm::ObjectWithDict>::reverse_iterator RI = objects_.rbegin(), RE = objects_.rend(); RI != RE;
204  ++RI) {
205  RI->destruct(false);
206  }
207  objects_.clear();
208  return ret;
209 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
edm::TypeWithDict::byName
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
reco::method::enumType
Definition: TypeCode.h:25
reco::parser::ExpressionLazyVar::methods_
std::vector< LazyInvoker > methods_
Definition: ExpressionVar.h:60
reco::parser::ExpressionVar::needsDestructor_
std::vector< bool > needsDestructor_
Definition: ExpressionVar.h:27
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
reco::method::uIntType
Definition: TypeCode.h:17
edm::ObjectWithDict
Definition: ObjectWithDict.h:17
AlcaSiPixelAliHarvester0T_cff.method
method
Definition: AlcaSiPixelAliHarvester0T_cff.py:41
cms::cuda::assert
assert(be >=bs)
reco::method::uCharType
Definition: TypeCode.h:19
TypeWithDict.h
edm::TypeWithDict::isClass
bool isClass() const
Definition: TypeWithDict.cc:403
reco::parser::ExpressionVar::initObjects_
void initObjects_()
Definition: ExpressionVar.cc:15
reco::parser::ExpressionVar::~ExpressionVar
~ExpressionVar() override
Definition: ExpressionVar.cc:38
reco::parser::ExpressionVar::ExpressionVar
ExpressionVar(const std::vector< MethodInvoker > &methods, method::TypeCode retType)
Definition: ExpressionVar.cc:29
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
reco::parser::ExpressionLazyVar::ExpressionLazyVar
ExpressionLazyVar(const std::vector< LazyInvoker > &methods)
Definition: ExpressionVar.cc:191
ObjectWithDict.h
generateTowerEtThresholdLUT.addr
addr
Definition: generateTowerEtThresholdLUT.py:57
reco::parser::ExpressionVar::methods_
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:25
Exhume::I
const std::complex< double > I
Definition: I.h:8
reco::method::boolType
Definition: TypeCode.h:24
reco::method::intType
Definition: TypeCode.h:16
reco::method::uShortType
Definition: TypeCode.h:21
edm::TypeWithDict::isPointer
bool isPointer() const
Definition: TypeWithDict.cc:416
edm::TypeWithDict::isReference
bool isReference() const
Definition: TypeWithDict.cc:418
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::TypeWithDict
Definition: TypeWithDict.h:38
reco::method::charType
Definition: TypeCode.h:18
reco::parser::ExpressionVar
Evaluate an object's method or datamember (or chain of them) to get a number.
Definition: ExpressionVar.h:23
MethodInvoker.h
reco::method::TypeCode
TypeCode
Definition: TypeCode.h:13
reco::parser::ExpressionLazyVar::value
double value(const edm::ObjectWithDict &) const override
Definition: ExpressionVar.cc:195
edm::ObjectWithDict::byType
static ObjectWithDict byType(TypeWithDict const &)
Definition: ObjectWithDict.cc:13
reco::parser::ExpressionVar::objToDouble
static double objToDouble(const edm::ObjectWithDict &obj, method::TypeCode type)
Definition: ExpressionVar.cc:142
reco::method::floatType
Definition: TypeCode.h:15
reco::parser
Definition: cutParser.h:9
reco::parser::ExpressionVar::delStorage
static void delStorage(edm::ObjectWithDict &)
Definition: ExpressionVar.cc:45
type
type
Definition: HCALResponse.h:21
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
reco::parser::ExpressionVar::makeStorage
static bool makeStorage(edm::ObjectWithDict &obj, const edm::TypeWithDict &retType)
Definition: ExpressionVar.cc:60
reco::parser::ExpressionVar::objects_
std::vector< edm::ObjectWithDict > objects_
Definition: ExpressionVar.h:26
edm::TypeWithDict::allocate
void * allocate() const
Definition: TypeWithDict.cc:787
reco::method::shortType
Definition: TypeCode.h:20
ExpressionVar.h
reco::parser::ExpressionVar::retType_
method::TypeCode retType_
Definition: ExpressionVar.h:28
reco::method::longType
Definition: TypeCode.h:22
reco::method::uLongType
Definition: TypeCode.h:23
reco::parser::ExpressionLazyVar::objects_
std::vector< edm::ObjectWithDict > objects_
Definition: ExpressionVar.h:61
reco::parser::ExpressionLazyVar::~ExpressionLazyVar
~ExpressionLazyVar() override
Definition: ExpressionVar.cc:193
reco::method::doubleType
Definition: TypeCode.h:14
reco::parser::ExpressionVar::isValidReturnType
static bool isValidReturnType(method::TypeCode)
Definition: ExpressionVar.cc:78
MemberWithDict.h
reco::parser::ExpressionVar::value
double value(const edm::ObjectWithDict &) const override
Definition: ExpressionVar.cc:125
FunctionWithDict.h