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  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
reco::MaskCollection::eval
virtual void eval(Collection const &, Mask &) const =0
mps_fire.i
i
Definition: mps_fire.py:428
reco::SelectInCollection::~SelectInCollection
virtual ~SelectInCollection()
Definition: ExpressionEvaluatorTemplates.h:54
reco::genericExpression
Definition: ExpressionEvaluatorTemplates.h:13
reco::MaskCollection
Definition: ExpressionEvaluatorTemplates.h:31
reco::ValueOnObject::~ValueOnObject
virtual ~ValueOnObject()
Definition: ExpressionEvaluatorTemplates.h:27
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
reco::SelectIndecesInCollection::Indices
std::vector< unsigned int > Indices
Definition: ExpressionEvaluatorTemplates.h:60
reco::SelectIndecesInCollection::Collection
std::vector< Object const * > Collection
Definition: ExpressionEvaluatorTemplates.h:59
reco::SelectIndecesInCollection
Definition: ExpressionEvaluatorTemplates.h:58
Indices
Indices
Definition: EdmEventSize.cc:28
reco::MaskCollection::Collection
std::vector< Object const * > Collection
Definition: ExpressionEvaluatorTemplates.h:32
reco::genericExpression::~genericExpression
virtual ~genericExpression()
Definition: ExpressionEvaluatorTemplates.h:15
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
reco::MaskCollection::~MaskCollection
virtual ~MaskCollection()
Definition: ExpressionEvaluatorTemplates.h:41
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
reco::SelectIndecesInCollection::eval
virtual void eval(Collection const &, Indices &) const =0
reco::MaskCollection::mask
void mask(Collection const &cands, Mask &mask, F f) const
Definition: ExpressionEvaluatorTemplates.h:35
reco::SelectInCollection
Definition: ExpressionEvaluatorTemplates.h:45
reco::CutOnObject::~CutOnObject
virtual ~CutOnObject()
Definition: ExpressionEvaluatorTemplates.h:21
reco::genericExpression::operator()
virtual Ret operator()(Args...) const =0
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15161
reco::MaskCollection::Mask
std::vector< bool > Mask
Definition: ExpressionEvaluatorTemplates.h:33
reco::SelectInCollection::eval
virtual void eval(Collection &) const =0
reco::ValueOnObject::eval
virtual double eval(Object const &) const =0
reco::SelectInCollection::select
void select(Collection &cands, F f) const
Definition: ExpressionEvaluatorTemplates.h:48
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
reco::SelectIndecesInCollection::~SelectIndecesInCollection
virtual ~SelectIndecesInCollection()
Definition: ExpressionEvaluatorTemplates.h:71
reco::SelectIndecesInCollection::select
void select(Collection const &cands, Indices &inds, F f) const
Definition: ExpressionEvaluatorTemplates.h:62
reco::SelectInCollection::Collection
std::vector< Object const * > Collection
Definition: ExpressionEvaluatorTemplates.h:46
reco::CutOnObject::eval
virtual bool eval(Object const &) const =0
reco::ValueOnObject
Definition: ExpressionEvaluatorTemplates.h:25
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
reco::CutOnObject
Definition: ExpressionEvaluatorTemplates.h:19