4#ifndef PHASEII_RAWDATACONTAINER_H
5#define PHASEII_RAWDATACONTAINER_H
19 template <
typename Type>
20 concept isAtomic =
requires(
Type a,
typename Type::value_type b ) {
a.compare_exchange_weak(b,b); };
23 template <
typename T_DataContainer>
24 concept hasErrors =
requires(T_DataContainer &
a,
unsigned int idx) {
a.errors()[idx]; };
55 DataRange(
unsigned int begin_val,
unsigned int n,
unsigned int idx)
56 :
m_payload{ .
m_range = {
static_cast<std::uint32_t
>(begin_val),
static_cast<std::uint16_t
>(n),
static_cast<std::uint16_t
>(idx)} }
58 assert(begin_val<std::numeric_limits<std::uint32_t>::max());
59 assert(n<std::numeric_limits<std::uint16_t>::max());
60 assert(idx<std::numeric_limits<std::uint16_t>::max());
62 DataRange(std::uint32_t begin_val, std::uint16_t n, std::uint16_t idx)
67 static_assert(
sizeof(
m_payload.m_range) ==
sizeof(std::uint64_t));
77 template <
typename T_ElementIndex,
typename T_ContainerIndex>
79 T_ElementIndex end_index,
80 T_ContainerIndex container_index) {
84 assert( end_index >= begin_index ) ;
85 assert(
static_cast<std::uint32_t
>(begin_index) == begin_index);
86 assert(
static_cast<std::size_t
>(end_index - begin_index) < std::numeric_limits<std::uint16_t>::max());
87 assert(
static_cast<std::uint16_t
>(container_index) == container_index);
88 return DataRange(
static_cast<std::uint32_t
>(begin_index),
89 static_cast<std::uint16_t
>(end_index - begin_index),
90 static_cast<std::uint16_t
>(container_index));
108 template <
class T_DataContainer,
class T_RangeType>
129 assert( new_range.containerIndex() <
m_containers.size() );
131 if (is_range.size() != new_range.size()) {
132 assert(is_range.empty());
138 assert( new_range.beginIndex() + new_range.size() ==
m_containers[new_range.containerIndex()].size());
139 m_containers[new_range.containerIndex()].erase_back(new_range.beginIndex());
147 return m_range[
index].compare_exchange_weak(is_range, new_range);
160 const T_DataContainer &
data(
unsigned int container_index)
const
165 T_DataContainer &
data(
unsigned int container_index)
244 template <std::
size_t NDim>
274 m_word.reserve(new_capacity);
285 m_word.emplace_back(data_word);
307 static constexpr int unpack(std::uint32_t mask,
unsigned int shift,
unsigned int word) {
308 return static_cast<int>( (word >> shift ) & mask );
319 static constexpr std::uint32_t
pack(std::uint32_t mask,
unsigned int shift,
int input) {
321 assert(
static_cast<int>(
static_cast<std::uint32_t
>(input) & mask) ==input );
322 return static_cast<std::uint32_t
>( (input & mask) << shift );
331 unsigned int copy_n_elements=
size()-start_index;
332 dest.m_coordinates.resize(copy_n_elements);
333 dest.m_word.resize(copy_n_elements);
335 std::memcpy(dest.m_word.data(),
m_word.data()+start_index, copy_n_elements*
sizeof(
typename decltype(
m_word)
::value_type) );
344 using namespace Utils;
352 template <
class T_RawDataContainer, AccessPolicy accessPolicy=AccessPolicy::ReadOnly>
378 template <
class T_RawDataContainer,
class T_RawDataProxy, AccessPolicy accessPolicy=AccessPolicy::ReadOnly>
380 RawDataContainerProxy<T_RawDataContainer, T_RawDataProxy, accessPolicy>,
397 return range.beginIndex();
402 return range.endIndex();
407 assert( element_index < container->
size());
408 return ++element_index;
423 template <
class T_RawDataContainer>
425 template <AccessPolicy accessPolicy>
439 template <
class T_RawDataContainerCollection,
class T_RawDataProxy, AccessPolicy accessPolicy=AccessPolicy::ReadOnly>
442 accessPolicy >::template ElementProxyBase<accessPolicy>
444 using T_Range =
typename T_RawDataContainerCollection::T_RangeTypeBase;
445 using T_RawDataContainer = std::remove_cvref_t<decltype(std::declval<T_RawDataContainerCollection>().data(std::uint32_t{}))>;
456 return &(
container.data(range.containerIndex()));
463 return &(
container.data(range.containerIndex()));
498 return index.rangeIndex();
503 template <
class T_RawDataContainerCollection,
class T_RawDataProxy, AccessPolicy accessPolicy=AccessPolicy::ReadOnly>
505 ContainerCollectionProxy<T_RawDataContainerCollection, T_RawDataProxy, accessPolicy>,
506 ContainerProxyAdapter<T_RawDataContainerCollection, T_RawDataProxy,accessPolicy>,
518 template <
class T_RawDataContainer, AccessPolicy accessPolicy=AccessPolicy::ReadOnly>
528 template <
class T_RawDataContainerCollection>
530 using T_RawDataContainer =
typename T_RawDataContainerCollection::DataContainerType;
535 template <
class T_RawDataContainerCollection>
537 using T_RawDataContainer =
typename T_RawDataContainerCollection::DataContainerType;
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
static const Attributes_t empty
Helper class which provides a possibly dynamically growing list of containers suitable for a multi-th...
size_t size() const
Duplicate of fullSize for backwards compatability.
Helper class to represent the top level proxy which provides per module proxy objects which provide t...
ContainerProxy< T_RawDataContainerCollection, ContainerCollectionProxy< T_RawDataContainerCollection, T_RawDataProxy, accessPolicy >, ContainerProxyAdapter< T_RawDataContainerCollection, T_RawDataProxy, accessPolicy >, RootNodeIndex, accessPolicy > BASE
An adapter to create a container proxy from a range index which defines the actual element container ...
std::remove_cvref_t< decltype(std::declval< T_RawDataContainerCollection >().data(std::uint32_t{}))> T_RawDataContainer
static RawDataContainerProxy< T_RawDataContainer, T_RawDataProxy, AccessPolicy::ReadOnly > create(const T_RawDataContainerCollection *container, unsigned int module_index)
Create the actual container proxy for the elements this proxy refers to.
static T_RawDataContainer * getRawDataContainer(T_RawDataContainerCollection &container, unsigned int module_index)
static IndexWithRange getIndexWithRange(const T_RawDataContainerCollection &container, unsigned int module_index)
typename ContainerProxyBase< T_RawDataContainerCollection, unsigned int, accessPolicy >::template ElementProxyBase< accessPolicy > BASE
typename T_RawDataContainerCollection::T_RangeTypeBase T_Range
static unsigned int getOriginalElementIndex(const IndexWithRange &index)
Supporting method for "converted" proxies resulting from the methods above to recover the original "c...
static const T_RawDataContainer * getRawDataContainer(const T_RawDataContainerCollection &container, unsigned int module_index)
static RawDataContainerProxy< T_RawDataContainer, T_RawDataProxy, accessPolicy > create(T_RawDataContainerCollection *container, unsigned int module_index)
Create the actual container proxy for the elements this proxy refers to.
Base raw data container which provides coordinates of a certain dimension and a data word per RDO (ra...
void emplace_back(std::array< std::int16_t, NDim > &&coordinates, std::uint32_t data_word)
Add a new RDO to the end of this container.
std::vector< std::array< std::int16_t, NDim > > m_coordinates
static constexpr int unpack(std::uint32_t mask, unsigned int shift, unsigned int word)
extract a value from a bit packed word.
std::size_t capacity() const
the maximum number RDOs this container can hold without reallocation.
void move(InDetRawDataContainer &dest, unsigned int start_index)
Move the coordinates and the data word of a certain number of elements at the end to a new container.
const std::array< std::int16_t, NDim > & coordinates(unsigned int index) const
return the coordinates i.e. column, row or strip of a certain RDO (read only).
std::vector< std::uint32_t > m_word
std::size_t size() const
total number of RDOs which are in this container.
bool isValid(unsigned int index) const
return true if the index refers to an element in the container
static constexpr std::uint32_t pack(std::uint32_t mask, unsigned int shift, int input)
Create a bit-packed word from an input value.
bool empty() const
test whether the container is empty i.e. does not contain any RDOs
std::array< std::int16_t, NDim > & coordinates(unsigned int index)
return the coordinates i.e. column, row or strip of a certain RDO.
const std::uint32_t & dataWord(unsigned int index) const
return the packed data word of of a certain RDO (read only).
void reserve(std::size_t new_capacity)
reserve space for a certain number of RDOs.
std::uint32_t & dataWord(unsigned int index)
return the packed data word of of a certain RDO.
void erase_back(unsigned int begin_index)
erase the elements at the end of the container
Helper class to associate ranges of elements in multiple containers to a contiguous index.
auto & errorContainer(unsigned int container_index)
if there is an associated error container get it (read/write access).
T_DataContainer DataContainerType
T_DataContainer & data(unsigned int container_index)
Get an existing container from the container collection.
IndexedRanges(unsigned int n_ranges, unsigned int container_list_size)
create a container collection for n_ranges and a certain maximum number of containers.
bool update(unsigned int index, T_RangeTypeBase &is_range, const T_RangeTypeBase &new_range)
update a range (version for a "non-atomic" range)
std::vector< std::atomic< PhaseII::DataRange > > m_range
const auto & errorContainer(unsigned int container_index) const
if there is an associated error container get it.
std::size_t empty() const
return true there are no element ranges.
ContainerList< T_RawDataContainer > m_containers
bool update(unsigned int index, T_RangeTypeBase &is_range, const T_RangeTypeBase &new_range)
const T_DataContainer & data(unsigned int container_index) const
Get an existing container from the container collection (read only).
const T_RangeType & range(unsigned int index) const
Get a specific element range.
bool registerOrEraseNewData(unsigned int index, const T_RangeTypeBase &new_range)
register an element range or erase the elements of this range.
decltype(GetValue< T_RangeType >::value(T_RangeType{})) T_RangeTypeBase
std::size_t containerListCapacity() const
std::size_t size() const
return the total number of element ranges.
A proxy providing access to the RDOs of a single module.
const unsigned int & identifyHash() const
method which returns the identifier hash of the module this proxy represents.
static unsigned int beginIndex(const T_RawDataContainer *container, const IndexWithRange &range)
method which returns the index of the first child element this proxy represents
unsigned int beginIndex() const
static unsigned int endIndex(const T_RawDataContainer *container, const IndexWithRange &range)
method which returns the index of the element after the last child element this proxy represents
static unsigned int nextElementIndex(const T_RawDataContainer *container, unsigned int element_index)
method which returns the element which follows the element specified by element_index
unsigned int endIndex() const
ContainerProxy< T_RawDataContainer, RawDataContainerProxy< T_RawDataContainer, T_RawDataProxy, accessPolicy >, T_RawDataProxy, IndexWithRange, accessPolicy > BASE
Base class for an RDO proxy.
const auto & dataWord() const
const auto & coordinates() const
typename ContainerProxyBase< T_RawDataContainer, unsigned int, accessPolicy >::template ElementProxyBase< accessPolicy > BASE
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
auto makeRawDataCollectionProxy(const T_RawDataContainerCollection &collection)
Create the top level container proxy for an RDO container collection (read only).
std::uint16_t size() const
RangeSize_t m_n
the number of elements in this range.
RangeBeginIndex_t m_beginIndex
the index of the first element in the range in the container defined by the container index
DataRange(std::uint32_t begin_val, std::uint16_t n, std::uint16_t idx)
std::uint64_t m_compactRange
unsigned int beginIndex() const
std::uint64_t makeCompact() const
DataRange(std::uint64_t compact_range)
union PhaseII::DataRange::@115366361000146103022305316242135000036157260104 m_payload
struct PhaseII::DataRange::@115366361000146103022305316242135000036157260104::Range m_range
std::uint16_t containerIndex() const
static DataRange makeDataRange(T_ElementIndex begin_index, T_ElementIndex end_index, T_ContainerIndex container_index)
std::uint16_t ContainerIndex_t
void setSize(RangeSize_t new_size)
std::uint32_t RangeBeginIndex_t
std::uint16_t RangeSize_t
ContainerIndex_t m_containerIndex
the index which identifies the the container within a container collection
DataRange(unsigned int begin_val, unsigned int n, unsigned int idx)
unsigned int endIndex() const
static auto value(const T &value)
static auto value(const T &value)
Helper class to be used in conjunction with ProxyContainers.
const unsigned int & rangeIndex() const
the index which identifies this range within its parent.
bool empty() const
return true if this range does not contain any elements.
bool operator==(const IndexWithRange &other) const
unsigned int beginIndex() const
the first element in the range
unsigned int m_endIndex
index after the last child element of this range
unsigned int m_beginIndex
index of the first child element in the range
unsigned int endIndex() const
the index of the element after the last element
unsigned int m_rangeIndex
the index if the element which is the parent of the children where the index may refer to a different...
helper class to define all the proxies for a RDO container.
PhaseII::RawDataContainerProxy< T_RawDataContainer, RawDataProxy, accessPolicy > RawDataContainerProxy
PhaseII::ContainerCollectionProxy< ContainerCollection, RawDataProxy, accessPolicy > ContainerCollectionProxy
typename RawData::details::traits< T_RawDataContainer >::template RawDataProxy< accessPolicy > RawDataProxy
PhaseII::IndexedRanges< T_RawDataContainer, std::atomic< PhaseII::DataRange > > ContainerCollection
PhaseII::ContainerProxyAdapter< ContainerCollection, RawDataProxy, accessPolicy > ContainerProxyAdapter
RawDataProxyBase< T_RawDataContainer, accessPolicy > RawDataProxy
Base class of a container proxy.
const T_RawDataContainer & container() const
ContainerProxy(T_RawDataContainer *container)
ContainerProxyBase< T_RawDataContainer, typename T_RawDataProxy::index_t, accessPolicy > BASE
Helper struct to indicate the "index" of a top level container proxy.