CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | 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 Types

using Objects = std::vector< std::pair< edm::ObjectWithDict, bool > >
 

Private Member Functions

Objects borrowObjects () const
 
Objects initObjects_ () const
 
void returnObjects (Objects &&) const
 

Private Attributes

std::vector< MethodInvokermethods_
 
oneapi::tbb::concurrent_queue< ObjectsobjectsCache_
 
method::TypeCode retType_
 

Detailed Description

Evaluate an object's method or datamember (or chain of them) to get a number.

Definition at line 24 of file ExpressionVar.h.

Member Typedef Documentation

◆ Objects

using reco::parser::ExpressionVar::Objects = std::vector<std::pair<edm::ObjectWithDict, bool> >
private

Definition at line 27 of file ExpressionVar.h.

Constructor & Destructor Documentation

◆ ExpressionVar() [1/2]

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

Definition at line 31 of file ExpressionVar.cc.

References initObjects_(), and returnObjects().

32  : methods_(methods), retType_(retType) {
34 }
method::TypeCode retType_
Definition: ExpressionVar.h:29
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:26
void returnObjects(Objects &&) const
Objects initObjects_() const

◆ ExpressionVar() [2/2]

ExpressionVar::ExpressionVar ( const ExpressionVar rhs)

Definition at line 36 of file ExpressionVar.cc.

References initObjects_(), and returnObjects().

36  : methods_(rhs.methods_), retType_(rhs.retType_) {
38 }
method::TypeCode retType_
Definition: ExpressionVar.h:29
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:26
void returnObjects(Objects &&) const
Objects initObjects_() const

◆ ~ExpressionVar()

ExpressionVar::~ExpressionVar ( )
override

Definition at line 50 of file ExpressionVar.cc.

References delStorage(), EcalTangentSkim_cfg::o, L1TPhase2Offline_cfi::objects, and objectsCache_.

50  {
52  while (objectsCache_.try_pop(objects)) {
53  for (auto& o : objects) {
54  delStorage(o.first);
55  }
56  }
57 }
std::vector< std::pair< edm::ObjectWithDict, bool > > Objects
Definition: ExpressionVar.h:27
static void delStorage(edm::ObjectWithDict &)
oneapi::tbb::concurrent_queue< Objects > objectsCache_
Definition: ExpressionVar.h:28

Member Function Documentation

◆ borrowObjects()

ExpressionVar::Objects ExpressionVar::borrowObjects ( ) const
private

Definition at line 40 of file ExpressionVar.cc.

References initObjects_(), L1TPhase2Offline_cfi::objects, and objectsCache_.

Referenced by value().

40  {
42  if (objectsCache_.try_pop(objects)) {
43  return objects;
44  }
45  return initObjects_();
46 }
std::vector< std::pair< edm::ObjectWithDict, bool > > Objects
Definition: ExpressionVar.h:27
oneapi::tbb::concurrent_queue< Objects > objectsCache_
Definition: ExpressionVar.h:28
Objects initObjects_() const

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

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

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

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

◆ initObjects_()

ExpressionVar::Objects ExpressionVar::initObjects_ ( ) const
private

Definition at line 15 of file ExpressionVar.cc.

References cms::cuda::assert(), AlcaSiPixelAliHarvester0T_cff::method, and L1TPhase2Offline_cfi::objects.

Referenced by borrowObjects(), and ExpressionVar().

15  {
16  Objects objects(methods_.size(), {edm::ObjectWithDict(), false});
17  assert(objects.size() == methods_.size());
18  auto IO = objects.begin();
19  for (auto const& method : methods_) {
20  if (method.isFunction()) {
21  edm::TypeWithDict retType = method.method().finalReturnType();
22  IO->second = makeStorage(IO->first, retType);
23  } else {
24  *IO = {edm::ObjectWithDict(), false};
25  }
26  ++IO;
27  }
28  return objects;
29 }
static bool makeStorage(edm::ObjectWithDict &obj, const edm::TypeWithDict &retType)
assert(be >=bs)
std::vector< std::pair< edm::ObjectWithDict, bool > > Objects
Definition: ExpressionVar.h:27
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:26

◆ isValidReturnType()

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

