CMS 3D CMS Logo

CachingVariable.cc
Go to the documentation of this file.
3 
6  if (!var->compute(iEvent))
7  return std::make_pair(false, 0);
8 
9  double v = (*var)(iEvent);
10  if (v < slots_.front()) {
11  if (useUnderFlow_)
12  return std::make_pair(true, 0);
13  else
14  return std::make_pair(false, 0);
15  }
16  if (v >= slots_.back()) {
17  if (useOverFlow_)
18  return std::make_pair(true, (double)maxIndex());
19  else
20  return std::make_pair(false, 0);
21  }
22  unsigned int i = 1;
23  for (; i < slots_.size(); ++i)
24  if (v < slots_[i])
25  break;
26 
27  if (useUnderFlow_)
28  return std::make_pair(true, (double)i);
29  //need to substract 1 because checking on upper edges
30  else
31  return std::make_pair(true, (double)i - 1);
32 }
33 
35  const CachingVariable* var = edm::Service<VariableHelperService>()->get().variable(var_);
36  if (!var->compute(iEvent))
37  return std::make_pair(false, 0);
38 
39  double v = (*var)(iEvent);
40  double p = exp(power_ * log(v));
41  return std::make_pair(true, p);
42 }
43 
45  : arg_(arg) {
46  if (arg_.iConfig.exists("separator"))
48  else
49  separator_ = "_";
50 
51  name_ = arg_.n;
53 }
54 
56  std::string aName = name_ + separator_ + var;
57  ComputedVariable* newVar = new ComputedVariable(method_, aName, arg_.iConfig, this, iC);
58  if (iCompute_.find(var) != iCompute_.end()) {
59  edm::LogError("VariableComputer") << "redeclaring: " << var << " skipping.";
60  delete newVar;
61  return;
62  }
63  iCompute_[var] = newVar;
64  arg_.m.insert(std::make_pair(aName, newVar));
65 }
67  std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.find(var);
68  if (it == iCompute_.end()) {
69  std::stringstream ss;
70  ss << "cannot assign: " << var << ". List of variable declared:\n";
71  for (std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.begin(); it != iCompute_.end();
72  ++it)
73  ss << it->first << std::endl;
74  edm::LogError("VariableComputer") << ss.str();
75  } else
76  it->second->setCache(value);
77 }
78 
80  for (std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.begin(); it != iCompute_.end();
81  ++it)
82  it->second->setNotCompute();
83 }
85  std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.find(var);
86  if (it == iCompute_.end()) {
87  std::stringstream ss;
88  ss << "cannot act on: " << var << ". List of variable declared:\n";
89  for (std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.begin(); it != iCompute_.end();
90  ++it)
91  ss << it->first << std::endl;
92  edm::LogError("VariableComputer") << ss.str();
93  } else
94  it->second->setNotCompute();
95 }
96 
98  : CachingVariable("ComputedVariable", arg.n, arg.iConfig, iC),
99  myComputer{VariableComputerFactory::get()->create(arg.iConfig.getParameter<std::string>("computer"), arg, iC)} {}
100 
103  : VariableComputer(arg, iC) {
104  declare("toto", iC);
105  declare("tutu", iC);
106  declare("much", iC);
107 }
108 
110  //does some mumbo jumbo with the event.
111  // computes a bunch of doubles
112  double toto = 3;
113  double tutu = 4;
114 
115  //set the variables value (which do as if they had been cached)
116  assign("toto", toto);
117  assign("tutu", tutu);
118  doesNotCompute("much");
119 }
T getParameter(std::string const &) const
std::string separator_
ComputedVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
bool exists(std::string const &parameterName) const
checks if a parameter exists
VariableComputer(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
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:224
void compute(const edm::Event &iEvent) const override
std::map< std::string, const ComputedVariable * > iCompute_
VariableComputerTest(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
CachingVariable::evalType eval(const edm::Event &iEvent) const override
Definition: value.py:1
CachingVariable::evalType eval(const edm::Event &iEvent) const override
bool compute(const edm::Event &iEvent) const
std::string var_
void doesNotCompute() const
std::string method_
void declare(std::string var, edm::ConsumesCollector &iC)
std::pair< bool, valueType > evalType