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++;
268 bool operator() (
const Object *
o1,
const Object * o2) {
269 return (*f_)(*o1) > (*f_)(*o2);
275 template <
typename Object, const
char * label>
287 addDescriptionLine(
"calculating: "+expr);
288 std::stringstream ss;
289 ss<<
"on object at index: "<<index_<<
" of: "<<srcTag_;
294 ss<<
" after sorting according to: "<<order;
305 addDescriptionLine(ss.str()); ss.str(
"");
310 std::map<std::string, edm::Entry> indexEntry;
311 if (arg.
n.find(
"_N")!=std::string::npos){
313 std::vector<unsigned int> indexes = arg.
iConfig.
getParameter<std::vector<unsigned int> >(
"indexes");
314 for (
unsigned int iI=0;iI!=indexes.size();++iI){
317 std::stringstream ss;
320 indexEntry.insert(std::make_pair(ss.str(),
e));
324 std::map< std::string, edm::Entry> varEntry;
325 if (arg.
n.find(
"_V")!=std::string::npos){
327 std::vector<std::string> vars = arg.
iConfig.
getParameter<std::vector<std::string> >(
"vars");
328 for (
unsigned int v=0;
v!=vars.size();++
v){
329 unsigned int sep=vars[
v].find(
":");
334 varEntry.insert(std::make_pair(name,e));
340 if (!varEntry.empty())
341 radical = radical.substr(0,radical.size()-2);
343 if (!indexEntry.empty())
344 radical = radical.substr(0,radical.size()-2);
346 if(varEntry.empty()){
348 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
350 toUse.
insert(
true,
"index",iIt->second);
357 for (std::map< std::string, edm::Entry>::iterator vIt=varEntry.begin();vIt!=varEntry.end();++vIt){
358 if (indexEntry.empty()){
360 toUse.
insert(
true,
"expr",vIt->second);
366 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
368 toUse.
insert(
true,
"expr",vIt->second);
369 toUse.
insert(
true,
"index",iIt->second);
370 std::string newVname = radical+iIt->first+vIt->first;
385 if (forder_)
delete forder_;
386 if (selector_)
delete selector_;
392 return std::make_pair(
false,0);
396 if (index_>=oH->size()){
397 LogDebug(
method())<<
"fail to get object at index: "<<index_<<
" in collection: "<<srcTag_;
398 return std::make_pair(
false,0);
402 if (selector_ || forder_){
403 std::vector<const Object*> copyToSort(0);
404 copyToSort.reserve(oH->size());
405 for (
unsigned int i=0;
i!=oH->size();++
i){
406 if (selector_ && !((*selector_)((*oH)[
i])))
continue;
407 copyToSort.push_back(&(*oH)[i]);
409 if (index_ >= copyToSort.size())
return std::make_pair(
false,0);
412 const Object *
o = copyToSort[index_];
413 return std::make_pair(
true,(*f_)(*o));
416 const Object &
o = (*oH)[index_];
417 return std::make_pair(
true,(*f_)(o));
431 template<
typename LHS,const
char * lLHS,
typename RHS,const
char * lRHS,
typename Calculator>
437 srcLhs_(iC.consumes<
std::vector<LHS> >(srcLhsTag_)),
438 indexLhs_(arg.iConfig.getParameter<unsigned
int>(
"indexLhs")),
440 srcRhs_(iC.consumes<
std::vector<RHS> >(srcRhsTag_)),
441 indexRhs_(arg.iConfig.getParameter<unsigned
int>(
"indexRhs"))
443 std::stringstream ss;
445 ss<<
"with Obj1 at index: "<<indexLhs_<<
" of: "<<srcLhs_;
446 addDescriptionLine(ss.str()); ss.str(
"");
447 ss<<
"with Obj2 at index: "<<indexRhs_<<
" of: "<<srcRhs_;
448 addDescriptionLine(ss.str()); ss.str(
"");
464 LogDebug(
"TwoObjectVariable")<<
name()<<
" could not get a collection with label: "<<srcLhsTag_;
466 if (indexLhs_>=lhsH->size()){
467 LogDebug(
"TwoObjectVariable")<<
name()<<
" tries to access index: "<<indexLhs_<<
" of: "<<srcLhsTag_<<
" with: "<<lhsH->size()<<
" entries.";
469 const LHS & lhs = (*lhsH)[indexLhs_];
474 LogDebug(
"TwoObjectVariable")<<
name()<<
" could not get a collection with label: "<<srcLhsTag_;
477 if (indexRhs_>=rhsH->size()){
478 LogDebug(
"TwoObjectVariable")<<
name()<<
" tries to access index: "<<indexRhs_<<
" of: "<<srcRhsTag_<<
" with: "<<rhsH->size()<<
" entries.";
480 const RHS & rhs = (*rhsH)[indexRhs_];
491 return calc(*o.
lhs,*o.
rhs);
495 if (!o.
test)
return std::make_pair(
false,0);
496 return std::make_pair(
true,calculate(o));
514 std::stringstream ss(
"Calculare X^Y, with X=");
515 ss<<var_<<
" and Y="<<power_;
516 addDescriptionLine(ss.str());
530 template <
typename TYPE>
539 catch(...){
return std::make_pair(
false,0); }
541 else return std::make_pair(
true, *value);
547 template <
typename TYPE>
553 index_(arg.iConfig.getParameter<unsigned
int>(
"index")) { arg.
m[arg.
n]=
this;}
557 catch(...){
return std::make_pair(
false,0); }
559 else if (index_>=values->size())
return std::make_pair(
false,0);
560 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)
StringObjectFunction< Object > * f_
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
sortByStringFunction(StringObjectFunction< Object > *f)
bool notSeenThisEventAlready(const edm::Event &iEvent) const
virtual CachingVariable::valueType calculate(getObject &o) const