ATLAS Offline Software
Loading...
Searching...
No Matches
MultiDimArray< T, N > Class Template Reference

Multi-dimensional array with a compile-time number of dimensions, and a run-time complete freedom over the size of the dimensions. More...

#include <MultiDimArray.h>

Collaboration diagram for MultiDimArray< T, N >:

Public Types

typedef MultiDimArray< T, N > ThisType
typedef MultiDimArrayTypes< T, N >::SubType SubType
typedef T::ValueType ValueType

Public Member Functions

 MultiDimArray ()
 ~MultiDimArray ()
 MultiDimArray (const MultiDimArray &)
MultiDimArrayoperator= (const MultiDimArray &)
void clear ()
SubTypeoperator[] (int index)
const SubTypeoperator[] (int index) const
int minIndex () const
int maxIndex () const
unsigned int size () const
 Size of this field.
unsigned int depth () const
 Depth of this field, i.e.
bool isInRange (int index) const
 Check that an index is in the range of the this field.
unsigned int totalSize () const
 The total number of elements, including invalid (=default) holes, from this field downwards.
unsigned int validSize () const
 The total number of valid (=non-default) elements from this field downwards.
void dump (std::ostream &os=std::cout) const
 Dump the complete table to an output stream.
void dump (const std::string &prefix, std::ostream &os=std::cout) const
 Dump the complete table to an output stream, with an additional prefix before each line.
std::string dumpToString () const
 Dump the complete table into a string.
std::string dumpToString (const std::string &prefix) const
 Dump the complete table into a string, with an additional prefix before each line.
template<class K>
void dumpOneEntry (const K &indices, std::ostream &os=std::cout) const
 Dump one entry with given indices to an output stream.
template<class K>
std::string dumpOneEntryToString (const K &indices) const
 Dump one entry with given indices into a string.

Static Public Member Functions

static SubType defaultSubType ()
static ValueType defaultValueType ()
static const SubTypeinvalidSubType ()

Private Attributes

SubTypem_data
int m_minIndex
unsigned int m_size

Static Private Attributes

static SubType s_invalidSubType

Detailed Description

template<class T, unsigned int N>
class MultiDimArray< T, N >

Multi-dimensional array with a compile-time number of dimensions, and a run-time complete freedom over the size of the dimensions.

It is used by IdentifierToHash to provide fast access in identifier to hash conversions. It is obtained as a vector of pointers to MultiDimArrayTypes<T,N>.

Definition at line 73 of file MultiDimArray.h.

Member Typedef Documentation

◆ SubType

template<class T, unsigned int N>
typedef MultiDimArrayTypes<T,N>::SubType MultiDimArray< T, N >::SubType

Definition at line 79 of file MultiDimArray.h.

◆ ThisType

template<class T, unsigned int N>
typedef MultiDimArray<T,N> MultiDimArray< T, N >::ThisType

Definition at line 78 of file MultiDimArray.h.

◆ ValueType

template<class T, unsigned int N>
typedef T::ValueType MultiDimArray< T, N >::ValueType

Definition at line 80 of file MultiDimArray.h.

Constructor & Destructor Documentation

◆ MultiDimArray() [1/2]

template<class T, unsigned int N>
MultiDimArray< T, N >::MultiDimArray ( )
inline

Definition at line 162 of file MultiDimArray.h.

163 : m_data(0), m_minIndex(0), m_size(0)
164{
165#ifdef MULTIDIMARRAY_DEBUG
167 MsgStream log(Athena::getMessageSvc(),"MultiDimArray<T,N>");
168 log<<MSG::DEBUG<<"Creating MultiDimArray<" << N << ">" << " at " << this << " #objects: " << s_objectCount<<endmsg;
169#endif
170}
Multi-dimensional array with a compile-time number of dimensions, and a run-time complete freedom ove...
SubType * m_data
unsigned int m_size

◆ ~MultiDimArray()

