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  if (iCompute_.find(var) != iCompute_.end()) {
57  edm::LogError("VariableComputer") << "redeclaring: " << var << " skipping.";
58  return;
59  }
60  std::string aName = name_ + separator_ + var;
61  ComputedVariable* newVar = new ComputedVariable(method_, aName, arg_.iConfig, this, iC);
62  iCompute_[var] = newVar;
63  arg_.m.insert(std::make_pair(aName, newVar));
64 }
66  std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.find(var);
67  if (it == iCompute_.end()) {
68  std::stringstream ss;
69  ss << "cannot assign: " << var << ". List of variable declared:\n";
70  for (std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.begin(); it != iCompute_.end();
71  ++it)
72  ss << it->first << std::endl;
73  edm::LogError("VariableComputer") << ss.str();
74  } else
75  it->second->setCache(value);
76 }
77 
79  for (std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.begin(); it != iCompute_.end();
80  ++it)
81  it->second->setNotCompute();
82 }
84  std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.find(var);
85  if (it == iCompute_.end()) {
86  std::stringstream ss;
87  ss << "cannot act on: " << var << ". List of variable declared:\n";
88  for (std::map<std::string, const ComputedVariable*>::const_iterator it = iCompute_.begin(); it != iCompute_.end();
89  ++it)
90  ss << it->first << std::endl;
91  edm::LogError("VariableComputer") << ss.str();
92  } else
93  it->second->setNotCompute();
94 }
95 
97  : CachingVariable("ComputedVariable", arg.n, arg.iConfig, iC),
98  myComputer{VariableComputerFactory::get()->create(arg.iConfig.getParameter<std::string>("computer"), arg, iC)} {}
99 
102  : VariableComputer(arg, iC) {
103  declare("toto", iC);
104  declare("tutu", iC);
105  declare("much", iC);
106 }
107 
109  //does some mumbo jumbo with the event.
110  // computes a bunch of doubles
111  double toto = 3;
112  double tutu = 4;
113 
114  //set the variables value (which do as if they had been cached)
115  assign("toto", toto);
116  assign("tutu", tutu);
117  doesNotCompute("much");
118 }
std::string separator_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
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)
unsigned int maxIndex() const
Log< level::Error, false > LogError
A arg
Definition: Factorize.h:31
void assign(std::string var, double &value) const
const CachingVariable::CachingVariableFactoryArg & arg_
std::vector< double > slots_
int iEvent
Definition: GenABIO.cc:224
std::map< std::string, const ComputedVariable * > iCompute_
void compute(const edm::Event &iEvent) const override
VariableComputerTest(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
Definition: value.py:1
void doesNotCompute() const
CachingVariable::evalType eval(const edm::Event &iEvent) const override
std::string var_
CachingVariable::evalType eval(const edm::Event &iEvent) const override
std::string method_
#define get
void declare(std::string var, edm::ConsumesCollector &iC)
std::string var_
std::pair< bool, valueType > evalType