ATLAS Offline Software
Loading...
Searching...
No Matches
Combinations.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <tuple>
7#include <algorithm>
8#include <numeric>
9
10namespace TrigCompositeUtils
11{
13 const std::vector<std::size_t> &legMultiplicities,
14 const std::vector<VecLInfo_t> &legFeatures,
15 const std::function<bool(const VecLInfo_t &)> &filter)
16 : m_filter(filter),
17 m_legMultiplicities(legMultiplicities),
18 m_legFeatures(legFeatures)
19 {
20 if (legMultiplicities.size() != legFeatures.size())
21 throw std::invalid_argument("Different numbers of multiplicities and features provided");
22 }
23
25 const std::vector<std::size_t> &legMultiplicities,
26 const std::vector<VecLInfo_t> &legFeatures,
27 FilterType filter)
28 : Combinations(legMultiplicities, legFeatures, getFilter(filter))
29 {
30 }
31
32 Combinations::Combinations(const std::function<bool(const VecLInfo_t &)> &filter)
33 : Combinations(std::vector<std::size_t>{}, std::vector<VecLInfo_t>{}, filter)
34 {
35 }
36
38
39 void Combinations::reserve(std::size_t capacity)
40 {
41 m_legMultiplicities.reserve(capacity);
42 m_legFeatures.reserve(capacity);
43 }
44
46 {
47 return begin() == end();
48 }
49
50 std::size_t Combinations::size() const
51 {
52 return std::accumulate(m_legMultiplicities.begin(), m_legMultiplicities.end(), std::size_t(0));
53 }
54
55 void Combinations::addLeg(std::size_t multiplicity, const VecLInfo_t &features)
56 {
57 m_legMultiplicities.push_back(multiplicity);
58 m_legFeatures.push_back(features);
59 }
60
61 void Combinations::addLeg(std::size_t multiplicity, VecLInfo_t&& features)
62 {
63 m_legMultiplicities.push_back(multiplicity);
64 m_legFeatures.push_back(std::move(features));
65 }
66
67 void Combinations::addLeg(const VecLInfo_t &features)
68 {
69 addLeg(1, features);
70 }
71
73 {
74 addLeg(1, std::move(features));
75 }
76
78 {
79 // Build up the constructor arguments
80 std::vector<std::tuple<std::size_t, VecLInfo_t::const_iterator, VecLInfo_t::const_iterator>> args;
81 for (std::size_t ii = 0; ii < m_legFeatures.size(); ++ii)
82 args.push_back(std::make_tuple(
84 m_legFeatures.at(ii).begin(),
85 m_legFeatures.at(ii).end()));
86 return IPartCombItr(args, m_filter);
87 }
88
90 {
91 return IPartCombItr();
92 }
93} // namespace TrigCompositeUtils
void reserve(std::size_t capacity)
Combinations(const std::vector< std::size_t > &legMultiplicities, const std::vector< VecLInfo_t > &legFeatures, const std::function< bool(const VecLInfo_t &)> &filter)
void addLeg(std::size_t multiplicity, const VecLInfo_t &features)
std::vector< VecLInfo_t > m_legFeatures
std::function< bool(const VecLInfo_t &)> m_filter
std::vector< LinkInfo< xAOD::IParticleContainer > > VecLInfo_t
std::vector< std::size_t > m_legMultiplicities
std::function< bool(const std::vector< LinkInfo< xAOD::IParticleContainer > > &)> getFilter(FilterType filter)
Get a lambda corresponding to the specified FilterType enum.
STL namespace.