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 
5  const CachingVariable * var=edm::Service<VariableHelperService>()->get().variable(var_);
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 
27  const CachingVariable * var=edm::Service<VariableHelperService>()->get().variable(var_);
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;
40  method_ = arg_.iConfig.getParameter<std::string>("computer");
41 }
42 
43 void VariableComputer::declare(std::string var){
44  std::string aName = name_+separator_+var;
45  ComputedVariable * newVar = new ComputedVariable(method_,aName,arg_.iConfig,this);
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 }
54 void VariableComputer::assign(std::string var, double & value) const{
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 }
71 void VariableComputer::doesNotCompute(std::string var) const{
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){
87  // instanciate the computer
88  std::string computerType = arg.iConfig.getParameter<std::string>("computer");
89  myComputer = VariableComputerFactory::get()->create(computerType,arg);
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");
95  declare("tutu");
96  declare("much");
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
const VariableComputer * myComputer
bool exists(std::string const &parameterName) const
checks if a parameter exists
CachingVariable::evalType eval(const edm::Event &iEvent) const
A arg
Definition: Factorize.h:36
std::vector< double > slots_
unsigned int maxIndex() const
ComputedVariable(CachingVariableFactoryArg arg)
void assign(std::string var, double &value) const
int iEvent
Definition: GenABIO.cc:243
VariableComputer(CachingVariable::CachingVariableFactoryArg arg)
CachingVariable::CachingVariableFactoryArg & arg_
std::map< std::string,const ComputedVariable * > iCompute_
VariableComputerTest(CachingVariable::CachingVariableFactoryArg arg)
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
std::string var_
mathSSE::Vec4< T > v
T get(const Candidate &c)
Definition: component.h:56
std::pair< bool, valueType > evalType
void declare(std::string var)