lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
psalg::AllocArray< T > Class Template Reference

Array<T> whose shape (MaxRank words), a reference count and up to maxElem elements live in one block from an Allocator. More...

#include <AllocArray.hh>

Inherits XtcData::Array< T >.

Inherited by psalg::AllocArray1D< uint16_t >, psalg::AllocArray1D< uint16_t * >, psalg::AllocArray1D< types::TwoIndexes >, psalg::AllocArray1D< AllocArray1D< types::TwoIndexes > >, psalg::AllocArray1D< psalgos::Peak >, psalg::AllocArray1D< float >, and psalg::AllocArray1D< T >.

Public Member Functions

 AllocArray (Allocator &allocator, size_t maxElem, uint32_t rank)
 Allocate one block for the shape, the reference count and maxElem elements, and set the rank, every shape entry to 0 and the count to 1.
 
 AllocArray (const AllocArray< T > &other)
 Share other's block and increment the reference count.
 
AllocArray< T > & operator= (const AllocArray< T > &other)
 Decrement this object's count, freeing its block with its allocator when the count reaches 0, then share other's block and increment that count.
 
virtual ~AllocArray ()
 Log a syslog error if the count is already <= 0, decrement it, and when it reaches 0 call the destructor of each of the num_elem() elements and free the block.
 
void incRefCnt ()
 Increment the shared reference count.
 
void decRefCnt ()
 Decrement the shared reference count.
 
uint32_t & _refCnt ()
 Return a reference to the shared reference count; public so cython can reach it (per the comment above).
 
- Public Member Functions inherited from XtcData::Array< T >
 Array (void *data, uint32_t *shape, uint32_t rank)
 Wrap data (reinterpreted as T*), shape and rank; nothing is copied.
 
 Array ()
 Construct an empty view: null data and shape pointers, rank 0.
 
 Array (const Array &a)
 Copy the data pointer, shape pointer and rank of a (shallow copy).
 
Array & operator= (const Array &o)
 Copy the data pointer, shape pointer and rank of o (shallow); self-assignment does nothing.
 
T & operator() (unsigned i)
 Return a reference to element i.
 
T & operator() (unsigned i, unsigned j)
 Return a reference to element (i, j) at offset i*shape[1]+j.
 
T & operator() (unsigned i, unsigned j, unsigned k)
 Return a reference to element (i, j, k) at the row-major offset.
 
T & operator() (unsigned i, unsigned j, unsigned k, unsigned l)
 Return a reference to element (i, j, k, l) at the row-major offset.
 
T & operator() (unsigned i, unsigned j, unsigned k, unsigned l, unsigned m)
 Return a reference to element (i, j, k, l, m) at the row-major offset.
 
uint32_t rank () const
 Return the rank.
 
uint32_t * shape () const
 Return the shape pointer (not a copy).
 
T * data ()
 Return the data pointer.
 
const T * const_data () const
 Return the data pointer as const T*.
 
uint64_t num_elem () const
 Return the product of shape[0] .
 
void shape (uint32_t a, uint32_t b=0, uint32_t c=0, uint32_t d=0, uint32_t e=0)
 Write a, b, c, d, e into shape[0..4] (always five entries).
 
void set_rank (uint32_t rank)
 Set the rank.
 
void set_shape (uint32_t *shape)
 Set the shape pointer.
 
void set_data (void *data)
 Set the data pointer (reinterpreted as T*).
 

Protected Attributes

uint32_t * _refCntPtr
 
Allocator & _allocator
 
- Protected Attributes inherited from XtcData::Array< T >
uint32_t * _shape
 
T * _data
 
uint32_t _rank
 

Detailed Description

template<typename T>
class psalg::AllocArray< T >

Array<T> whose shape (MaxRank words), a reference count and up to maxElem elements live in one block from an Allocator.

Copies share the block and increment the count; when the count reaches 0 the elements are destroyed and the block is freed.

Constructor & Destructor Documentation

◆ AllocArray() [1/2]

template<typename T >
psalg::AllocArray< T >::AllocArray ( Allocator &  allocator,
size_t  maxElem,
uint32_t  rank 
)
inline

Allocate one block for the shape, the reference count and maxElem elements, and set the rank, every shape entry to 0 and the count to 1.

The elements are not constructed.

◆ AllocArray() [2/2]

template<typename T >
psalg::AllocArray< T >::AllocArray ( const AllocArray< T > &  other)
inline

Share other's block and increment the reference count.

◆ ~AllocArray()

template<typename T >
virtual psalg::AllocArray< T >::~AllocArray ( )
inlinevirtual

Log a syslog error if the count is already <= 0, decrement it, and when it reaches 0 call the destructor of each of the num_elem() elements and free the block.

Member Function Documentation

◆ _refCnt()

template<typename T >
uint32_t & psalg::AllocArray< T >::_refCnt ( )
inline

Return a reference to the shared reference count; public so cython can reach it (per the comment above).

◆ decRefCnt()

template<typename T >
void psalg::AllocArray< T >::decRefCnt ( )
inline

Decrement the shared reference count.

◆ incRefCnt()

template<typename T >
void psalg::AllocArray< T >::incRefCnt ( )
inline

Increment the shared reference count.

◆ operator=()

template<typename T >
AllocArray< T > & psalg::AllocArray< T >::operator= ( const AllocArray< T > &  other)
inline

Decrement this object's count, freeing its block with its allocator when the count reaches 0, then share other's block and increment that count.

Self-assignment does nothing.

Returns
*this.

Member Data Documentation

◆ _allocator

template<typename T >
Allocator& psalg::AllocArray< T >::_allocator
protected

◆ _refCntPtr

template<typename T >
uint32_t* psalg::AllocArray< T >::_refCntPtr
protected

The documentation for this class was generated from the following file: