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

Non-owning view of an array of T: a data pointer, a pointer to a shape array and a rank. More...

#include <Array.hh>

Inherited by psalg::NDArray< float >, psalg::NDArray< common_mode_t >, psalg::NDArray< pedestals_t >, psalg::NDArray< pixel_rms_t >, psalg::NDArray< pixel_status_t >, psalg::NDArray< pixel_gain_t >, psalg::NDArray< pixel_offset_t >, psalg::NDArray< pixel_bkgd_t >, psalg::NDArray< pixel_mask_t >, psalg::NDArray< const pixel_size_t >, psalg::NDArray< double >, psalg::NDArray< uint16_t >, psalg::NDArray< uint32_t >, psalg::NDArray< raw_t >, psalg::NDArray< calib_t >, psalg::NDArray< image_t >, psalg::NDArray< raw_cspad_t >, psalg::NDArray< raw_jungfrau_t >, psalg::NDArray< opal_raw_t >, psalg::NDArray< opal_calib_t >, psalg::NDArray< opal_pedestals_t >, psalg::NDArray< pnccd_raw_t >, psalg::NDArray< pnccd_calib_t >, psalg::NDArray< pnccd_pedestals_t >, psalg::AllocArray< T >, and psalg::NDArray< T >.

Public Member Functions

 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 * _shape
 
T * _data
 
uint32_t _rank
 

Detailed Description

template<typename T>
class XtcData::Array< T >

Non-owning view of an array of T: a data pointer, a pointer to a shape array and a rank.

Copies are shallow (pointers only). operator() computes C-order (row-major) offsets and aborts with a message if an index is out of range.

Constructor & Destructor Documentation

◆ Array() [1/3]

template<typename T >
XtcData::Array< T >::Array ( void *  data,
uint32_t *  shape,
uint32_t  rank 
)
inline

Wrap data (reinterpreted as T*), shape and rank; nothing is copied.

◆ Array() [2/3]

template<typename T >
XtcData::Array< T >::Array ( )
inline

Construct an empty view: null data and shape pointers, rank 0.

◆ Array() [3/3]

template<typename T >
XtcData::Array< T >::Array ( const Array< T > &  a)
inline

Copy the data pointer, shape pointer and rank of a (shallow copy).

Member Function Documentation

◆ const_data()

template<typename T >
const T * XtcData::Array< T >::const_data ( ) const
inline

Return the data pointer as const T*.

◆ data()

template<typename T >
T * XtcData::Array< T >::data ( )
inline

Return the data pointer.

◆ num_elem()

template<typename T >
uint64_t XtcData::Array< T >::num_elem ( ) const
inline

Return the product of shape[0] .

. shape[rank-1], or 0 if the shape pointer is null. With rank 0 and a non-null shape it returns shape[0].

◆ operator()() [1/5]

template<typename T >
T & XtcData::Array< T >::operator() ( unsigned  i)
inline

Return a reference to element i.

Aborts with a message if i >= shape[0]; the rank is not checked.

◆ operator()() [2/5]

template<typename T >
T & XtcData::Array< T >::operator() ( unsigned  i,
unsigned  j 
)
inline

Return a reference to element (i, j) at offset i*shape[1]+j.

Aborts with a message if an index is out of range; the rank is not checked.

◆ operator()() [3/5]

template<typename T >
T & XtcData::Array< T >::operator() ( unsigned  i,
unsigned  j,
unsigned  k 
)
inline

Return a reference to element (i, j, k) at the row-major offset.

Aborts with a message if an index is out of range; the rank is not checked.

◆ operator()() [4/5]

template<typename T >
T & XtcData::Array< T >::operator() ( unsigned  i,
unsigned  j,
unsigned  k,
unsigned  l 
)
inline

Return a reference to element (i, j, k, l) at the row-major offset.

Aborts with a message if an index is out of range; the rank is not checked.

◆ operator()() [5/5]

template<typename T >
T & XtcData::Array< T >::operator() ( unsigned  i,
unsigned  j,
unsigned  k,
unsigned  l,
unsigned  m 
)
inline

Return a reference to element (i, j, k, l, m) at the row-major offset.

Aborts with a message if an index is out of range; the rank is not checked.

◆ operator=()

template<typename T >
Array & XtcData::Array< T >::operator= ( const Array< T > &  o)
inline

Copy the data pointer, shape pointer and rank of o (shallow); self-assignment does nothing.

Returns
*this.

◆ rank()

template<typename T >
uint32_t XtcData::Array< T >::rank ( ) const
inline

Return the rank.

◆ set_data()

template<typename T >
void XtcData::Array< T >::set_data ( void *  data)
inline

Set the data pointer (reinterpreted as T*).

◆ set_rank()

template<typename T >
void XtcData::Array< T >::set_rank ( uint32_t  rank)
inline

Set the rank.

◆ set_shape()

template<typename T >
void XtcData::Array< T >::set_shape ( uint32_t *  shape)
inline

Set the shape pointer.

◆ shape() [1/2]

template<typename T >
uint32_t * XtcData::Array< T >::shape ( ) const
inline

Return the shape pointer (not a copy).

◆ shape() [2/2]

template<typename T >
void XtcData::Array< T >::shape ( uint32_t  a,
uint32_t  b = 0,
uint32_t  c = 0,
uint32_t  d = 0,
uint32_t  e = 0 
)
inline

Write a, b, c, d, e into shape[0..4] (always five entries).

Aborts with a message if the rank is 0 or >= MaxRank.

Member Data Documentation

◆ _data

template<typename T >
T* XtcData::Array< T >::_data
protected

◆ _rank

template<typename T >
uint32_t XtcData::Array< T >::_rank
protected

◆ _shape

template<typename T >
uint32_t* XtcData::Array< T >::_shape
protected

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