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_;}
34 std::vector<std::string>
d_;
44 typedef std::map<std::string, const CachingVariable*>
vMap;
54 cache_(
std::make_pair(
false,0)),method_(m),
55 name_(n),conf_(iConfig) {}
85 cache_.first=
true; cache_.second =
v;}
87 cache_.first=
false; cache_.second = 0;}
89 if(notSeenThisEventAlready(iEvent)) {
90 LogDebug(
"CachingVariable")<<name_+
":"+holderName_<<
" is checking once";
123 void doesNotCompute()
const;
139 mutable std::map<std::string ,const ComputedVariable *>
iCompute_;
161 if (myComputer->notSeenThisEventAlready(iEvent))
162 myComputer->compute(iEvent);
185 unsigned int maxIndex()
const {
return maxSlots()-1;}
188 virtual unsigned int maxSlots()
const {
return labels_.size();}
191 if (i>=short_labels_.size()){
192 edm::LogError(
"Splitter")<<
"trying to access slots short_label at index: "<<i<<
"while of size: "<<short_labels_.size()<<
"\n"<<conf_.dump();
193 return short_labels_.back(); }
194 else return short_labels_[
i];}
197 if (i>=labels_.size()){
198 edm::LogError(
"Splitter")<<
"trying to access slots label at index: "<<i<<
"while of size: "<<labels_.size()<<
"\n"<<conf_.dump();
199 return labels_.back(); }
200 else return labels_[
i];}
211 Splitter(
"VarSplitter",arg.
n,arg.iConfig,iC) {
217 labels_.push_back(
"underflow");
218 short_labels_.push_back(
"_"+arg.
n+
"_underflow");}
219 std::vector<std::string> confLabels;
225 for (
unsigned int is=0;is!=slots_.size()-1;++is){
226 std::string l(Form(labelFormat.c_str(),slots_[is],slots_[is+1]));
227 confLabels.push_back(l);
230 for (
unsigned int i=0;
i!=confLabels.size();++
i){
231 labels_.push_back(confLabels[
i]);
232 std::stringstream ss;
233 ss<<
"_"<<arg.
n<<
"_"<<
i;
234 short_labels_.push_back(ss.str());
237 { labels_.push_back(
"overFlow");
238 short_labels_.push_back(
"_"+arg.
n+
"_overFlow");}
241 if (labels_.size()!=maxSlots())
242 edm::LogError(
"Splitter")<<
"splitter with name: "<<
name()<<
" has inconsistent configuration\n"<<conf_.dump();
251 unsigned int s=slots_.size()-1;
252 if (useUnderFlow_) s++;
253 if (useOverFlow_) s++;
263 template <
typename Object, const
char * label>
275 addDescriptionLine(
"calculating: "+expr);
276 std::stringstream ss;
277 ss<<
"on object at index: "<<index_<<
" of: "<<srcTag_;
282 ss<<
" after sorting according to: "<<order;
293 addDescriptionLine(ss.str()); ss.str(
"");
298 std::map<std::string, edm::Entry> indexEntry;
299 if (arg.
n.find(
"_N")!=std::string::npos){
301 std::vector<unsigned int> indexes = arg.
iConfig.
getParameter<std::vector<unsigned int> >(
"indexes");
302 for (
unsigned int iI=0;iI!=indexes.size();++iI){
305 std::stringstream ss;
308 indexEntry.insert(std::make_pair(ss.str(),
e));
312 std::map< std::string, edm::Entry> varEntry;
313 if (arg.
n.find(
"_V")!=std::string::npos){
315 std::vector<std::string> vars = arg.
iConfig.
getParameter<std::vector<std::string> >(
"vars");
316 for (
unsigned int v=0;
v!=vars.size();++
v){
317 unsigned int sep=vars[
v].find(
":");
322 varEntry.insert(std::make_pair(name,e));
328 if (!varEntry.empty())
329 radical = radical.substr(0,radical.size()-2);
331 if (!indexEntry.empty())
332 radical = radical.substr(0,radical.size()-2);
334 if(varEntry.empty()){
336 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
338 toUse.
insert(
true,
"index",iIt->second);
345 for (std::map< std::string, edm::Entry>::iterator vIt=varEntry.begin();vIt!=varEntry.end();++vIt){
346 if (indexEntry.empty()){
348 toUse.
insert(
true,
"expr",vIt->second);
354 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
356 toUse.
insert(
true,
"expr",vIt->second);
357 toUse.
insert(
true,
"index",iIt->second);
358 std::string newVname = radical+iIt->first+vIt->first;
373 if (forder_)
delete forder_;
374 if (selector_)
delete selector_;
380 return std::make_pair(
false,0);
384 if (index_>=oH->size()){
385 LogDebug(
method())<<
"fail to get object at index: "<<index_<<
" in collection: "<<srcTag_;
386 return std::make_pair(
false,0);
390 if (selector_ || forder_){
391 std::vector<const Object*> copyToSort(0);
392 copyToSort.reserve(oH->size());
393 for (
unsigned int i=0;
i!=oH->size();++
i){
394 if (selector_ && !((*selector_)((*oH)[
i])))
continue;
395 copyToSort.push_back(&(*oH)[i]);
397 if (index_ >= copyToSort.size())
return std::make_pair(
false,0);
400 const Object *
o = copyToSort[index_];
401 return std::make_pair(
true,(*f_)(*o));
404 const Object &
o = (*oH)[index_];
405 return std::make_pair(
true,(*f_)(o));
419 template<
typename LHS,const
char * lLHS,
typename RHS,const
char * lRHS,
typename Calculator>
425 srcLhs_(iC.consumes<
std::vector<LHS> >(srcLhsTag_)),
426 indexLhs_(arg.iConfig.getParameter<unsigned
int>(
"indexLhs")),
428 srcRhs_(iC.consumes<
std::vector<RHS> >(srcRhsTag_)),
429 indexRhs_(arg.iConfig.getParameter<unsigned
int>(
"indexRhs"))
431 std::stringstream ss;
433 ss<<
"with Obj1 at index: "<<indexLhs_<<
" of: "<<srcLhs_;
434 addDescriptionLine(ss.str()); ss.str(
"");
435 ss<<
"with Obj2 at index: "<<indexRhs_<<
" of: "<<srcRhs_;
436 addDescriptionLine(ss.str()); ss.str(
"");
452 LogDebug(
"TwoObjectVariable")<<
name()<<
" could not get a collection with label: "<<srcLhsTag_;
454 if (indexLhs_>=lhsH->size()){
455 LogDebug(
"TwoObjectVariable")<<
name()<<
" tries to access index: "<<indexLhs_<<
" of: "<<srcLhsTag_<<
" with: "<<lhsH->size()<<
" entries.";
457 const LHS & lhs = (*lhsH)[indexLhs_];
462 LogDebug(
"TwoObjectVariable")<<
name()<<
" could not get a collection with label: "<<srcLhsTag_;
465 if (indexRhs_>=rhsH->size()){
466 LogDebug(
"TwoObjectVariable")<<
name()<<
" tries to access index: "<<indexRhs_<<
" of: "<<srcRhsTag_<<
" with: "<<rhsH->size()<<
" entries.";
468 const RHS & rhs = (*rhsH)[indexRhs_];
479 return calc(*o.
lhs,*o.
rhs);
483 if (!o.
test)
return std::make_pair(
false,0);
484 return std::make_pair(
true,calculate(o));
502 std::stringstream ss(
"Calculare X^Y, with X=");
503 ss<<var_<<
" and Y="<<power_;
504 addDescriptionLine(ss.str());
518 template <
typename TYPE>
527 catch(...){
return std::make_pair(
false,0); }
529 else return std::make_pair(
true, *value);
535 template <
typename TYPE>
541 index_(arg.iConfig.getParameter<unsigned
int>(
"index")) { arg.
m[arg.
n]=
this;}
545 catch(...){
return std::make_pair(
false,0); }
547 else if (index_>=values->size())
return std::make_pair(
false,0);
548 else return std::make_pair(
true, (*values)[index_]);
CachingVariable(std::string m, std::string n, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
CachingVariable::evalType eval(const edm::Event &iEvent) const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
unsigned long CacheIdentifier_t
const Description & description() const
CachingVariable::evalType eval(const edm::Event &iEvent) const
virtual evalType eval(const edm::Event &iEvent) const
unsigned int maxSlots() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const VariableComputer * myComputer
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
edmplugin::PluginFactory< CachingVariable *(CachingVariable::CachingVariableFactoryArg, edm::ConsumesCollector &iC) > CachingVariableFactory
void insert(bool ok_to_replace, char const *, Entry const &)
std::vector< std::string > short_labels_
edmplugin::PluginFactory< VariableComputer *(CachingVariable::CachingVariableFactoryArg, edm::ConsumesCollector &iC) > VariableComputerFactory
CachingVariable::evalType eval(const edm::Event &iEvent) const
valueType operator()(const edm::Event &iEvent) const
CachingVariable::evalType eval(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 ~ComputedVariable()
virtual ~VariableComputer()
TwoObjectVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
edm::ParameterSet & iConfig
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)
std::map< std::string,const ComputedVariable * > iCompute_
CachingVariable::vMap & m
SimpleValueVectorVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
StringObjectFunction< Object > * forder_
std::vector< std::string > d_
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
CachingVariableFactoryArg(std::string &N, CachingVariable::vMap &M, edm::ParameterSet &P)
CachingVariableFactoryArg(const CachingVariableFactoryArg ©)
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