CaloRec::Arrayrep Class Reference

Representation class for Array's. More...

#include <Arrayrep.h>

Inheritance diagram for CaloRec::Arrayrep:
CxxUtils::WritableArrayData< N >

List of all members.

Public Member Functions

 Arrayrep ()
 Default constructor.
 Arrayrep (const std::string &str, const std::string &context="")
 Construct from a string.
 Arrayrep (const std::vector< unsigned int > &shape)
 Construct an empty array of a given shape.
 Arrayrep (const unsigned int shape[], unsigned int n)
 Construct an empty array of a given shape.
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.

Public Attributes

std::vector< Arrayelt > m_data
 The array data, stored using the C array ordering.
std::vector< unsigned int > m_shape
std::vector< unsigned int > m_sizes

Detailed Description

Representation class for Array's.

This class is used for the implementation of multidimensional array constants. The user interface is provided by the Array template class. Given an Array<N> a, we want a[i] to be an Array<N-1>. However, we don't want to have to copy the array data. Thus, the Array class just holds a reference to the actual array data. Those data are stored in an instance of Arrayrep.

An Arrayrep is defined by two vectors: one giving all the array elements, and the second giving the shape of the array. (A shape is a vector with one integer per array dimension, the integers giving the size of the dimensions.)

We maintain one additional array as an optimization. m_sizes[0] contains the total size in elements of the array resulting from a single indexing operation. m_sizes[1] contains the size of the array resulting from two indexing operations, and so on. m_sizes has the same length as m_shape, but the last element is always 1. The function init_sizes will initialize the m_sizes array from the contents of m_shape.

A scalar (0-dimensional array) is represented by m_shape (and m_sizes) being empty, and m_data having a single element.

If both m_shape and m_data are empty, then the representation is uninitialized.


Constructor & Destructor Documentation

CaloRec::Arrayrep::Arrayrep (  )  [inline]

Default constructor.

This makes an uninitialized Arrayrep.

CaloRec::Arrayrep::Arrayrep ( const std::string &  str,
const std::string &  context = "" 
) [explicit]

Construct from a string.

Parameters:
str The string to convert.
context An optional string to use for error reporting.

Parse the string and initialize the array. This string should be like `[[1, 2], [3, 4]]'.

CaloRec::Arrayrep::Arrayrep ( const std::vector< unsigned int > &  shape  )  [explicit]

Construct an empty array of a given shape.

Parameters:
shape The shape of the array.

Initialize an array of a given shape. The array will contain all 0's.

CaloRec::Arrayrep::Arrayrep ( const unsigned int  shape[],
unsigned int  n 
) [explicit]

Construct an empty array of a given shape.

Parameters:
shape The shape of the array.
n The length of the shape array.

Initialize an array of a given shape. The array will contain all 0's. This version is more convenient to call with a constant shape.


Member Function Documentation

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

Initialize the m_sizes vector from the m_shape vector.

Parameters:
resize_data Should 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.

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

Creates a text representation of the array content.

Helper function for write_array.

Parameters:
std::ostream where 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:
stream where the array should be written
idx Current index in m_data
dimIndex Current index in m_shapes

Calls itself recursively with dimIndex-1

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

Helper function for write_array.

Creates a text representation of the array content.

Parameters:
stream where the array should be written
idx Current index in m_data
dimIndex Current index in m_shapes

Calls itself recursively with dimIndex-1

Parameters:
std::ostream where 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.


Member Data Documentation

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

The array shape. One entry per dimension, giving the size of each dimension.

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

Subarray sizes, for faster access. See above. This member could be considered transient.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 1 Dec 2017 for RootCore Packages by  doxygen 1.6.1