CMS 3D CMS Logo

ExpressionEvaluatorTemplates.h
Go to the documentation of this file.
1 #ifndef CommonToolsUtilsExpressionEvaluatorTemplates_H
2 #define CommonToolsUtilsExpressionEvaluatorTemplates_H
3 #include <vector>
4 #include <algorithm>
5 #include<numeric>
6 #include<limits>
7 #include<memory>
8 #include<tuple>
9 
10 namespace reco {
11 
12  template<typename Ret, typename... Args>
14  virtual Ret operator()(Args ...) const =0;
15  virtual ~genericExpression(){};
16  };
17 
18 
19  template<typename Object>
20  struct CutOnObject {
21  virtual bool eval(Object const&) const = 0;
22  virtual ~CutOnObject(){};
23  };
24 
25  template<typename Object>
26  struct ValueOnObject {
27  virtual double eval(Object const&) const =0;
28  virtual ~ValueOnObject(){};
29  };
30 
31  template<typename Object>
32  struct MaskCollection {
33  using Collection = std::vector<Object const *>;
34  using Mask = std::vector<bool>;
35  template<typename F>
36  void mask(Collection const& cands, Mask& mask, F f) const {
37  mask.resize(cands.size());
38  std::transform(cands.begin(),cands.end(),mask.begin(), [&](typename Collection::value_type const & c){ return f(*c);});
39  }
40  virtual void eval(Collection const&, Mask&) const = 0;
41  virtual ~MaskCollection(){};
42  };
43 
44  template<typename Object>
46  using Collection = std::vector<Object const *>;
47  template<typename F>
48  void select(Collection& cands, F f) const {
49  cands.erase(std::remove_if(cands.begin(),cands.end(),[&](typename Collection::value_type const &c){return !f(*c);}),cands.end());
50  }
51  virtual void eval(Collection&) const = 0;
52  virtual ~SelectInCollection(){};
53  };
54 
55  template<typename Object>
57  using Collection = std::vector<Object const *>;
58  using Indices = std::vector<unsigned int>;
59  template<typename F>
60  void select(Collection const & cands, Indices& inds, F f) const {
61  unsigned int i=0;
62  for (auto const & c : cands) { if(f(*c)) inds.push_back(i); ++i; }
63  }
64  virtual void eval(Collection const&, Indices&) const = 0;
66  };
67 
68 
69 }
70 
71 #endif // CommonToolsUtilsExpressionEvaluatorTemplates_H
72 
std::vector< Object const * > Collection
std::vector< Object const * > Collection
void mask(Collection const &cands, Mask &mask, F f) const
double f[11][100]
std::vector< Object const * > Collection
fixed size matrix
void select(Collection &cands, F f) const
virtual Ret operator()(Args...) const =0
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
void select(Collection const &cands, Indices &inds, F f) const