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;
139 mutable std::map<std::string ,const ComputedVariable *>
iCompute_;
211 Splitter(
"VarSplitter",arg.
n,arg.iConfig,iC) {
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>
288 std::stringstream
ss;
289 ss<<
"on object at index: "<<index_<<
" of: "<<
srcTag_;
294 ss<<
" after sorting according to: "<<order;
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;
392 return std::make_pair(
false,0);
398 return std::make_pair(
false,0);
403 std::vector<const Object*> copyToSort(0);
404 copyToSort.reserve(oH->size());
405 for (
unsigned int i=0;
i!=oH->size();++
i){
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>
438 indexLhs_(arg.iConfig.getParameter<unsigned int>(
"indexLhs")),
441 indexRhs_(arg.iConfig.getParameter<unsigned int>(
"indexRhs"))
443 std::stringstream
ss;
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_;
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
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 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