CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
ExpressionVariable< Object, label > Class Template Reference

#include <CachingVariable.h>

Inheritance diagram for ExpressionVariable< Object, label >:
CachingVariable

Public Member Functions

CachingVariable::evalType eval (const edm::Event &iEvent) const
 
 ExpressionVariable (const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
 
 ~ExpressionVariable ()
 
- Public Member Functions inherited from CachingVariable
void addDescriptionLine (const std::string &s)
 
 CachingVariable (std::string m, std::string n, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
 
bool compute (const edm::Event &iEvent) const
 
const Descriptiondescription () const
 
const std::string & holderName () const
 
const std::string & method () const
 
const std::string & name () const
 
valueType operator() (const edm::Event &iEvent) const
 
void print () const
 
void setHolder (std::string hn) const
 
virtual ~CachingVariable ()
 

Private Attributes

StringObjectFunction< Object > * f_
 
StringObjectFunction< Object > * forder_
 
unsigned int index_
 
StringCutObjectSelector< Object > * selector_
 
edm::EDGetTokenT< edm::View
< Object > > 
src_
 
edm::InputTag srcTag_
 

Additional Inherited Members

- Public Types inherited from CachingVariable
typedef std::pair< bool,
valueType
evalType
 
typedef double valueType
 
typedef std::map< std::string,
const CachingVariable * > 
vMap
 
- Protected Member Functions inherited from CachingVariable
evalTypebaseEval (const edm::Event &iEvent) const
 
bool notSeenThisEventAlready (const edm::Event &iEvent) const
 
void setCache (valueType &v) const
 
void setNotCompute () const
 
- Protected Attributes inherited from CachingVariable
evalType cache_
 
edm::ParameterSet conf_
 
Description d_
 
edm::Event::CacheIdentifier_t eventCacheID_ =0
 
std::string holderName_
 
std::string method_
 
std::string name_
 

Detailed Description

template<typename Object, const char * label>
class ExpressionVariable< Object, label >

Definition at line 276 of file CachingVariable.h.

Constructor & Destructor Documentation

template<typename Object , const char * label>
ExpressionVariable< Object, label >::ExpressionVariable ( const CachingVariableFactoryArg arg,
edm::ConsumesCollector iC 
)
inline

Definition at line 278 of file CachingVariable.h.

References CachingVariable::addDescriptionLine(), edm::ConsumesCollector::consumes(), alignCSCRings::e, edm::ParameterSet::exists(), ExpressionVariable< Object, label >::f_, ExpressionVariable< Object, label >::forder_, edm::ParameterSet::getParameter(), CachingVariable::CachingVariableFactoryArg::iConfig, ExpressionVariable< Object, label >::index_, edm::ParameterSet::insert(), CachingVariable::CachingVariableFactoryArg::m, CachingVariable::CachingVariableFactoryArg::n, CachingVariable::name(), corrVsCorr::selection, ExpressionVariable< Object, label >::selector_, cmsHarvester::sep, ExpressionVariable< Object, label >::src_, ExpressionVariable< Object, label >::srcTag_, contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, and findQualityFiles::v.

278  :
279  CachingVariable(std::string(label)+"ExpressionVariable",arg.n,arg.iConfig,iC) , f_(0), forder_(0) {
280  srcTag_=edm::Service<InputTagDistributorService>()->retrieve("src",arg.iConfig);
282  //old style constructor
283  if (arg.iConfig.exists("expr") && arg.iConfig.exists("index")){
284  std::string expr=arg.iConfig.getParameter<std::string>("expr");
285  index_=arg.iConfig.getParameter<unsigned int>("index");
286  f_ = new StringObjectFunction<Object>(expr);
287  addDescriptionLine("calculating: "+expr);
288  std::stringstream ss;
289  ss<<"on object at index: "<<index_<<" of: "<<srcTag_;
290 
291  if (arg.iConfig.exists("order")){
292  std::string order=arg.iConfig.getParameter<std::string>("order");
294  ss<<" after sorting according to: "<<order;
295  }else forder_ =0;
296 
297  if (arg.iConfig.exists("selection")){
298  std::string selection=arg.iConfig.getParameter<std::string>("selection");
300  ss<<" and selecting only: "<<selection;
301  }else selector_=0;
302 
303 
304 
305  addDescriptionLine(ss.str()); ss.str("");
306  arg.m[arg.n] = this;
307  }
308  else{
309  //multiple instance constructor
310  std::map<std::string, edm::Entry> indexEntry;
311  if (arg.n.find("_N")!=std::string::npos){
312  //will have to loop over indexes
313  std::vector<unsigned int> indexes = arg.iConfig.getParameter<std::vector<unsigned int> >("indexes");
314  for (unsigned int iI=0;iI!=indexes.size();++iI){
315  edm::ParameterSet toUse = arg.iConfig;
316  edm::Entry e("unsigned int",indexes[iI],true);
317  std::stringstream ss;
318  //add +1 0->1, 1->2, ... in the variable label
319  ss<<indexes[iI]+1;
320  indexEntry.insert(std::make_pair(ss.str(),e));
321  }
322  }//contains "_N"
323 
324  std::map< std::string, edm::Entry> varEntry;
325  if (arg.n.find("_V")!=std::string::npos){
326  //do something fancy for multiple variable from one PSet
327  std::vector<std::string> vars = arg.iConfig.getParameter<std::vector<std::string> >("vars");
328  for (unsigned int v=0;v!=vars.size();++v){
329  unsigned int sep=vars[v].find(":");
330  std::string name=vars[v].substr(0,sep);
331  std::string expr=vars[v].substr(sep+1);
332 
333  edm::Entry e("string",expr,true);
334  varEntry.insert(std::make_pair(name,e));
335  }
336  }//contains "_V"
337 
338  std::string radical = arg.n;
339  //remove the "_V";
340  if (!varEntry.empty())
341  radical = radical.substr(0,radical.size()-2);
342  //remove the "_N";
343  if (!indexEntry.empty())
344  radical = radical.substr(0,radical.size()-2);
345 
346  if(varEntry.empty()){
347  //loop only the indexes
348  for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
349  edm::ParameterSet toUse = arg.iConfig;
350  toUse.insert(true,"index",iIt->second);
351  std::string newVname = radical+iIt->first;
352  // std::cout<<"in the loop, creating variable with name: "<<newVname<<std::endl;
353  // the constructor auto log the new variable in the map
355  }
356  }else{
357  for (std::map< std::string, edm::Entry>::iterator vIt=varEntry.begin();vIt!=varEntry.end();++vIt){
358  if (indexEntry.empty()){
359  edm::ParameterSet toUse = arg.iConfig;
360  toUse.insert(true,"expr",vIt->second);
361  std::string newVname = radical+vIt->first;
362  // std::cout<<"in the loop, creating variable with name: "<<newVname<<std::endl;
363  // the constructor auto log the new variable in the map
365  }else{
366  for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
367  edm::ParameterSet toUse = arg.iConfig;
368  toUse.insert(true,"expr",vIt->second);
369  toUse.insert(true,"index",iIt->second);
370  std::string newVname = radical+iIt->first+vIt->first;
371  // std::cout<<"in the loop, creating variable with name: "<<newVname<<std::endl;
372  // the constructor auto log the new variable in the map
374  }}
375  }
376  }
377  //there is a memory leak here, because the object we are in is not logged in the arg.m, the variable is not valid
378  // anyways, but reside in memory with no ways of de-allocating it.
379  // since the caching variables are actually "global" objects, it does not matter.
380  // we cannot add it to the map, otherwise, it would be considered for eventV ntupler
381  }
382  }
CachingVariable(std::string m, std::string n, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::InputTag srcTag_
selection
main part
Definition: corrVsCorr.py:98
StringCutObjectSelector< Object > * selector_
void insert(bool ok_to_replace, char const *, Entry const &)
A arg
Definition: Factorize.h:36
StringObjectFunction< Object > * f_
void addDescriptionLine(const std::string &s)
edm::EDGetTokenT< edm::View< Object > > src_
StringObjectFunction< Object > * forder_
ExpressionVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
const std::string & name() const
template<typename Object , const char * label>
ExpressionVariable< Object, label >::~ExpressionVariable ( )
inline

Definition at line 383 of file CachingVariable.h.

References ExpressionVariable< Object, label >::f_, ExpressionVariable< Object, label >::forder_, and ExpressionVariable< Object, label >::selector_.

383  {
384  if (f_) delete f_;
385  if (forder_) delete forder_;
386  if (selector_) delete selector_;
387  }
StringCutObjectSelector< Object > * selector_
StringObjectFunction< Object > * f_
StringObjectFunction< Object > * forder_

Member Function Documentation

template<typename Object , const char * label>
CachingVariable::evalType ExpressionVariable< Object, label >::eval ( const edm::Event iEvent) const
inlinevirtual

Reimplemented from CachingVariable.

Definition at line 389 of file CachingVariable.h.

References ExpressionVariable< Object, label >::f_, ExpressionVariable< Object, label >::forder_, edm::Event::getByToken(), i, ExpressionVariable< Object, label >::index_, LogDebug, CachingVariable::method(), python.connectstrParser::o, ExpressionVariable< Object, label >::selector_, python.multivaluedict::sort(), ExpressionVariable< Object, label >::src_, and ExpressionVariable< Object, label >::srcTag_.

389  {
390  if (!f_) {
391  edm::LogError(method())<<" no parser attached.";
392  return std::make_pair(false,0);
393  }
395  iEvent.getByToken(src_,oH);
396  if (index_>=oH->size()){
397  LogDebug(method())<<"fail to get object at index: "<<index_<<" in collection: "<<srcTag_;
398  return std::make_pair(false,0);
399  }
400 
401  //get the ordering right first. if required
402  if (selector_ || forder_){
403  std::vector<const Object*> copyToSort(0);
404  copyToSort.reserve(oH->size());
405  for (unsigned int i=0;i!=oH->size();++i){
406  if (selector_ && !((*selector_)((*oH)[i]))) continue;
407  copyToSort.push_back(&(*oH)[i]);
408  }
409  if (index_ >= copyToSort.size()) return std::make_pair(false,0);
410  if (forder_) std::sort(copyToSort.begin(), copyToSort.end(), sortByStringFunction<Object>(forder_));
411 
412  const Object * o = copyToSort[index_];
413  return std::make_pair(true,(*f_)(*o));
414  }
415  else{
416  const Object & o = (*oH)[index_];
417  return std::make_pair(true,(*f_)(o));
418  }
419  }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::InputTag srcTag_
StringCutObjectSelector< Object > * selector_
StringObjectFunction< Object > * f_
edm::EDGetTokenT< edm::View< Object > > src_
StringObjectFunction< Object > * forder_
const std::string & method() const

Member Data Documentation

template<typename Object , const char * label>
StringObjectFunction<Object>* ExpressionVariable< Object, label >::f_
private
template<typename Object , const char * label>
StringObjectFunction<Object>* ExpressionVariable< Object, label >::forder_
private
template<typename Object , const char * label>
unsigned int ExpressionVariable< Object, label >::index_
private
template<typename Object , const char * label>
StringCutObjectSelector<Object>* ExpressionVariable< Object, label >::selector_
private
template<typename Object , const char * label>
edm::EDGetTokenT<edm::View<Object> > ExpressionVariable< Object, label >::src_
private
template<typename Object , const char * label>
edm::InputTag ExpressionVariable< Object, label >::srcTag_
private