ATLAS Offline Software
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 
10 namespace 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,
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 
45  bool Combinations::empty() const
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(
83  m_legMultiplicities.at(ii),
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
TrigCompositeUtils::Combinations::m_legFeatures
std::vector< VecLInfo_t > m_legFeatures
Definition: Combinations.h:52
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
TrigCompositeUtils::Combinations::reserve
void reserve(std::size_t capacity)
Definition: Combinations.cxx:39
TrigCompositeUtils::Combinations::m_filter
std::function< bool(const VecLInfo_t &)> m_filter
Definition: Combinations.h:50
TrigCompositeUtils::IPartCombItr
Definition: IPartCombItr.h:42
TrigCompositeUtils::Combinations::addLeg
void addLeg(std::size_t multiplicity, const VecLInfo_t &features)
Definition: Combinations.cxx:55
covarianceTool.filter
filter
Definition: covarianceTool.py:514
TrigCompositeUtils::FilterType
FilterType
Definition: IPartCombItr.h:22
TrigCompositeUtils::Combinations::end
IPartCombItr end() const
Definition: Combinations.cxx:89
TrigCompositeUtils::Combinations::Combinations
Combinations(const std::vector< std::size_t > &legMultiplicities, const std::vector< VecLInfo_t > &legFeatures, const std::function< bool(const VecLInfo_t &)> &filter)
Definition: Combinations.cxx:12
vector
Definition: MultiHisto.h:13
TrigCompositeUtils::Combinations
Definition: Combinations.h:18
TrigCompositeUtils::Combinations::VecLInfo_t
std::vector< LinkInfo< xAOD::IParticleContainer > > VecLInfo_t
Definition: Combinations.h:20
TrigCompositeUtils::getFilter
std::function< bool(const std::vector< LinkInfo< xAOD::IParticleContainer >> &)> getFilter(FilterType filter)
Get a lambda corresponding to the specified FilterType enum.
Definition: IPartCombItr.cxx:69
TrigCompositeUtils::Combinations::size
std::size_t size() const
Definition: Combinations.cxx:50
TrigCompositeUtils::Combinations::m_legMultiplicities
std::vector< std::size_t > m_legMultiplicities
Definition: Combinations.h:51
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigCompositeUtils::Combinations::empty
bool empty() const
Definition: Combinations.cxx:45
Combinations.h
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
TrigCompositeUtils::Combinations::begin
IPartCombItr begin() const
Definition: Combinations.cxx:77