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  };
16 
17 
18  template<typename Object>
19  struct CutOnObject {
20  virtual bool eval(Object const&) const = 0;
21  };
22 
23  template<typename Object>
24  struct ValueOnObject {
25  virtual double eval(Object const&) const =0;
26  };
27 
28  template<typename Object>
29  struct MaskCollection {
30  using Collection = std::vector<Object const *>;
31  using Mask = std::vector<bool>;
32  template<typename F>
33  void mask(Collection const& cands, Mask& mask, F f) const {
34  mask.resize(cands.size());
35  std::transform(cands.begin(),cands.end(),mask.begin(), [&](typename Collection::value_type const & c){ return f(*c);});
36  }
37  virtual void eval(Collection const&, Mask&) const = 0;
38  };
39 
40  template<typename Object>
42  using Collection = std::vector<Object const *>;
43  template<typename F>
44  void select(Collection& cands, F f) const {
45  cands.erase(std::remove_if(cands.begin(),cands.end(),[&](typename Collection::value_type const &c){return !f(*c);}),cands.end());
46  }
47  virtual void eval(Collection&) const = 0;
48  };
49 
50  template<typename Object>
52  using Collection = std::vector<Object const *>;
53  using Indices = std::vector<unsigned int>;
54  template<typename F>
55  void select(Collection const & cands, Indices& inds, F f) const {
56  unsigned int i=0;
57  for (auto const & c : cands) { if(f(*c)) inds.push_back(i); ++i; }
58  }
59  virtual void eval(Collection const&, Indices&) const = 0;
60  };
61 
62 
63 }
64 
65 #endif // CommonToolsUtilsExpressionEvaluatorTemplates_H
66 
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