ATLAS Offline Software
IPartCombItr.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 <set>
9 
10 namespace {
11  using namespace TrigCompositeUtils;
12  template <typename T>
13  std::ostream &operator<<(std::ostream &os, const LinkInfo<T> &info)
14  {
15  return os << info.source << ", (" << info.link.persKey() << ", " << info.link.persIndex() << ")";
16  }
17 
18  template <typename T>
19  std::ostream &operator<<(std::ostream &os, const std::vector<T> &v)
20  {
21  os << "[";
22  if (v.size() > 0)
23  {
24  for (auto itr = v.begin(); itr != v.end() - 1; ++itr)
25  os << *itr << ", ";
26  os << v.back();
27  }
28  return os << "]";
29  }
30 }
31 
32 namespace TrigCompositeUtils
33 {
35  {
36  std::set<const xAOD::IParticle *> seen;
37  for (const auto &info : links)
38  if (!seen.insert(*info.link).second)
39  return false;
40  return true;
41  }
42 
44  {
45  std::set<std::pair<uint32_t, uint32_t>> seen;
46  for (const auto &info : links)
47  {
48  LinkInfo<TrigRoiDescriptorCollection> roi = findLink<TrigRoiDescriptorCollection>(info.source, initialRoIString());
49  if (!seen.insert(std::make_pair(roi.link.persKey(), roi.link.persIndex())).second)
50  // Insert returns false if that item already exists in it
51  return false;
52  }
53  return true;
54  }
55 
57  {
58  std::set<std::pair<uint32_t, uint32_t>> seen;
59  for (const auto &info : links)
60  {
61  LinkInfo<TrigRoiDescriptorCollection> roi = findLink<TrigRoiDescriptorCollection>(info.source, "roi");
62  if (!seen.insert(std::make_pair(roi.link.persKey(), roi.link.persIndex())).second)
63  // Insert returns false if that item already exists in it
64  return false;
65  }
66  return true;
67  }
68 
69  std::function<bool(const std::vector<LinkInfo<xAOD::IParticleContainer>> &)> getFilter(FilterType filter)
70  {
71  switch (filter)
72  {
73  case FilterType::All:
74  return [](const std::vector<LinkInfo<xAOD::IParticleContainer>> &) { return true; };
76  return uniqueObjects;
78  return uniqueRoIs;
79  default:
80  throw std::runtime_error("Unhandled FilterType enum value!");
81  return {};
82  }
83  }
84 
86 
88  const std::vector<std::tuple<std::size_t, LInfoItr_t, LInfoItr_t>> &pieces,
89  std::function<bool(const VecLInfo_t &)> filter)
90  : m_filter(std::move(filter))
91  {
92  std::vector<KFromNItr> idxItrs;
93  idxItrs.reserve(pieces.size());
94  m_linkInfoItrs.reserve(pieces.size());
95  std::size_t size = 0;
96  for (const auto &tup : pieces)
97  {
98  std::size_t multiplicity = std::get<0>(tup);
99  LInfoItr_t begin = std::get<1>(tup);
100  LInfoItr_t end = std::get<2>(tup);
101  idxItrs.emplace_back(multiplicity, std::distance(begin, end));
102  m_linkInfoItrs.push_back(begin);
103  size += multiplicity;
104  }
105  m_idxItr = ProductItr<KFromNItr>(idxItrs, std::vector<KFromNItr>(idxItrs.size()));
106  m_current.assign(size, {});
107  readCurrent();
108  }
109 
111  const std::vector<std::tuple<std::size_t, LInfoItr_t, LInfoItr_t>> &pieces,
113  : IPartCombItr(pieces, getFilter(filter))
114  {
115  }
116 
118  {
119  // Reset each individual iterator and set our current value accordingly
120  m_idxItr.reset();
121  readCurrent();
122  }
123 
125  {
126  return m_idxItr.exhausted();
127  }
128 
130  {
131  if (exhausted())
132  throw std::runtime_error("Dereferencing past-the-end iterator");
133  return m_current;
134  }
135 
137  {
138  if (exhausted())
139  throw std::runtime_error("Dereferencing past-the-end iterator");
140  return &m_current;
141  }
142 
144  {
145  if (exhausted())
146  // Don't iterate an iterator that is already past the end
147  return *this;
148  ++m_idxItr;
149  readCurrent();
150  return *this;
151  }
152 
154  {
155  IPartCombItr ret(*this);
156  this->operator++();
157  return ret;
158  }
159 
161  {
162  // All past-the-end iterators compare equal
163  if (exhausted() && other.exhausted())
164  return true;
165  return m_idxItr == other.m_idxItr && m_linkInfoItrs == other.m_linkInfoItrs;
166  }
167 
169  {
170  return !(*this == other);
171  }
172 
174  {
175  if (exhausted())
176  m_current.assign(m_current.size(), {});
177  else
178  {
179  auto currentItr = m_current.begin();
180  for (std::size_t iLeg = 0; iLeg < nLegs(); ++iLeg)
181  {
182  std::vector<std::size_t> indices = *(*m_idxItr)[iLeg];
183  for (std::size_t idx : indices)
184  *(currentItr++) = *(m_linkInfoItrs[iLeg] + idx);
185  }
186  if (!m_filter(m_current))
187  // If we fail the filter condition, advance the iterator again
188  this->operator++();
189  }
190  }
191 
192 } // namespace TrigCompositeUtils
grepfile.info
info
Definition: grepfile.py:38
TrigCompositeUtils::IPartCombItr::m_idxItr
ProductItr< KFromNItr > m_idxItr
Definition: IPartCombItr.h:117
TrigCompositeUtils::IPartCombItr::m_filter
std::function< bool(const VecLInfo_t &)> m_filter
Definition: IPartCombItr.h:115
TrigCompositeUtils::uniqueRoIs
bool uniqueRoIs(const std::vector< LinkInfo< xAOD::IParticleContainer >> &links)
Helper function that returns true if no objects share a final RoI.
Definition: IPartCombItr.cxx:56
TrigCompositeUtils::LinkInfo::link
ElementLink< T > link
Link to the feature.
Definition: LinkInfo.h:61
TrigCompositeUtils::FilterType::UniqueRoIs
@ UniqueRoIs
Do not allow any two objects to share an RoI.
TrigCompositeUtils::ProductItr
Iterates over all combinations of the provided input iterators.
Definition: ProductItr.h:43
IPartCombItr.h
TrigCompositeUtils::IPartCombItr::nLegs
std::size_t nLegs() const
The number of legs.
Definition: IPartCombItr.h:86
TrigCompositeUtils::uniqueObjects
bool uniqueObjects(const std::vector< LinkInfo< xAOD::IParticleContainer >> &links)
Helper fucntion that returns true if no objects are repeated.
Definition: IPartCombItr.cxx:34
TrigCompositeUtils::FilterType::UniqueObjects
@ UniqueObjects
Do not allow any repeated objects.
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
TrigCompositeUtils::IPartCombItr::readCurrent
void readCurrent()
Definition: IPartCombItr.cxx:173
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TrigCompositeUtils::IPartCombItr::operator*
reference operator*() const
Dereference.
Definition: IPartCombItr.cxx:129
TrigCompositeUtils::IPartCombItr::reset
void reset()
Reset the iterator to its starting point.
Definition: IPartCombItr.cxx:117
TrigCompositeUtils::FilterType::All
@ All
Allow all combinations.
TrigCompositeUtils::IPartCombItr
Definition: IPartCombItr.h:42
TrigCompositeUtils::IPartCombItr::VecLInfo_t
std::vector< LinkInfo< xAOD::IParticleContainer > > VecLInfo_t
Definition: IPartCombItr.h:44
TrigCompositeUtils::IPartCombItr::IPartCombItr
IPartCombItr()
A default constructed iterator acts as a past-the-end iterator.
Definition: IPartCombItr.cxx:85
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TrigCompositeUtils::IPartCombItr::size
std::size_t size() const
The size of each combination.
Definition: IPartCombItr.h:83
covarianceTool.filter
filter
Definition: covarianceTool.py:514
TrigCompositeUtils::FilterType
FilterType
Definition: IPartCombItr.h:22
TrigCompositeUtils.h
TrigCompositeUtils::IPartCombItr::reference
const value_type & reference
Definition: IPartCombItr.h:49
TrigCompositeUtils::initialRoIString
const std::string & initialRoIString()
Definition: TrigCompositeUtilsRoot.cxx:868
DMTest::links
links
Definition: CLinks_v1.cxx:22
TrigCompositeUtils::IPartCombItr::m_current
VecLInfo_t m_current
Definition: IPartCombItr.h:119
TrigCompositeUtils::IPartCombItr::LInfoItr_t
VecLInfo_t::const_iterator LInfoItr_t
Definition: IPartCombItr.h:45
TrigCompositeUtils::IPartCombItr::operator==
bool operator==(const IPartCombItr &other) const
Iterator comparison functions.
Definition: IPartCombItr.cxx:160
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
TrigCompositeUtils::IPartCombItr::operator++
IPartCombItr & operator++()
Pre-increment operator.
Definition: IPartCombItr.cxx:143
TrigCompositeUtils::IPartCombItr::operator!=
bool operator!=(const IPartCombItr &other) const
Definition: IPartCombItr.cxx:168
operator<<
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Definition: TestGaudiProperty.cxx:69
TrigCompositeUtils::IPartCombItr::pointer
const value_type * pointer
Definition: IPartCombItr.h:50
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
python.PyAthena.v
v
Definition: PyAthena.py:154
TrigCompositeUtils::IPartCombItr::operator->
pointer operator->() const
Definition: IPartCombItr.cxx:136
TrigCompositeUtils::uniqueInitialRoIs
bool uniqueInitialRoIs(const std::vector< LinkInfo< xAOD::IParticleContainer >> &links)
Helper function that returns true if no objects share an initial RoI.
Definition: IPartCombItr.cxx:43
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
TrigCompositeUtils::IPartCombItr::exhausted
bool exhausted() const
True if this iterator is past the end.
Definition: IPartCombItr.cxx:124
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
TrigCompositeUtils::IPartCombItr::m_linkInfoItrs
std::vector< LInfoItr_t > m_linkInfoItrs
Definition: IPartCombItr.h:116
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
TrigRoiDescriptorCollection.h