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;
140 mutable std::map<std::string ,const ComputedVariable *>
iCompute_;
212 Splitter(
"VarSplitter",arg.
n,arg.iConfig,iC) {
218 labels_.push_back(
"underflow");
220 std::vector<std::string> confLabels;
226 for (
unsigned int is=0;is!=slots_.size()-1;++is){
227 std::string l(Form(labelFormat.c_str(),slots_[is],slots_[is+1]));
228 confLabels.push_back(l);
231 for (
unsigned int i=0;
i!=confLabels.size();++
i){
233 std::stringstream
ss;
234 ss<<
"_"<<arg.
n<<
"_"<<
i;
238 {
labels_.push_back(
"overFlow");
252 unsigned int s=
slots_.size()-1;
270 return (*
f_)(*o1) > (*f_)(*o2);
276 template <
typename Object, const
char * label>
289 std::stringstream
ss;
290 ss<<
"on object at index: "<<index_<<
" of: "<<
srcTag_;
295 ss<<
" after sorting according to: "<<order;
311 std::map<std::string, edm::Entry> indexEntry;
312 if (arg.
n.find(
"_N")!=std::string::npos){
314 std::vector<unsigned int> indexes = arg.
iConfig.
getParameter<std::vector<unsigned int> >(
"indexes");
315 for (
unsigned int iI=0;iI!=indexes.size();++iI){
318 std::stringstream
ss;
321 indexEntry.insert(std::make_pair(ss.str(),
e));
325 std::map< std::string, edm::Entry> varEntry;
326 if (arg.
n.find(
"_V")!=std::string::npos){
328 std::vector<std::string> vars = arg.
iConfig.
getParameter<std::vector<std::string> >(
"vars");
329 for (
unsigned int v=0;
v!=vars.size();++
v){
330 unsigned int sep=vars[
v].find(
":");
335 varEntry.insert(std::make_pair(name,e));
341 if (!varEntry.empty())
342 radical = radical.substr(0,radical.size()-2);
344 if (!indexEntry.empty())
345 radical = radical.substr(0,radical.size()-2);
347 if(varEntry.empty()){
349 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
351 toUse.
insert(
true,
"index",iIt->second);
358 for (std::map< std::string, edm::Entry>::iterator vIt=varEntry.begin();vIt!=varEntry.end();++vIt){
359 if (indexEntry.empty()){
361 toUse.
insert(
true,
"expr",vIt->second);
367 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
369 toUse.
insert(
true,
"expr",vIt->second);
370 toUse.
insert(
true,
"index",iIt->second);
371 std::string newVname = radical+iIt->first+vIt->first;
393 return std::make_pair(
false,0);
399 return std::make_pair(
false,0);
404 std::vector<const Object*> copyToSort(0);
405 copyToSort.reserve(oH->size());
406 for (
unsigned int i=0;
i!=oH->size();++
i){
408 copyToSort.push_back(&(*oH)[i]);
410 if (
index_ >= copyToSort.size())
return std::make_pair(
false,0);
413 const Object *
o = copyToSort[
index_];
414 return std::make_pair(
true,(*
f_)(*o));
417 const Object &
o = (*oH)[
index_];
418 return std::make_pair(
true,(*
f_)(o));
432 template<
typename LHS,const
char * lLHS,
typename RHS,const
char * lRHS,
typename Calculator>
439 indexLhs_(arg.iConfig.getParameter<unsigned int>(
"indexLhs")),
442 indexRhs_(arg.iConfig.getParameter<unsigned int>(
"indexRhs"))
444 std::stringstream
ss;
492 return calc(*o.
lhs,*o.
rhs);
496 if (!o.
test)
return std::make_pair(
false,0);
497 return std::make_pair(
true,
calculate(o));
515 std::stringstream
ss(
"Calculare X^Y, with X=");
516 ss<<var_<<
" and Y="<<
power_;
531 template <
typename TYPE>
540 catch(...){
return std::make_pair(
false,0); }
542 else return std::make_pair(
true, *value);
548 template <
typename TYPE>
554 index_(arg.iConfig.getParameter<unsigned int>(
"index")) { arg.
m[arg.
n]=
this;}
558 catch(...){
return std::make_pair(
false,0); }
560 else if (
index_>=values->size())
return std::make_pair(
false,0);
561 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
virtual CachingVariable::evalType eval(const edm::Event &iEvent) const =0
CachingVariable::evalType eval(const edm::Event &iEvent) const
virtual evalType eval(const edm::Event &iEvent) const
unsigned int maxSlots() const
ComputedVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
std::string dump(unsigned int indent=0) 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
VariableComputer(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
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_
CachingVariable::evalType eval(const edm::Event &iEvent) const
edmplugin::PluginFactory< VariableComputer *(CachingVariable::CachingVariableFactoryArg, edm::ConsumesCollector &iC) > VariableComputerFactory
CachingVariable::evalType eval(const edm::Event &iEvent) const
edm::Event::CacheIdentifier_t eventCacheID_
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()
void assign(std::string var, double &value) const
TwoObjectVariable(const CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
edm::ParameterSet & iConfig
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)
edm::EDGetTokenT< TYPE > src_
VariableComputerTest(const CachingVariable::CachingVariableFactoryArg &arg, edm::ConsumesCollector &iC)
void setNotCompute() const
edm::EDGetTokenT< edm::View< Object > > src_
edm::Event::CacheIdentifier_t eventCacheID_
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_
bool operator()(const Object *o1, const Object *o2)
Splitter(std::string method, std::string n, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
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 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
void declare(std::string var, edm::ConsumesCollector &iC)
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