test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CachingVariable.cc
Go to the documentation of this file.
3 
6  if (!var->compute(iEvent)) return std::make_pair(false,0);
7 
8  double v=(*var)(iEvent);
9  if (v<slots_.front()){
10  if (useUnderFlow_) return std::make_pair(true,0);
11  else return std::make_pair(false,0);
12  }
13  if (v>=slots_.back()){
14  if (useOverFlow_) return std::make_pair(true,(double)maxIndex());
15  else return std::make_pair(false,0);
16  }
17  unsigned int i=1;
18  for (;i<slots_.size();++i)
19  if (v<slots_[i]) break;
20 
21  if (useUnderFlow_) return std::make_pair(true,(double) i);
22  //need to substract 1 because checking on upper edges
23  else return std::make_pair(true,(double)i-1);
24 }
25 
28  if (!var->compute(iEvent)) return std::make_pair(false,0);
29 
30  double v=(*var)(iEvent);
31  double p=exp(power_*log(v));
32  return std::make_pair(true,p);
33 }
34 
36  if (arg_.iConfig.exists("separator")) separator_ = arg_.iConfig.getParameter<std::string>("separator");
37  else separator_ ="_";
38 
39  name_=arg_.n;
41 }
42 
45  ComputedVariable * newVar = new ComputedVariable(method_,aName,arg_.iConfig,this,iC);
46  if (iCompute_.find(var) != iCompute_.end()){
47  edm::LogError("VariableComputer")<<"redeclaring: "<<var<<" skipping.";
48  delete newVar;
49  return;
50  }
51  iCompute_[var] = newVar;
52  arg_.m.insert(std::make_pair(aName,newVar));
53 }
55  std::map<std::string ,const ComputedVariable *>::const_iterator it=iCompute_.find(var);
56  if (it == iCompute_.end()){
57  std::stringstream ss;
58  ss<<"cannot assign: "<<var<<". List of variable declared:\n";
59  for ( std::map<std::string ,const ComputedVariable *>::const_iterator it=iCompute_.begin(); it!=iCompute_.end();++it)
60  ss<<it->first<<std::endl;
61  edm::LogError("VariableComputer")<<ss.str();
62  }
63  else
64  it->second->setCache(value);
65 }
66 
68  for ( std::map<std::string ,const ComputedVariable *>::const_iterator it=iCompute_.begin(); it!=iCompute_.end();++it)
69  it->second->setNotCompute();
70 }
72  std::map<std::string ,const ComputedVariable *>::const_iterator it=iCompute_.find(var);
73  if (it == iCompute_.end()){
74  std::stringstream ss;
75  ss<<"cannot act on: "<<var<<". List of variable declared:\n";
76  for ( std::map<std::string ,const ComputedVariable *>::const_iterator it=iCompute_.begin(); it!=iCompute_.end();++it)
77  ss<<it->first<<std::endl;
78  edm::LogError("VariableComputer")<<ss.str();
79  }
80  else
81  it->second->setNotCompute();
82 }
83 
84 
86  CachingVariable("ComputedVariable",arg.n,arg.iConfig,iC){
87  // instanciate the computer
88  std::string computerType = arg.iConfig.getParameter<std::string>("computer");
89  myComputer = VariableComputerFactory::get()->create(computerType,arg,iC);
90  //there is a memory leak here, because the object we are in is not register anywhere. since it happens once per job, this is not a big deal.
91 }
92 
94  declare("toto", iC);
95  declare("tutu", iC);
96  declare("much", iC);
97 }
98 
100  //does some mumbo jumbo with the event.
101  // computes a bunch of doubles
102  double toto = 3;
103  double tutu = 4;
104 
105  //set the variables value (which do as if they had been cached)
106  assign("toto",toto);
107  assign("tutu",tutu);
108  doesNotCompute("much");
109 }
T getParameter(std::string const &) const
std::string separator_
int i
Definition: DBlmapReader.cc:9
ComputedVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
const VariableComputer * myComputer
bool exists(std::string const &parameterName) const
checks if a parameter exists
VariableComputer(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
CachingVariable::evalType eval(const edm::Event &iEvent) const
A arg
Definition: Factorize.h:36
const CachingVariable::CachingVariableFactoryArg & arg_
std::vector< double > slots_
unsigned int maxIndex() const
void assign(std::string var, double &value) const
int iEvent
Definition: GenABIO.cc:230
VariableComputerTest(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
std::map< std::string,const ComputedVariable * > iCompute_
bool compute(const edm::Event &iEvent) const
std::string var_
CachingVariable::evalType eval(const edm::Event &iEvent) const
void doesNotCompute() const
std::string method_
void compute(const edm::Event &iEvent) const
void declare(std::string var, edm::ConsumesCollector &iC)
std::string var_
T get(const Candidate &c)
Definition: component.h:55
std::pair< bool, valueType > evalType