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 }
VariableComputer::method_
std::string method_
Definition: CachingVariable.h:139
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
Splitter::maxIndex
unsigned int maxIndex() const
Definition: CachingVariable.h:190
ComputedVariable::ComputedVariable
ComputedVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
Definition: CachingVariable.cc:97
CachingVariable.h
VariablePower::eval
CachingVariable::evalType eval(const edm::Event &iEvent) const override
Definition: CachingVariable.cc:34
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CachingVariable
Definition: CachingVariable.h:40
VariableComputer::separator_
std::string separator_
Definition: CachingVariable.h:141
VariableComputer::doesNotCompute
void doesNotCompute() const
Definition: CachingVariable.cc:79
findQualityFiles.v
v
Definition: findQualityFiles.py:179
VariableComputerTest::compute
void compute(const edm::Event &iEvent) const override
Definition: CachingVariable.cc:109
trigObjTnPSource_cfi.var
var
Definition: trigObjTnPSource_cfi.py:21
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
VariableComputer::VariableComputer
VariableComputer(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
Definition: CachingVariable.cc:44
VarSplitter::slots_
std::vector< double > slots_
Definition: CachingVariable.h:277
VariableComputer
Definition: CachingVariable.h:115
VariableComputer::iCompute_
std::map< std::string, const ComputedVariable * > iCompute_
Definition: CachingVariable.h:140
CachingVariable::CachingVariableFactoryArg::m
CachingVariable::vMap & m
Definition: CachingVariable.h:51
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
VariableComputer::assign
void assign(std::string var, double &value) const
Definition: CachingVariable.cc:66
VarSplitter::useOverFlow_
bool useOverFlow_
Definition: CachingVariable.h:276
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
value
Definition: value.py:1
VarSplitter::var_
std::string var_
Definition: CachingVariable.h:274
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
VariableComputer::declare
void declare(std::string var, edm::ConsumesCollector &iC)
Definition: CachingVariable.cc:55
VariablePower::var_
std::string var_
Definition: CachingVariable.h:546
VariablePower::power_
double power_
Definition: CachingVariable.h:545
VariableComputer::name_
std::string name_
Definition: CachingVariable.h:138
VariableComputer::arg_
const CachingVariable::CachingVariableFactoryArg & arg_
Definition: CachingVariable.h:137
VarSplitter::eval
CachingVariable::evalType eval(const edm::Event &iEvent) const override
Definition: CachingVariable.cc:4
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
CachingVariable::evalType
std::pair< bool, valueType > evalType
Definition: CachingVariable.h:44
VariableHelper.h
ComputedVariable
Definition: CachingVariable.h:156
funct::arg
A arg
Definition: Factorize.h:31
CachingVariable::CachingVariableFactoryArg
Definition: CachingVariable.h:46
VariableComputerTest::VariableComputerTest
VariableComputerTest(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
Definition: CachingVariable.cc:101
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
edm::Event
Definition: Event.h:73
CachingVariable::CachingVariableFactoryArg::n
std::string & n
Definition: CachingVariable.h:50
CachingVariable::CachingVariableFactoryArg::iConfig
edm::ParameterSet & iConfig
Definition: CachingVariable.h:52
edm::Log
Definition: MessageLogger.h:70
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
VarSplitter::useUnderFlow_
bool useUnderFlow_
Definition: CachingVariable.h:275