1 #ifndef ConfigurableAnalysis_CachingVariable_H
2 #define ConfigurableAnalysis_CachingVariable_H
26 for (
unsigned int i=0;
i!=
d_.size();++
i)
30 const std::vector<std::string>
lines(){
return d_;}
33 std::vector<std::string>
d_;
43 typedef std::map<std::string, const CachingVariable*>
vMap;
139 mutable std::map<std::string ,const ComputedVariable *>
iCompute_;
211 Splitter(
"VarSplitter",arg.
n,arg.iConfig) {
217 labels_.push_back(
"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){
232 std::stringstream ss;
233 ss<<
"_"<<arg.
n<<
"_"<<
i;
237 {
labels_.push_back(
"overFlow");
251 unsigned int s=
slots_.size()-1;
269 return (*
f_)(*o1) > (*f_)(*o2);
275 template <
typename Object, const
char * label>
287 std::stringstream ss;
288 ss<<
"on object at index: "<<index_<<
" of: "<<
src_;
293 ss<<
" after sorting according to: "<<order;
309 std::map<std::string, edm::Entry> indexEntry;
310 if (arg.
n.find(
"_N")!=std::string::npos){
312 std::vector<unsigned int> indexes = arg.
iConfig.
getParameter<std::vector<unsigned int> >(
"indexes");
313 for (
unsigned int iI=0;iI!=indexes.size();++iI){
316 std::stringstream ss;
319 indexEntry.insert(std::make_pair(ss.str(),
e));
323 std::map< std::string, edm::Entry> varEntry;
324 if (arg.
n.find(
"_V")!=std::string::npos){
326 std::vector<std::string> vars = arg.
iConfig.
getParameter<std::vector<std::string> >(
"vars");
327 for (
unsigned int v=0;
v!=vars.size();++
v){
328 unsigned int sep=vars[
v].find(
":");
333 varEntry.insert(std::make_pair(name,e));
339 if (!varEntry.empty())
340 radical = radical.substr(0,radical.size()-2);
342 if (!indexEntry.empty())
343 radical = radical.substr(0,radical.size()-2);
345 if(varEntry.empty()){
347 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
349 toUse.
insert(
true,
"index",iIt->second);
356 for (std::map< std::string, edm::Entry>::iterator vIt=varEntry.begin();vIt!=varEntry.end();++vIt){
357 if (indexEntry.empty()){
359 toUse.
insert(
true,
"expr",vIt->second);
365 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
367 toUse.
insert(
true,
"expr",vIt->second);
368 toUse.
insert(
true,
"index",iIt->second);
369 std::string newVname = radical+iIt->first+vIt->first;
391 return std::make_pair(
false,0);
397 return std::make_pair(
false,0);
402 std::vector<const Object*> copyToSort(0);
403 copyToSort.reserve(oH->size());
404 for (
unsigned int i=0;
i!=oH->size();++
i){
406 copyToSort.push_back(&(*oH)[i]);
408 if (
index_ >= copyToSort.size())
return std::make_pair(
false,0);
411 const Object *
o = copyToSort[
index_];
412 return std::make_pair(
true,(*
f_)(*o));
415 const Object &
o = (*oH)[
index_];
416 return std::make_pair(
true,(*
f_)(o));
429 template<
typename LHS,const
char * lLHS,
typename RHS,const
char * lRHS,
typename Calculator>
435 indexLhs_(arg.iConfig.getParameter<unsigned int>(
"indexLhs")),
437 indexRhs_(arg.iConfig.getParameter<unsigned int>(
"indexRhs"))
439 std::stringstream ss;
460 LogDebug(
"TwoObjectVariable")<<
name()<<
" could not get a collection with label: "<<
srcLhs_;
470 LogDebug(
"TwoObjectVariable")<<
name()<<
" could not get a collection with label: "<<
srcLhs_;
487 return calc(*o.
lhs,*o.
rhs);
491 if (!o.
test)
return std::make_pair(
false,0);
492 return std::make_pair(
true,
calculate(o));
508 std::stringstream ss(
"Calculare X^Y, with X=");
509 ss<<var_<<
" and Y="<<
power_;
524 template <
typename TYPE>
533 catch(...){
return std::make_pair(
false,0); }
535 else return std::make_pair(
true, *value);
541 template <
typename TYPE>
547 index_(arg.iConfig.getParameter<unsigned int>(
"index")) { arg.
m[arg.
n]=
this;}
551 catch(...){
return std::make_pair(
false,0); }
553 else if (
index_>=values->size())
return std::make_pair(
false,0);
554 else return std::make_pair(
true, (*values)[
index_]);
ComputedVariable(const std::string &M, std::string &N, edm::ParameterSet &P, const VariableComputer *c)
CachingVariable::evalType eval(const edm::Event &iEvent) const
T getParameter(std::string const &) const
unsigned long CacheIdentifier_t
const Description & description() const
virtual CachingVariable::evalType eval(const edm::Event &iEvent) const =0
ComputedVariable(const CachingVariableFactoryArg &arg)
CachingVariable::evalType eval(const edm::Event &iEvent) const
virtual evalType eval(const edm::Event &iEvent) const
unsigned int maxSlots() const
std::string dump(unsigned int indent=0) const
const VariableComputer * myComputer
VariableComputerTest(const CachingVariable::CachingVariableFactoryArg &arg)
edmplugin::PluginFactory< CachingVariable *(CachingVariable::CachingVariableFactoryArg) > CachingVariableFactory
const std::string & holderName() const
VariablePower(const CachingVariableFactoryArg &arg)
void setHolder(std::string hn) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
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_
CachingVariable::evalType eval(const edm::Event &iEvent) const
CachingVariable::evalType eval(const edm::Event &iEvent) const
VarSplitter(const CachingVariableFactoryArg &arg)
edmplugin::PluginFactory< VariableComputer *(CachingVariable::CachingVariableFactoryArg) > VariableComputerFactory
edm::Event::CacheIdentifier_t eventCacheID_
valueType operator()(const edm::Event &iEvent) const
CachingVariable::evalType eval(const edm::Event &iEvent) const
const CachingVariable::CachingVariableFactoryArg & arg_
std::vector< double > slots_
unsigned int maxIndex() const
virtual ~ComputedVariable()
virtual ~VariableComputer()
void assign(std::string var, double &value) const
edm::ParameterSet & iConfig
SimpleValueVectorVariable(const CachingVariableFactoryArg &arg)
const T & max(const T &a, const T &b)
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)
void setNotCompute() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
VariableComputer(const CachingVariable::CachingVariableFactoryArg &arg)
Splitter(std::string method, std::string n, const edm::ParameterSet &iConfig)
edm::Event::CacheIdentifier_t eventCacheID_
std::map< std::string,const ComputedVariable * > iCompute_
ExpressionVariable(const CachingVariableFactoryArg &arg)
CachingVariable::vMap & m
StringObjectFunction< Object > * forder_
std::vector< std::string > d_
bool operator()(const Object *o1, const Object *o2)
std::vector< std::string > labels_
const std::vector< std::string > lines()
bool compute(const edm::Event &iEvent) const
void addLine(const std::string &l)
virtual void compute(const edm::Event &iEvent) const =0
virtual evalType eval(const edm::Event &iEvent) const
CachingVariable::evalType eval(const edm::Event &iEvent) const
bool notSeenThisEventAlready(const edm::Event &iEvent) const
void doesNotCompute() const
void compute(const edm::Event &iEvent) const
volatile std::atomic< bool > shutdown_flag false
CachingVariable(std::string m, std::string n, const edm::ParameterSet &iConfig)
CachingVariableFactoryArg(std::string &N, CachingVariable::vMap &M, edm::ParameterSet &P)
StringObjectFunction< Object > * f_
CachingVariableFactoryArg(const CachingVariableFactoryArg ©)
TwoObjectVariable(const CachingVariableFactoryArg &arg)
const std::string & name() const
const std::string & name() const
SimpleValueVariable(const CachingVariableFactoryArg &arg)
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)
void declare(std::string var)
bool notSeenThisEventAlready(const edm::Event &iEvent) const
virtual CachingVariable::valueType calculate(getObject &o) const