template<class T, unsigned int N>
MultiDimArray< T, N >::~MultiDimArray ( )
inline

Definition at line 173 of file MultiDimArray.h.

173 {
174#ifdef MULTIDIMARRAY_DEBUG
176 MsgStream log(Athena::getMessageSvc(),"MultiDimArray<T,N>");
177 log<<MSG::DEBUG<<"Deleting MultiDimArray<" << N << ">" << " at " << this << " #objects: " << s_objectCount<<endmsg;
178#endif
179 delete[] m_data;
180}

◆ MultiDimArray() [2/2]

template<class T, unsigned int N>
MultiDimArray< T, N >::MultiDimArray ( const MultiDimArray< T, N > & rhs)
inline

Definition at line 183 of file MultiDimArray.h.

184 : m_data(0), m_minIndex(0), m_size(0)
185{
186#ifdef MULTIDIMARRAY_DEBUG
188 MsgStream log(Athena::getMessageSvc(),"MultiDimArray<T,N>");
189 log<<MSG::DEBUG<<"Copying MultiDimArray<" << N << ">" << " at " << this << " #objects: " << s_objectCount<<endmsg;
190#endif
191 operator=( rhs );
192}
MultiDimArray & operator=(const MultiDimArray &)

Member Function Documentation

◆ clear()

template<class T, unsigned int N>
void MultiDimArray< T, N >::clear ( )
inline

Definition at line 195 of file MultiDimArray.h.

195 {
196 delete[] m_data;
197 m_data = 0;
198 m_size = 0;
199 m_minIndex = 0;
200}

◆ defaultSubType()

template<class T, unsigned int N>
MultiDimArray< T, N >::SubType MultiDimArray< T, N >::defaultSubType ( )
inlinestatic

Definition at line 147 of file MultiDimArray.h.

147 {
149}
static ThisType defaultThisType()

◆ defaultValueType()

template<class T, unsigned int N>
MultiDimArray< T, N >::ValueType MultiDimArray< T, N >::defaultValueType ( )
inlinestatic

Definition at line 152 of file MultiDimArray.h.

152 {
154}

◆ depth()

template<class T, unsigned int N>
unsigned int MultiDimArray< T, N >::depth ( ) const
inline

Depth of this field, i.e.

the number of fields from this fields downwards, including this field. It is equal to this field number plus one.

Definition at line 218 of file MultiDimArray.h.

218 {
219 return N;
220}

◆ dump() [1/2]

template<class T, unsigned int N>
void MultiDimArray< T, N >::dump ( const std::string & prefix,
std::ostream & os = std::cout ) const
inline

Dump the complete table to an output stream, with an additional prefix before each line.

Definition at line 386 of file MultiDimArray.h.

386 {
387 ::dump( *this, os, prefix + "(" );
388 os.flush();
389}

◆ dump() [2/2]

template<class T, unsigned int N>
void MultiDimArray< T, N >::dump ( std::ostream & os = std::cout) const
inline

Dump the complete table to an output stream.

Definition at line 380 of file MultiDimArray.h.

380 {
381 ::dump( *this, os );
382 os.flush();
383}

◆ dumpOneEntry()

template<class T, unsigned int N>
template<class K>
void MultiDimArray< T, N >::dumpOneEntry ( const K & indices,
std::ostream & os = std::cout ) const
inline

Dump one entry with given indices to an output stream.

Definition at line 423 of file MultiDimArray.h.

423 {
424 ::dumpOneEntry( *this, indices, os );
425}
void dumpOneEntry(const K &indices, std::ostream &os=std::cout) const
Dump one entry with given indices to an output stream.

◆ dumpOneEntryToString()

template<class T, unsigned int N>
template<class K>
std::string MultiDimArray< T, N >::dumpOneEntryToString ( const K & indices) const

Dump one entry with given indices into a string.

Definition at line 429 of file MultiDimArray.h.