Definition at line 92 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().

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

74  {
75  static const edm::TypeWithDict tVoid(edm::TypeWithDict::byName("void"));
76  bool ret = false;
77  if (retType == tVoid) {
79  } else if (retType.isPointer() || retType.isReference()) {
80  // in this case, I have to allocate a void*, not an object!
81  obj = edm::ObjectWithDict(retType, new void*);
82  } else {
83  obj = edm::ObjectWithDict(retType, retType.allocate());
84  ret = retType.isClass();
85  //std::cout << "ExpressionVar: reserved memory at " << obj.address() <<
86  // " for a " << retType.qualifiedName() << " returned by " <<
87  // member.name() << std::endl;
88  }
89  return ret;
90 }
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 157 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().

157  {
158  using namespace method;
159  void* addr = obj.address();
160  double ret = 0.0;
161  switch (type) {
162  case doubleType:
163  ret = *static_cast<double*>(addr);
164  break;
165  case floatType:
166  ret = *static_cast<float*>(addr);
167  break;
168  case intType:
169  ret = *static_cast<int*>(addr);
170  break;
171  case uIntType:
172  ret = *static_cast<unsigned int*>(addr);
173  break;
174  case shortType:
175  ret = *static_cast<short*>(addr);
176  break;
177  case uShortType:
178  ret = *static_cast<unsigned short*>(addr);
179  break;
180  case longType:
181  ret = *static_cast<long*>(addr);
182  break;
183  case uLongType:
184  ret = *static_cast<unsigned long*>(addr);
185  break;
186  case charType:
187  ret = *static_cast<char*>(addr);
188  break;
189  case uCharType:
190  ret = *static_cast<unsigned char*>(addr);
191  break;
192  case boolType:
193  ret = *static_cast<bool*>(addr);
194  break;
195  case enumType:
196  ret = *static_cast<int*>(addr);
197  break;
198  default:
199  //FIXME: Error not caught in production build!
200  assert(false && "objToDouble: invalid type!");
201  break;
202  };
203  return ret;
204 }
ret
prodAgent to be discontinued
assert(be >=bs)

◆ returnObjects()

void ExpressionVar::returnObjects ( Objects &&  iOb) const
private

Definition at line 48 of file ExpressionVar.cc.

References eostools::move(), and objectsCache_.

Referenced by ExpressionVar(), and value().

48 { objectsCache_.push(std::move(iOb)); }
oneapi::tbb::concurrent_queue< Objects > objectsCache_
Definition: ExpressionVar.h:28
def move(src, dest)
Definition: eostools.py:511

◆ value()

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

Implements reco::parser::ExpressionBase.

Definition at line 139 of file ExpressionVar.cc.

References borrowObjects(), visualization-live-secondInstance_cfg::m, methods_, eostools::move(), getGTfromDQMFile::obj, objToDouble(), runTheMatrix::ret, retType_, returnObjects(), 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().

139  {
141  auto objects = borrowObjects();
142  auto IO = objects.begin();
143  for (auto& m : methods_) {
144  val = m.invoke(val, IO->first);
145  ++IO;
146  }
147  double ret = objToDouble(val, retType_);
148  for (auto RI = objects.rbegin(), RE = objects.rend(); RI != RE; ++RI) {
149  if (RI->second) {
150  RI->first.destruct(false);
151  }
152  }
154  return ret;
155 }
ret
prodAgent to be discontinued
static double objToDouble(const edm::ObjectWithDict &obj, method::TypeCode type)
method::TypeCode retType_
Definition: ExpressionVar.h:29
Objects borrowObjects() const
std::vector< MethodInvoker > methods_
Definition: ExpressionVar.h:26
void returnObjects(Objects &&) const
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ methods_

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

Definition at line 26 of file ExpressionVar.h.

Referenced by value().

◆ objectsCache_

oneapi::tbb::concurrent_queue<Objects> reco::parser::ExpressionVar::objectsCache_
mutableprivate

Definition at line 28 of file ExpressionVar.h.

Referenced by borrowObjects(), returnObjects(), and ~ExpressionVar().

◆ retType_

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

Definition at line 29 of file ExpressionVar.h.

Referenced by value().