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 277 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 279 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.

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

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

384  {
385  if (f_) delete f_;
386  if (forder_) delete forder_;
387  if (selector_) delete selector_;
388  }
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 390 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(), and ExpressionVariable< Object, label >::src_.

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