ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
xAOD
xAODInDetMeasurement
xAODInDetMeasurement
ContainerAccessor.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef XAODINDETMEASUREMENT_CONTAINERACCESSOR_H
6
#define XAODINDETMEASUREMENT_CONTAINERACCESSOR_H
7
8
#include "
AthContainers/DataVector.h
"
9
10
#include <boost/container/small_vector.hpp>
11
#include <vector>
12
#include <unordered_map>
13
14
#include <algorithm>
15
#include <functional>
16
#include <optional>
17
#include <utility>
18
23
24
template
<
typename
value_t,
typename
id
entifier_t,
size_t
inline_size = 10>
25
class
ContainerAccessor
{
26
27
public
:
28
using
container_t
=
DataVector<value_t>
;
29
using
Iterator
=
typename
container_t::const_iterator
;
30
using
Range
= std::pair<Iterator, Iterator>;
31
41
ContainerAccessor
(
const
container_t
& values,
42
std::function<identifier_t(
const
value_t&)> mapper,
size_t
max_ids=2000) {
43
m_ranges
.reserve(max_ids);
44
std::optional<identifier_t> prev = std::nullopt;
45
Iterator
groupStart = values.begin();
46
for
(
Iterator
it = values.begin(); it != values.end(); ++it) {
47
identifier_t
id
= mapper(**it);
48
if
(prev && (*prev) !=
id
) {
49
m_ranges
[*prev].emplace_back(groupStart, it);
50
groupStart = it;
51
}
52
prev = id;
53
}
54
if
(prev)
55
m_ranges
[*prev].emplace_back(groupStart, values.end());
56
}
57
59
~ContainerAccessor
() =
default
;
61
ContainerAccessor
(
const
ContainerAccessor
&) =
delete
;
62
ContainerAccessor
&
operator=
(
const
ContainerAccessor
&) =
delete
;
63
69
const
boost::container::small_vector<Range, inline_size>
rangesForIdentifierDirect
(
const
identifier_t& identifier)
const
{
70
boost::container::small_vector<Range, inline_size> rangesForId =
m_ranges
.at(identifier);
71
return
rangesForId;
72
}
73
77
bool
isIdentifierPresent
(
const
identifier_t& identifier)
const
{
78
if
(
m_ranges
.find(identifier) ==
m_ranges
.end())
79
return
false
;
80
return
true
;
81
}
82
84
std::vector<identifier_t>
allIdentifiers
()
const
{
85
std::vector<identifier_t> ids{};
86
ids.reserve(
m_ranges
.size());
87
for
(
const
auto
& id_range :
m_ranges
)
88
ids.push_back(id_range.first);
89
return
ids;
90
};
91
92
private
:
93
std::unordered_map<identifier_t, boost::container::small_vector<Range, inline_size>>
m_ranges
;
94
95
};
96
97
#endif
// XAODINDETMEASUREMENT_CONTAINERACCESSOR_H
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
ContainerAccessor::m_ranges
std::unordered_map< identifier_t, boost::container::small_vector< Range, inline_size > > m_ranges
Definition
ContainerAccessor.h:93
ContainerAccessor::ContainerAccessor
ContainerAccessor(const container_t &values, std::function< identifier_t(const value_t &)> mapper, size_t max_ids=2000)
Constructor.
Definition
ContainerAccessor.h:41
ContainerAccessor::rangesForIdentifierDirect
const boost::container::small_vector< Range, inline_size > rangesForIdentifierDirect(const identifier_t &identifier) const
Function to return the list of ranges corresponding to a given identifier.
Definition
ContainerAccessor.h:69
ContainerAccessor::Range
std::pair< Iterator, Iterator > Range
Definition
ContainerAccessor.h:30
ContainerAccessor::Iterator
typename container_t::const_iterator Iterator
Definition
ContainerAccessor.h:29
ContainerAccessor::allIdentifiers
std::vector< identifier_t > allIdentifiers() const
Function to return all available identifier (i.e. keys in the map).
Definition
ContainerAccessor.h:84
ContainerAccessor::isIdentifierPresent
bool isIdentifierPresent(const identifier_t &identifier) const
Function to verify if a given identifier is present in the map, i.e.
Definition
ContainerAccessor.h:77
ContainerAccessor::ContainerAccessor
ContainerAccessor(const ContainerAccessor &)=delete
Copy constructor, deleted.
ContainerAccessor::container_t
DataVector< value_t > container_t
Definition
ContainerAccessor.h:28
ContainerAccessor::~ContainerAccessor
~ContainerAccessor()=default
Default destructor.
ContainerAccessor::operator=
ContainerAccessor & operator=(const ContainerAccessor &)=delete
DataVector
Derived DataVector<T>.
Definition
DataVector.h:795
DataVector< value_t >::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Definition
DataVector.h:838
Generated on
for ATLAS Offline Software by
1.17.0