ATLAS Offline Software
Loading...
Searching...
No Matches
CaloRec::WritableArrayData< N > Class Template Reference

#include <Array.h>

Inheritance diagram for CaloRec::WritableArrayData< N >:
Collaboration diagram for CaloRec::WritableArrayData< N >:

Public Types

enum  { NDIM = N }
 The number of dimensions of the array. More...
typedef ArrayIteratorChooser< N >::const_iterator const_iterator
 The iterator for this container.

Public Member Functions

 WritableArrayData (const unsigned int shape[])
 Constructor.
 WritableArrayData (const std::vector< unsigned int > &shape)
 Constructor.
WritableArray< N-1 > operator[] (unsigned int i)
 Array indexing.
Array< N-1 > operator[] (unsigned int i) const
 Array indexing.
Arrayeltptr ()
 Return a direct pointer to array elements.
const Arrayeltptr () const
 Return a direct pointer to array elements.
bool valid () const
 Test for validity.
std::vector< unsigned int > shape () const
 Return the array shape.
unsigned int size (unsigned int dim=0) const
 Return the size of the array along one dimension.
const_iterator begin () const
 Return an iterator pointing at the beginning of the container.
const_iterator end () const
 Return an iterator pointing past the end of the container.
void write_array (std::ostream &stream) const
 Creates a text representation of the array content.

Protected Attributes

const Arrayrepm_rep
 Pointer to the representation.
unsigned int m_offs
 Offset in the Arrayrep's data of the first element of this array.

Private Member Functions

void init_sizes (bool resize_data=false)
 Initialize the m_sizes vector from the m_shape vector.
void write_array (std::ostream &stream) const
 Creates a text representation of the array content.
void write_subarray (std::ostream &stream, std::vector< Arrayelt >::size_type &idx, unsigned dimIndex) const
 Helper function for write_array.

Private Attributes

std::vector< Arrayeltm_data
 The array data, stored using the C array ordering.
std::vector< unsigned int > m_shape
 The array shape.
std::vector< unsigned int > m_sizes
 Subarray sizes, for faster access.
Arrayrepm_rep_nc
 The underlying array representation, non-const copy.

Detailed Description

template<unsigned int N>
class CaloRec::WritableArrayData< N >

Definition at line 772 of file Control/CxxUtils/CxxUtils/Array.h.

Member Typedef Documentation

◆ const_iterator

template<unsigned int N>
typedef ArrayIteratorChooser<N>::const_iterator CxxUtils::Array< N >::const_iterator
inherited

The iterator for this container.

Definition at line 141 of file Control/CxxUtils/CxxUtils/Array.h.

Member Enumeration Documentation

◆ anonymous enum

template<unsigned int N>
anonymous enum
inherited

The number of dimensions of the array.

Enumerator
NDIM 

Definition at line 138 of file Control/CxxUtils/CxxUtils/Array.h.

Constructor & Destructor Documentation

◆ WritableArrayData() [1/2]

template<unsigned int N>
CxxUtils::WritableArrayData< N >::WritableArrayData ( const unsigned int shape[])

Constructor.

Parameters
shapeThe shape of the array, as a C array. Should be N elements long.

The shape is the size of the array along each dimension.

◆ WritableArrayData() [2/2]

template<unsigned int N>
CxxUtils::WritableArrayData< N >::WritableArrayData ( const std::vector< unsigned int > & shape)

Constructor.

Parameters
shapeThe shape of the array, as a std::vector. Should be N elements long.

The shape is the size of the array along each dimension.

Member Function Documentation

◆ begin()

template<unsigned int N>
const_iterator CxxUtils::Array< N >::begin ( ) const
inherited

Return an iterator pointing at the beginning of the container.

Returns
An iterator pointing at the beginning of the container.

◆ end()

template<unsigned int N>
const_iterator CxxUtils::Array< N >::end ( ) const
inherited

Return an iterator pointing past the end of the container.

Returns
An iterator pointing past the end of the container.

◆ init_sizes()

