ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
ContainerAccessor< value_t, identifier_t, inline_size > Class Template Reference

#include <ContainerAccessor.h>

Collaboration diagram for ContainerAccessor< value_t, identifier_t, inline_size >:

Public Types

using container_t = DataVector< value_t >
 
using Iterator = typename container_t::const_iterator
 
using Range = std::pair< Iterator, Iterator >
 

Public Member Functions

 ContainerAccessor (const container_t &values, std::function< identifier_t(const value_t &)> mapper, size_t max_ids=2000)
 Constructor. More...
 
 ~ContainerAccessor ()=default
 Default destructor. More...
 
 ContainerAccessor (const ContainerAccessor &)=delete
 Copy constructor, deleted. More...
 
ContainerAccessoroperator= (const ContainerAccessor &)=delete
 
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. More...
 
bool isIdentifierPresent (const identifier_t &identifier) const
 Function to verify if a given identifier is present in the map, i.e. More...
 
std::vector< identifier_t > allIdentifiers () const
 Function to return all available identifier (i.e. keys in the map) More...
 

Private Attributes

std::unordered_map< identifier_t, boost::container::small_vector< Range, inline_size > > m_ranges
 

Detailed Description

template<typename value_t, typename identifier_t, size_t inline_size = 10>
class ContainerAccessor< value_t, identifier_t, inline_size >

Class implementing how to access a container

It is templated on the type of the objects in the container (value_t), and the type of the identifier (identifier_t)

Definition at line 25 of file ContainerAccessor.h.

Member Typedef Documentation

◆ container_t

template<typename value_t , typename identifier_t , size_t inline_size = 10>
using ContainerAccessor< value_t, identifier_t, inline_size >::container_t = DataVector<value_t>

Definition at line 28 of file ContainerAccessor.h.

◆ Iterator

template<typename value_t , typename identifier_t , size_t inline_size = 10>
using ContainerAccessor< value_t, identifier_t, inline_size >::Iterator = typename container_t::const_iterator

Definition at line 29 of file ContainerAccessor.h.

◆ Range

template<typename value_t , typename identifier_t , size_t inline_size = 10>
using ContainerAccessor< value_t, identifier_t, inline_size >::Range = std::pair<Iterator, Iterator>

Definition at line 30 of file ContainerAccessor.h.

Constructor & Destructor Documentation

◆ ContainerAccessor() [1/2]

template<typename value_t , typename identifier_t , size_t inline_size = 10>
ContainerAccessor< value_t, identifier_t, inline_size >::ContainerAccessor ( const container_t values,
std::function< identifier_t(const value_t &)>  mapper,
size_t  max_ids = 2000 
)
inline

Constructor.

Template Parameters
valuesContainer type, based on value_t
mapperFunction used to access the identifier_t
Parameters
max_idsExpected maximum number of identifiers, to reserve enough space in the map and avoid re-hashing

At construction, a map is filled with identifiers and corresponding ranges of objects in the container

Note
The map has to be built as soon as the container is complete. If changes in the container happen the ranges may be invalidated.

Definition at line 41 of file ContainerAccessor.h.

42  {
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  }

◆ ~ContainerAccessor()

template<typename value_t , typename identifier_t , size_t inline_size = 10>
ContainerAccessor< value_t, identifier_t, inline_size >::~ContainerAccessor ( )
default

Default destructor.

◆ ContainerAccessor() [2/2]

template<typename value_t , typename identifier_t , size_t inline_size = 10>
ContainerAccessor< value_t, identifier_t, inline_size >::ContainerAccessor ( const ContainerAccessor< value_t, identifier_t, inline_size > &  )
delete

Copy constructor, deleted.

Member Function Documentation

◆ allIdentifiers()

template<typename value_t , typename identifier_t , size_t inline_size = 10>
std::vector<identifier_t> ContainerAccessor< value_t, identifier_t, inline_size >::allIdentifiers ( ) const
inline

Function to return all available identifier (i.e. keys in the map)

Definition at line 84 of file ContainerAccessor.h.

84  {
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  };

◆ isIdentifierPresent()

template<typename value_t , typename identifier_t , size_t inline_size = 10>
bool ContainerAccessor< value_t, identifier_t, inline_size >::isIdentifierPresent ( const identifier_t &  identifier) const
inline

Function to verify if a given identifier is present in the map, i.e.

was present in the input container.

Template Parameters
identifierInput identifier to check.

Definition at line 77 of file ContainerAccessor.h.

77  {
78  if (m_ranges.find(identifier) == m_ranges.end())
79  return false;
80  return true;
81  }

◆ operator=()

template<typename value_t , typename identifier_t , size_t inline_size = 10>
ContainerAccessor& ContainerAccessor< value_t, identifier_t, inline_size >::operator= ( const ContainerAccessor< value_t, identifier_t, inline_size > &  )
delete

◆ rangesForIdentifierDirect()

template<typename value_t , typename identifier_t , size_t inline_size = 10>
const boost::container::small_vector<Range, inline_size> ContainerAccessor< value_t, identifier_t, inline_size >::rangesForIdentifierDirect ( const identifier_t &  identifier) const
inline

Function to return the list of ranges corresponding to a given identifier.

Template Parameters
identifierInput identifier, used for returning the list of ranges from the map.
Note
the identifier must be contained in the map. Check if it is present first with isIdentifierPresent.

Definition at line 69 of file ContainerAccessor.h.

69  {
70  boost::container::small_vector<Range, inline_size> rangesForId = m_ranges.at(identifier);
71  return rangesForId;
72  }

Member Data Documentation

◆ m_ranges

template<typename value_t , typename identifier_t , size_t inline_size = 10>
std::unordered_map<identifier_t, boost::container::small_vector<Range, inline_size> > ContainerAccessor< value_t, identifier_t, inline_size >::m_ranges
private

Definition at line 93 of file ContainerAccessor.h.


The documentation for this class was generated from the following file:
skel.it
it
Definition: skel.GENtoEVGEN.py:423
xAOD::identifier
identifier
Definition: UncalibratedMeasurement_v1.cxx:15
ContainerAccessor::Iterator
typename container_t::const_iterator Iterator
Definition: ContainerAccessor.h:29
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:797
ContainerAccessor::m_ranges
std::unordered_map< identifier_t, boost::container::small_vector< Range, inline_size > > m_ranges
Definition: ContainerAccessor.h:90
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8