429 {
432 return oss.str();
433}

◆ dumpToString() [1/2]

template<class T, unsigned int N>
std::string MultiDimArray< T, N >::dumpToString ( ) const
inline

Dump the complete table into a string.

Definition at line 392 of file MultiDimArray.h.

392 {
394 dump( oss );
395 return oss.str();
396}
void dump(std::ostream &os=std::cout) const
Dump the complete table to an output stream.

◆ dumpToString() [2/2]

template<class T, unsigned int N>
std::string MultiDimArray< T, N >::dumpToString ( const std::string & prefix) const
inline

Dump the complete table into a string, with an additional prefix before each line.

Definition at line 399 of file MultiDimArray.h.

399 {
401 dump( prefix, oss );
402 return oss.str();
403}

◆ invalidSubType()

template<class T, unsigned int N>
const MultiDimArray< T, N >::SubType & MultiDimArray< T, N >::invalidSubType ( )
inlinestatic

Definition at line 157 of file MultiDimArray.h.

157 {
158 return s_invalidSubType;
159}
static SubType s_invalidSubType

◆ isInRange()

template<class T, unsigned int N>
bool MultiDimArray< T, N >::isInRange ( int index) const
inline

Check that an index is in the range of the this field.

Definition at line 223 of file MultiDimArray.h.

223 {
224 return index >= minIndex() && index <= maxIndex();
225}
int maxIndex() const
int minIndex() const

◆ maxIndex()

template<class T, unsigned int N>
int MultiDimArray< T, N >::maxIndex ( ) const
inline

Definition at line 208 of file MultiDimArray.h.

208 {
209 return m_minIndex + m_size - 1;
210}

◆ minIndex()

template<class T, unsigned int N>
int MultiDimArray< T, N >::minIndex ( ) const
inline

Definition at line 203 of file MultiDimArray.h.

203 {
204 return m_minIndex;
205}

◆ operator=()

template<class T, unsigned int N>
MultiDimArray< T, N > & MultiDimArray< T, N >::operator= ( const MultiDimArray< T, N > & rhs)

Definition at line 228 of file MultiDimArray.h.

228 {
229#ifdef MULTIDIMARRAY_DEBUG
230 MsgStream log(Athena::getMessageSvc(),"MultiDimArray<T,N>");
231 log<<MSG::DEBUG<<"Assigning MultiDimArray<" << N << ">" << " to " << this << " from " << &rhs<<endmsg;
232#endif
233 // ensure equal data size
234 if ( m_size != rhs.m_size ) {
235 delete[] m_data;
236 m_size = rhs.m_size;
237 if ( m_size ) {
238 m_data = new SubType[m_size];
239 } else {
240 m_data = 0;
241 }
242 }
243 // copy the data
244 for ( unsigned int i = 0; i < m_size; ++i ) m_data[i] = rhs.m_data[i];
245 // set others
247
248 return *this;
249}
MultiDimArrayTypes< T, N >::SubType SubType

◆ operator[]() [1/2]

template<class T, unsigned int N>
MultiDimArray< T, N >::SubType & MultiDimArray< T, N >::operator[] ( int index)

Definition at line 262 of file MultiDimArray.h.