void CaloRec::Arrayrep::init_sizes ( bool resize_data = false)
inherited

Initialize the m_sizes vector from the m_shape vector.

Parameters
resize_dataShould m_data be resized appropriately?

The contents of the m_sizes vector are initialized from the contents of the m_shape vector. If resize_data is true, then the size of m_data is changed to the total size indicated by m_shape. Otherwise, we verify that m_data has the correct size, and raise an assertion if not.

Definition at line 34 of file Arrayrep.cxx.

35{
36 // Don't do anything if we've already done this, or if the array
37 // is empty.
38 if (m_sizes.size() < m_shape.size())
39 {
40 // Calculate the m_sizes array.
41 unsigned int sz = 1;
42 unsigned int dim = m_shape.size();
43 m_sizes.resize (dim);
44 m_sizes[0] = 1;
45 for (unsigned int i=0; i < dim; i++) {
46 m_sizes[i] = sz;
47 sz *= m_shape[dim-1 - i];
48 }
49
50 if (resize_data) {
51 // Resize m_data to the proper size.
52 m_data.resize (sz);
53 }
54 else {
55 // Check that m_data has the correct size.
56 assert (sz == m_data.size());
57 }
58 }
59}
static Double_t sz
std::vector< Arrayelt > m_data
The array data, stored using the C array ordering.
std::vector< unsigned int > m_sizes
Subarray sizes, for faster access.
std::vector< unsigned int > m_shape
The array shape.

◆ operator[]() [1/2]

template<unsigned int N>
WritableArray< N-1 > CxxUtils::WritableArray< N >::operator[] ( unsigned int i)
inherited

Array indexing.

Parameters
iThe desired index. Must be less than the array size along this dimension.
Returns
The i'th N-1 dimensional subarray in the array.

Note that this operation is not available if N is 0.

◆ operator[]() [2/2]

template<unsigned int N>
Array< N-1 > CxxUtils::WritableArray< N >::operator[] ( unsigned int i) const
inherited

Array indexing.

Parameters
iThe desired index. Must be less than the array size along this dimension.
Returns
The i'th N-1 dimensional subarray in the array.

Note that this operation is not available if N is 0.

◆ ptr() [1/2]

template<unsigned int N>
const Arrayelt * CxxUtils::Array< N >::ptr ( ) const
inherited

Return a direct pointer to array elements.

Returns
A pointer to the first array elements.

Subsequent elements follow in standard C indexing order.

◆ ptr() [2/2]

template<unsigned int N>
Arrayelt * CxxUtils::WritableArray< N >::ptr ( )
inherited

Return a direct pointer to array elements.

Returns
A pointer to the first array elements.

Subsequent elements follow in standard C indexing order.

◆ shape()

template<unsigned int N>
std::vector< unsigned int > CxxUtils::Array< N >::shape ( ) const
inherited

Return the array shape.

Returns
The array shape.

The array shape is vector with one element for each array dimension, giving the size of the array along that dimension.

◆ size()

template<unsigned int N>
unsigned int CxxUtils::Array< N >::size ( unsigned int dim = 0) const
inherited

Return the size of the array along one dimension.

Parameters
dimThe dimension of the size to retrieve. Must be less than the number of dimensions.
Returns
The array size along dimension dim.

◆ valid()

template<unsigned int N>
bool CxxUtils::Array< N >::valid ( ) const
inherited

Test for validity.

Returns
True if the Array is associated with an Arrayrep, false if not.

◆ write_array() [1/2]

void CaloRec::Arrayrep::write_array ( std::ostream & stream) const
inherited

Creates a text representation of the array content.

Helper function for write_array.

Parameters
std::ostreamwhere the text should be written

Writes the content of the array to a ostream. The sub-arrays are enclosed by square brackets and separated by commas.

Parameters
streamwhere the array should be written
idxCurrent index in m_data
dimIndexCurrent index in m_shapes

Calls itself recursively with dimIndex-1

Definition at line 245 of file Arrayrep.cxx.

