CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  template <typename Object>
19  struct CutOnObject {
20  virtual bool eval(Object const&) const = 0;
21  virtual ~CutOnObject(){};
22  };
23 
24  template <typename Object>
25  struct ValueOnObject {
26  virtual double eval(Object const&) const = 0;
27  virtual ~ValueOnObject(){};
28  };
29 
30  template <typename Object>
31  struct MaskCollection {
32  using Collection = std::vector<Object const*>;
33  using Mask = std::vector<bool>;
34  template <typename F>
35  void mask(Collection const& cands, Mask& mask, F f) const {
36  mask.resize(cands.size());
38  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(
50  std::remove_if(cands.begin(), cands.end(), [&](typename Collection::value_type const& c) { return !f(*c); }),
51  cands.end());
52  }
53  virtual void eval(Collection&) const = 0;
54  virtual ~SelectInCollection(){};
55  };
56 
57  template <typename Object>
59  using Collection = std::vector<Object const*>;
60  using Indices = std::vector<unsigned int>;
61  template <typename F>
62  void select(Collection const& cands, Indices& inds, F f) const {
63  unsigned int i = 0;
64  for (auto const& c : cands) {
65  if (f(*c))
66  inds.push_back(i);
67  ++i;
68  }
69  }
70  virtual void eval(Collection const&, Indices&) const = 0;
72  };
73 
74 } // namespace reco
75 
76 #endif // CommonToolsUtilsExpressionEvaluatorTemplates_H
void mask(Collection const &cands, Mask &mask, F f) const
const edm::EventSetup & c
std::vector< Object const * > Collection
virtual double eval(Object const &) const =0
virtual void eval(Collection &) const =0
Indices
Definition: EdmEventSize.cc:28
std::vector< Object const * > Collection
virtual void eval(Collection const &, Indices &) const =0
virtual Ret operator()(Args...) const =0
virtual bool eval(Object const &) const =0
void select(Collection &cands, F f) const
virtual void eval(Collection const &, Mask &) const =0
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
void select(Collection const &cands, Indices &inds, F f) const
std::vector< Object const * > Collection
unsigned transform(const HcalDetId &id, unsigned transformCode)