ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CxxUtils::WritableArrayData< N > Class Template Reference

#include <Array.h>

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

Public Member Functions

 WritableArrayData (const unsigned int shape[])
 Constructor. More...
 
 WritableArrayData (const std::vector< unsigned int > &shape)
 Constructor. More...
 
WritableArray< N-1 > operator[] (unsigned int i)
 Array indexing. More...
 
Array< N-1 > operator[] (unsigned int i) const
 Array indexing. More...
 
Arrayelt * ptr ()
 Return a direct pointer to array elements. More...
 

Private Member Functions

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

Private Attributes

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

Detailed Description

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

Definition at line 775 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

◆ 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 }

◆ operator[]() [1/2]

WritableArray<N-1> CxxUtils::WritableArray::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]

Array<N-1> CxxUtils::WritableArray::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()

Arrayelt* CxxUtils::WritableArray::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.

◆ write_array()

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 }

◆ 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_rep_nc

Arrayrep* CxxUtils::WritableArray::m_rep_nc
privateinherited

The underlying array representation, non-const copy.

Definition at line 707 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:
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
fitman.sz
sz
Definition: fitman.py:527
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
CaloRec::Arrayrep::m_data
std::vector< Arrayelt > m_data
The array data, stored using the C array ordering.
Definition: Control/CxxUtils/CxxUtils/Arrayrep.h:102
lumiFormat.i
int i
Definition: lumiFormat.py:92
CaloRec::Arrayrep::m_sizes
std::vector< unsigned int > m_sizes
Subarray sizes, for faster access.
Definition: Control/CxxUtils/CxxUtils/Arrayrep.h:110
CaloRec::Arrayrep::write_subarray
void write_subarray(std::ostream &stream, std::vector< Arrayelt >::size_type &idx, unsigned dimIndex) const
Helper function for write_array.
Definition: Arrayrep.cxx:279
CaloRec::Arrayrep::m_shape
std::vector< unsigned int > m_shape
The array shape.
Definition: Control/CxxUtils/CxxUtils/Arrayrep.h:106
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
get_generator_info.error
error
Definition: get_generator_info.py:40