262 {
263#ifdef MULTIDIMARRAY_DEBUG
264 MsgStream log(Athena::getMessageSvc(),"MultiDimArray<T,N>");
265#endif if ( !m_data ) {
267 m_size = 1;
268 m_data = new SubType[1];
270#ifdef MULTIDIMARRAY_DEBUG
271 log<<MSG::DEBUG<<"MultiDimArray<" << N << ">::operator["<< index << "]" << " at " << this << ":" << " new data array. size=" << m_size << " range=(" << minIndex() << "," << maxIndex() << ")"<<endmsg;
272#endif
273 } else if ( index > maxIndex() ) {
274 // add to vector at back
275 unsigned int oldSize = m_size;
276 int nAdd = index - maxIndex();
277 m_size += nAdd;
279 // copy old data and set new data to invalid
280 unsigned int i = 0;
281 for ( ; i < oldSize; ++i ) newData[i] = m_data[i];
282 for ( ; i < m_size ; ++i ) newData[i] = s_invalidSubType;
283 delete[] m_data;
284 m_data = newData;
285#ifdef MULTIDIMARRAY_DEBUG
286 log<<MSG::DEBUG<<"MultiDimArray<" << N << ">::operator["<< index << "]" << " at " << this << ":" << " added " << nAdd << " at back. size=" << m_size << " range=(" << minIndex() << "," << maxIndex() << ")"<<endmsg;
287#endif
288 } else if ( index < minIndex() ) {
289 // add to vector at front
290 unsigned int nAdd = minIndex() - index;
291 m_size += nAdd;
293 // copy old data and set new data to invalid
294 unsigned int i = 0;
295 for ( ; i < nAdd ; ++i ) newData[i] = s_invalidSubType;
296 for ( ; i < m_size; ++i ) newData[i] = m_data[i-nAdd];
297 delete[] m_data;
298 m_data = newData;
300#ifdef MULTIDIMARRAY_DEBUG
301 log<<MSG::DEBUG<<"MultiDimArray<" << N << ">::operator["<< index << "]" << " at " << this << ":" << " added " << nAdd << " at front. size=" << m_size << " range=(" << minIndex() << "," << maxIndex() << ")"<<endmsg;
302#endif
303 }
304 // return ref to indexed value
305 return m_data[index - m_minIndex];
306}

◆ operator[]() [2/2]

template<class T, unsigned int N>
const MultiDimArray< T, N >::SubType & MultiDimArray< T, N >::operator[] ( int index) const
inline

Definition at line 252 of file MultiDimArray.h.

252 {
253 if ( !isInRange( index ) ) {
254 MsgStream log(Athena::getMessageSvc(),"MultiDimArray<T,N>");
255 log<<MSG::WARNING<<"MultiDimArray<" << N << ">::operator["<< index << "]" << " index out of range (" << minIndex() << "," << maxIndex() << ")"<<endmsg;
256 return s_invalidSubType;
257 }
258 return m_data[index - m_minIndex];
259}
bool isInRange(int index) const
Check that an index is in the range of the this field.

◆ size()

template<class T, unsigned int N>
unsigned int MultiDimArray< T, N >::size ( ) const
inline

Size of this field.

Definition at line 213 of file MultiDimArray.h.

213 {
214 return m_size;
215}

◆ totalSize()

template<class T, unsigned int N>
unsigned int MultiDimArray< T, N >::totalSize ( ) const
inline

The total number of elements, including invalid (=default) holes, from this field downwards.

Definition at line 348 of file MultiDimArray.h.

348 {
349 return ::totalSize( *this );
350}

◆ validSize()

template<class T, unsigned int N>
unsigned int MultiDimArray< T, N >::validSize ( ) const
inline

The total number of valid (=non-default) elements from this field downwards.

Definition at line 353 of file MultiDimArray.h.

353 {
354 return ::validSize( *this );
355}

Member Data Documentation

◆ m_data

template<class T, unsigned int N>
SubType* MultiDimArray< T, N >::m_data
private

Definition at line 127 of file MultiDimArray.h.

◆ m_minIndex

template<class T, unsigned int N>
int MultiDimArray< T, N >::m_minIndex
private

Definition at line 128 of file MultiDimArray.h.

◆ m_size

template<class T, unsigned int N>
unsigned int MultiDimArray< T, N >::m_size
private

Definition at line 129 of file MultiDimArray.h.

◆ s_invalidSubType

template<class T, unsigned int N>
SubType MultiDimArray< T, N >::s_invalidSubType
staticprivate

Definition at line 130 of file MultiDimArray.h.


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