245 {
246 if (!m_data.size()) {//Empty array
247 stream << "[ ]" << std::endl;
248 return;
249 }
250
251 if (!m_shape.size()) {//Single element
252 stream << m_data[0] << std::endl;
253 return;
254 }
255
256 //All other cases: Array of dimension>=1
257 //check consistency of Array
258 unsigned totSize=m_shape[0];
259 for (unsigned i=1;i<m_shape.size();i++)
260 totSize=totSize*m_shape[i];
261 if (totSize!=m_data.size())
262 error("","Array is inconsistent!");
263
264 std::vector<Arrayelt>::size_type dataIndex=0;
265 write_subarray(stream,dataIndex,0);
266 stream << "]" << std::endl;
267 return;
268}
void write_subarray(std::ostream &stream, std::vector< Arrayelt >::size_type &idx, unsigned dimIndex) const
Helper function for write_array.
Definition Arrayrep.cxx:279

◆ write_array() [2/2]

template<unsigned int N>
void CxxUtils::Array< N >::write_array ( std::ostream & stream) const
inherited

Creates a text representation of the array content.

Parameters
std::ostreamwhere the text should be written

Writes the content of the array to a ostream. The sub-arrays are enclosed by square-brackets and separated by commas.

◆ write_subarray()

void CaloRec::Arrayrep::write_subarray ( std::ostream & stream,
std::vector< Arrayelt >::size_type & idx,
unsigned dimIndex ) const
inherited

Helper function for write_array.

Creates a text representation of the array content.

Parameters
streamwhere the array should be written
idxCurrent index in m_data
dimIndexCurrent index in m_shapes

Calls itself recursively with dimIndex-1

Parameters
std::ostreamwhere the text should be written

Writes the content of the array to a ostream. The sub-arrays are enclosed by square brackets and separated by commas.

Definition at line 279 of file Arrayrep.cxx.

279 {
280 if (dimIndex<(m_shape.size()-1)) {
281 stream << "[\n ";
282 for (unsigned i=0;i<m_shape[dimIndex];i++) {
283 write_subarray(stream,idx,dimIndex+1);
284 if (i==m_shape[dimIndex]-1)
285 stream << "]\n ";
286 else
287 stream << "],\n ";
288 }
289 }
290 else { // last dimension
291 stream << "[" << m_data[idx++];
292 for (unsigned i=1;i<m_shape[dimIndex];i++)
293 stream << ", " << m_data[idx++];
294 }
295 return;
296}

Member Data Documentation

◆ m_data

std::vector<Arrayelt> CaloRec::Arrayrep::m_data
inherited

The array data, stored using the C array ordering.

Definition at line 102 of file Control/CxxUtils/CxxUtils/Arrayrep.h.

◆ m_offs

template<unsigned int N>
unsigned int CxxUtils::Array< N >::m_offs
protectedinherited

Offset in the Arrayrep's data of the first element of this array.

Definition at line 255 of file Control/CxxUtils/CxxUtils/Array.h.

◆ m_rep

template<unsigned int N>
const Arrayrep* CxxUtils::Array< N >::m_rep
protectedinherited

Pointer to the representation.

Null if this instance was created using the default constructor.

Definition at line 252 of file Control/CxxUtils/CxxUtils/Array.h.

◆ m_rep_nc

template<unsigned int N>
Arrayrep* CxxUtils::WritableArray< N >::m_rep_nc
privateinherited

The underlying array representation, non-const copy.

Definition at line 704 of file Control/CxxUtils/CxxUtils/Array.h.

◆ m_shape

std::vector<unsigned int> CaloRec::Arrayrep::m_shape
inherited

The array shape.

One entry per dimension, giving the size of each dimension.

Definition at line 106 of file Control/CxxUtils/CxxUtils/Arrayrep.h.

◆ m_sizes

std::vector<unsigned int> CaloRec::Arrayrep::m_sizes
inherited

Subarray sizes, for faster access.

See above. This member could be considered transient.

Definition at line 110 of file Control/CxxUtils/CxxUtils/Arrayrep.h.


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