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;
114 void assign(std::string var,
double &
value)
const;
122 mutable std::map<std::string ,const ComputedVariable *>
iCompute_;
176 const std::string &
label(
unsigned int i)
const{
191 Splitter(
"VarSplitter",arg.
n,arg.iConfig) {
197 labels_.push_back(
"underflow");
199 std::vector<std::string> confLabels;
205 for (
unsigned int is=0;is!=slots_.size()-1;++is){
206 std::string
l(Form(labelFormat.c_str(),slots_[is],slots_[is+1]));
207 confLabels.push_back(l);
210 for (
unsigned int i=0;
i!=confLabels.size();++
i){
212 std::stringstream ss;
213 ss<<
"_"<<arg.
n<<
"_"<<
i;
217 {
labels_.push_back(
"overFlow");
231 unsigned int s=
slots_.size()-1;
249 return (*
f_)(*o1) > (*f_)(*o2);
255 template <
typename Object, const
char * label>
267 std::stringstream ss;
268 ss<<
"on object at index: "<<index_<<
" of: "<<
src_;
273 ss<<
" after sorting according to: "<<order;
289 std::map<std::string, edm::Entry> indexEntry;
290 if (arg.
n.find(
"_N")!=std::string::npos){
292 std::vector<unsigned int> indexes = arg.
iConfig.
getParameter<std::vector<unsigned int> >(
"indexes");
293 for (
unsigned int iI=0;iI!=indexes.size();++iI){
296 std::stringstream ss;
299 indexEntry.insert(std::make_pair(ss.str(),
e));
303 std::map< std::string, edm::Entry> varEntry;
304 if (arg.
n.find(
"_V")!=std::string::npos){
306 std::vector<std::string> vars = arg.
iConfig.
getParameter<std::vector<std::string> >(
"vars");
307 for (
unsigned int v=0;
v!=vars.size();++
v){
308 unsigned int sep=vars[
v].find(
":");
309 std::string
name=vars[
v].substr(0,sep);
310 std::string expr=vars[
v].substr(sep+1);
313 varEntry.insert(std::make_pair(name,e));
317 std::string radical = arg.
n;
319 if (!varEntry.empty())
320 radical = radical.substr(0,radical.size()-2);
322 if (!indexEntry.empty())
323 radical = radical.substr(0,radical.size()-2);
325 if(varEntry.empty()){
327 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
329 toUse.
insert(
true,
"index",iIt->second);
330 std::string newVname = radical+iIt->first;
336 for (std::map< std::string, edm::Entry>::iterator vIt=varEntry.begin();vIt!=varEntry.end();++vIt){
337 if (indexEntry.empty()){
339 toUse.
insert(
true,
"expr",vIt->second);
340 std::string newVname = radical+vIt->first;
345 for(std::map< std::string, edm::Entry>::iterator iIt=indexEntry.begin();iIt!=indexEntry.end();++iIt){
347 toUse.
insert(
true,
"expr",vIt->second);
348 toUse.
insert(
true,
"index",iIt->second);
349 std::string newVname = radical+iIt->first+vIt->first;
371 return std::make_pair(
false,0);
377 return std::make_pair(
false,0);
382 std::vector<const Object*> copyToSort(0);
383 copyToSort.reserve(oH->size());
384 for (
unsigned int i=0;
i!=oH->size();++
i){
386 copyToSort.push_back(&(*oH)[i]);
388 if (
index_ >= copyToSort.size())
return std::make_pair(
false,0);
391 const Object *
o = copyToSort[
index_];
392 return std::make_pair(
true,(*
f_)(*o));
395 const Object &
o = (*oH)[
index_];
396 return std::make_pair(
true,(*
f_)(o));
409 template<
typename LHS,const
char * lLHS,
typename RHS,const
char * lRHS,
typename Calculator>
413 CachingVariable(Calculator::calculationType()+std::string(lLHS)+std::string(lRHS),arg.
n,arg.iConfig),
415 indexLhs_(arg.iConfig.getParameter<unsigned int>(
"indexLhs")),
417 indexRhs_(arg.iConfig.getParameter<unsigned int>(
"indexRhs"))
419 std::stringstream ss;
440 LogDebug(
"TwoObjectVariable")<<
name()<<
" could not get a collection with label: "<<
srcLhs_;
450 LogDebug(
"TwoObjectVariable")<<
name()<<
" could not get a collection with label: "<<
srcLhs_;
467 return calc(*o.
lhs,*o.
rhs);
471 if (!o.
test)
return std::make_pair(
false,0);
472 return std::make_pair(
true,
calculate(o));
488 std::stringstream ss(
"Calculare X^Y, with X=");
489 ss<<var_<<
" and Y="<<
power_;
504 template <
typename TYPE>
513 catch(...){
return std::make_pair(
false,0); }
515 else return std::make_pair(
true, *value);
521 template <
typename TYPE>
527 index_(arg.iConfig.getParameter<unsigned int>(
"index")) { arg.
m[arg.
n]=
this;}
531 catch(...){
return std::make_pair(
false,0); }
533 else if (
index_>=values->size())
return std::make_pair(
false,0);
534 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
const Description & description() const
virtual CachingVariable::evalType eval(const edm::Event &iEvent) const =0
VarSplitter(CachingVariableFactoryArg arg)
CachingVariable::evalType eval(const edm::Event &iEvent) const
virtual evalType eval(const edm::Event &iEvent) const
unsigned int maxSlots() const
const VariableComputer * myComputer
edmplugin::PluginFactory< CachingVariable *(CachingVariable::CachingVariableFactoryArg) > CachingVariableFactory
const std::string & holderName() const
ExpressionVariable(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
edmplugin::PluginFactory< VariableComputer *(CachingVariable::CachingVariableFactoryArg) > VariableComputerFactory
valueType operator()(const edm::Event &iEvent) const
CachingVariable::evalType eval(const edm::Event &iEvent) const
std::vector< double > slots_
unsigned int maxIndex() const
virtual ~ComputedVariable()
virtual ~VariableComputer()
SimpleValueVectorVariable(CachingVariableFactoryArg arg)
TwoObjectVariable(CachingVariableFactoryArg arg)
ComputedVariable(CachingVariableFactoryArg arg)
void assign(std::string var, double &value) const
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
VariableComputer(CachingVariable::CachingVariableFactoryArg arg)
virtual ~CachingVariable()
void addDescriptionLine(const std::string &s)
const std::string & label(unsigned int i) const
Description(std::vector< std::string > &d)
CachingVariable::CachingVariableFactoryArg & arg_
void setNotCompute() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Splitter(std::string method, std::string n, const edm::ParameterSet &iConfig)
std::map< std::string,const ComputedVariable * > iCompute_
CachingVariable::vMap & m
StringObjectFunction< Object > * forder_
VariableComputerTest(CachingVariable::CachingVariableFactoryArg arg)
std::vector< std::string > d_
bool operator()(const Object *o1, const Object *o2)
SimpleValueVariable(CachingVariableFactoryArg arg)
std::vector< std::string > labels_
const std::vector< std::string > lines()
bool compute(const edm::Event &iEvent) const
void addLine(const std::string &l)
VariablePower(CachingVariableFactoryArg arg)
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
void doesNotCompute() const
void compute(const edm::Event &iEvent) const
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 ©)
const std::string & name() const
const std::string & name() const
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)
virtual CachingVariable::valueType calculate(getObject &o) const