1 #ifndef ConfigurableAnalysis_CachingVariable_H 2 #define ConfigurableAnalysis_CachingVariable_H 27 for (
unsigned int i = 0;
i != d_.size(); ++
i)
31 const std::vector<std::string>
lines() {
return d_; }
35 std::vector<std::string>
d_;
45 typedef std::map<std::string, const CachingVariable*>
vMap;
49 :
n(N),
m(M), iConfig(P) {}
56 : cache_(
std::make_pair(
false, 0)), method_(m), name_(n), conf_(iConfig) {}
91 if (notSeenThisEventAlready(iEvent)) {
92 LogDebug(
"CachingVariable") << name_ +
":" + holderName_ <<
" is checking once";
93 cache_ = eval(iEvent);
124 void doesNotCompute()
const;
140 mutable std::map<std::string, const ComputedVariable*>
iCompute_;
165 if (myComputer->notSeenThisEventAlready(iEvent))
166 myComputer->compute(iEvent);
190 unsigned int maxIndex()
const {
return maxSlots() - 1; }
193 virtual unsigned int maxSlots()
const {
return labels_.size(); }
196 if (i >= short_labels_.size()) {
197 edm::LogError(
"Splitter") <<
"trying to access slots short_label at index: " << i
198 <<
"while of size: " << short_labels_.size() <<
"\n" 200 return short_labels_.back();
202 return short_labels_[
i];
206 if (i >= labels_.size()) {
207 edm::LogError(
"Splitter") <<
"trying to access slots label at index: " << i <<
"while of size: " << labels_.size()
210 return labels_.back();
223 :
Splitter(
"VarSplitter", arg.
n, arg.iConfig, iC) {
229 labels_.push_back(
"underflow");
230 short_labels_.push_back(
"_" + arg.
n +
"_underflow");
232 std::vector<std::string> confLabels;
237 for (
unsigned int is = 0; is != slots_.size() - 1; ++is) {
238 std::string l(Form(labelFormat.c_str(), slots_[is], slots_[is + 1]));
239 confLabels.push_back(l);
242 for (
unsigned int i = 0;
i != confLabels.size(); ++
i) {
243 labels_.push_back(confLabels[
i]);
244 std::stringstream
ss;
245 ss <<
"_" << arg.
n <<
"_" <<
i;
246 short_labels_.push_back(ss.str());
249 labels_.push_back(
"overFlow");
250 short_labels_.push_back(
"_" + arg.
n +
"_overFlow");
254 if (labels_.size() != maxSlots())
255 edm::LogError(
"Splitter") <<
"splitter with name: " <<
name() <<
" has inconsistent configuration\n" 265 unsigned int s = slots_.size() - 1;
280 template <
typename Object, const
char* label>
294 addDescriptionLine(
"calculating: " + expr);
295 std::stringstream
ss;
296 ss <<
"on object at index: " << index_ <<
" of: " << srcTag_;
301 ss <<
" after sorting according to: " <<
order;
308 ss <<
" and selecting only: " <<
selection;
312 addDescriptionLine(ss.str());
317 std::map<std::string, edm::Entry> indexEntry;
318 if (arg.
n.find(
"_N") != std::string::npos) {
320 std::vector<unsigned int> indexes = arg.
iConfig.
getParameter<std::vector<unsigned int> >(
"indexes");
321 for (
unsigned int iI = 0; iI != indexes.size(); ++iI) {
324 std::stringstream
ss;
326 ss << indexes[iI] + 1;
327 indexEntry.insert(std::make_pair(ss.str(),
e));
331 std::map<std::string, edm::Entry> varEntry;
332 if (arg.
n.find(
"_V") != std::string::npos) {
335 for (
unsigned int v = 0;
v != vars.size(); ++
v) {
336 unsigned int sep = vars[
v].find(
":");
341 varEntry.insert(std::make_pair(name, e));
347 if (!varEntry.empty())
348 radical = radical.substr(0, radical.size() - 2);
350 if (!indexEntry.empty())
351 radical = radical.substr(0, radical.size() - 2);
353 if (varEntry.empty()) {
355 for (std::map<std::string, edm::Entry>::iterator iIt = indexEntry.begin(); iIt != indexEntry.end(); ++iIt) {
357 toUse.
insert(
true,
"index", iIt->second);
364 for (std::map<std::string, edm::Entry>::iterator vIt = varEntry.begin(); vIt != varEntry.end(); ++vIt) {
365 if (indexEntry.empty()) {
367 toUse.
insert(
true,
"expr", vIt->second);
373 for (std::map<std::string, edm::Entry>::iterator iIt = indexEntry.begin(); iIt != indexEntry.end(); ++iIt) {
375 toUse.
insert(
true,
"expr", vIt->second);
376 toUse.
insert(
true,
"index", iIt->second);
377 std::string newVname = radical + iIt->first + vIt->first;
403 return std::make_pair(
false, 0);
407 if (index_ >= oH->size()) {
408 LogDebug(
method()) <<
"fail to get object at index: " << index_ <<
" in collection: " << srcTag_;
409 return std::make_pair(
false, 0);
413 if (selector_ || forder_) {
414 std::vector<const Object*> copyToSort(0);
415 copyToSort.reserve(oH->size());
416 for (
unsigned int i = 0;
i != oH->size(); ++
i) {
417 if (selector_ && !((*selector_)((*oH)[
i])))
419 copyToSort.push_back(&(*oH)[i]);
421 if (index_ >= copyToSort.size())
422 return std::make_pair(
false, 0);
426 const Object*
o = copyToSort[index_];
427 return std::make_pair(
true, (*f_)(*o));
429 const Object&
o = (*oH)[index_];
430 return std::make_pair(
true, (*f_)(o));
443 template <
typename LHS, const
char* lLHS,
typename RHS, const
char* lRHS,
typename Calculator>
449 srcLhs_(iC.consumes<
std::vector<LHS> >(srcLhsTag_)),
450 indexLhs_(arg.iConfig.getParameter<unsigned
int>(
"indexLhs")),
452 srcRhs_(iC.consumes<
std::vector<RHS> >(srcRhsTag_)),
453 indexRhs_(arg.iConfig.getParameter<unsigned
int>(
"indexRhs")) {
454 std::stringstream
ss;
456 ss <<
"with Obj1 at index: " << indexLhs_ <<
" of: " << srcLhs_;
457 addDescriptionLine(ss.str());
459 ss <<
"with Obj2 at index: " << indexRhs_ <<
" of: " << srcRhs_;
460 addDescriptionLine(ss.str());
477 LogDebug(
"TwoObjectVariable") <<
name() <<
" could not get a collection with label: " << srcLhsTag_;
480 if (indexLhs_ >= lhsH->size()) {
481 LogDebug(
"TwoObjectVariable") <<
name() <<
" tries to access index: " << indexLhs_ <<
" of: " << srcLhsTag_
482 <<
" with: " << lhsH->size() <<
" entries.";
485 const LHS& lhs = (*lhsH)[indexLhs_];
490 LogDebug(
"TwoObjectVariable") <<
name() <<
" could not get a collection with label: " << srcLhsTag_;
494 if (indexRhs_ >= rhsH->size()) {
495 LogDebug(
"TwoObjectVariable") <<
name() <<
" tries to access index: " << indexRhs_ <<
" of: " << srcRhsTag_
496 <<
" with: " << rhsH->size() <<
" entries.";
499 const RHS& rhs = (*rhsH)[indexRhs_];
510 return calc(*o.
lhs, *o.
rhs);
515 return std::make_pair(
false, 0);
516 return std::make_pair(
true, calculate(o));
534 std::stringstream
ss(
"Calculare X^Y, with X=");
535 ss << var_ <<
" and Y=" << power_;
536 addDescriptionLine(ss.str());
549 template <
typename TYPE>
561 return std::make_pair(
false, 0);
563 return std::make_pair(
true, *value);
570 template <
typename TYPE>
576 index_(arg.iConfig.getParameter<unsigned
int>(
"index")) {
583 return std::make_pair(
false, 0);
584 else if (index_ >= values->size())
585 return std::make_pair(
false, 0);
587 return std::make_pair(
true, (*values)[index_]);
CachingVariable(std::string m, std::string n, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
unsigned long CacheIdentifier_t
const Description & description() const
~ExpressionVariable() override
evalType eval(const edm::Event &iEvent) const override
CachingVariable::evalType eval(const edm::Event &iEvent) const override
unsigned int maxSlots() const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< std::vector< LHS > > srcLhs_
const std::string & holderName() const
void setHolder(std::string hn) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
VarSplitter(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
StringCutObjectSelector< Object > * selector_
getObject objects(const edm::Event &iEvent) const
void insert(bool ok_to_replace, char const *, Entry const &)
std::vector< std::string > short_labels_
~ComputedVariable() override
valueType operator()(const edm::Event &iEvent) const
const CachingVariable::CachingVariableFactoryArg & arg_
VariablePower(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
std::vector< double > slots_
unsigned int maxIndex() const
virtual ~VariableComputer()
TwoObjectVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
edm::ParameterSet & iConfig
std::map< std::string, const ComputedVariable * > iCompute_
~VariablePower() override
const std::string shortLabel(unsigned int i) const
StringObjectFunction< Object > * f_
evalType & baseEval(const edm::Event &iEvent) const
virtual unsigned int maxSlots() const
virtual ~CachingVariable()
CacheIdentifier_t cacheIdentifier() const
void addDescriptionLine(const std::string &s)
const std::string & label(unsigned int i) const
Description(std::vector< std::string > &d)
edm::EDGetTokenT< TYPE > src_
void assign(const std::vector< float > &vec, float &a, float &b, float &c, float &d)
void setNotCompute() const
edm::EDGetTokenT< edm::View< Object > > src_
SimpleValueVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
CachingVariable::evalType eval(const edm::Event &iEvent) const override
CachingVariable::vMap & m
SimpleValueVectorVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
StringObjectFunction< Object > * forder_
std::vector< std::string > d_
CachingVariable::evalType eval(const edm::Event &iEvent) const override
std::unique_ptr< const VariableComputer > myComputer
Splitter(std::string method, std::string n, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
std::pair< OmniClusterRef, TrackingParticleRef > P
std::vector< std::string > labels_
edm::EDGetTokenT< TYPE > src_
const std::vector< std::string > lines()
bool compute(const edm::Event &iEvent) const
ExpressionVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
void addLine(const std::string &l)
virtual evalType eval(const edm::Event &iEvent) const
bool notSeenThisEventAlready(const edm::Event &iEvent) const
~VariableComputerTest() override
CachingVariableFactoryArg(std::string &N, CachingVariable::vMap &M, edm::ParameterSet &P)
CachingVariableFactoryArg(const CachingVariableFactoryArg ©)
CachingVariable::evalType eval(const edm::Event &iEvent) const override
const std::string & name() const
const std::string & name() const
edm::EDGetTokenT< std::vector< RHS > > srcRhs_
ComputedVariable(const std::string &M, std::string &N, edm::ParameterSet &P, const VariableComputer *c, edm::ConsumesCollector &iC)
void setCache(valueType &v) const
std::map< std::string, const CachingVariable * > vMap
const std::string & method() const
std::pair< bool, valueType > evalType
bool notSeenThisEventAlready(const edm::Event &iEvent) const
virtual CachingVariable::valueType calculate(getObject &o) const