ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
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. More...
 
unsigned int depth () const
 Depth of this field, i.e. More...
 
bool isInRange (int index) const
 Check that an index is in the range of the this field. More...
 
unsigned int totalSize () const
 The total number of elements, including invalid (=default) holes, from this field downwards. More...
 
unsigned int validSize () const
 The total number of valid (=non-default) elements from this field downwards. More...
 
void dump (std::ostream &os=std::cout) const
 Dump the complete table to an output stream. More...
 
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. More...
 
std::string dumpToString () const
 Dump the complete table into a string. More...
 
std::string dumpToString (const std::string &prefix) const
 Dump the complete table into a string, with an additional prefix before each line. More...
 
template<class K >
void dumpOneEntry (const K &indices, std::ostream &os=std::cout) const
 Dump one entry with given indices to an output stream. More...
 
template<class K >
std::string dumpOneEntryToString (const K &indices) const
 Dump one entry with given indices into a string. More...
 

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 = MultiDimArray<T,N>::defaultSubType()
 

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 24 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
166  ++s_objectCount;
167  MsgStream log(Athena::getMessageSvc(),"MultiDimArray<T,N>");
168  log<<MSG::DEBUG<<"Creating MultiDimArray<" << N << ">" << " at " << this << " #objects: " << s_objectCount<<endmsg;
169 #endif
170 }

◆ ~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
175  --s_objectCount;
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
187  ++s_objectCount;
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 }

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 }

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

◆ 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  {
430  std::ostringstream oss;
431  dumpOneEntry( indices, oss );
432  return oss.str();
433 }

◆ dumpToString() [1/2]

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

Dump the complete table into a string.

Definition at line 392 of file MultiDimArray.h.

392  {
393  std::ostringstream oss;
394  dump( oss );
395  return oss.str();
396 }

◆ 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  {
400  std::ostringstream oss;
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 }

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

◆ maxIndex()

template<class T , unsigned int N>
int MultiDimArray< T, N >::maxIndex
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
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
246  m_minIndex = rhs.m_minIndex;
247 
248  return *this;
249 }

◆ 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 ) {
266  m_minIndex = index;
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;
278  SubType* newData = new SubType[m_size];
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;
292  SubType* newData = new SubType[m_size];
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;
299  m_minIndex = index;
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 }

◆ size()

template<class T , unsigned int N>
unsigned int MultiDimArray< T, N >::size
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
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
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>
MultiDimArray< T, N >::SubType MultiDimArray< T, N >::s_invalidSubType = MultiDimArray<T,N>::defaultSubType()
staticprivate

Definition at line 130 of file MultiDimArray.h.


The documentation for this class was generated from the following file:
MultiDimArray::minIndex
int minIndex() const
Definition: MultiDimArray.h:203
MultiDimArray::m_minIndex
int m_minIndex
Definition: MultiDimArray.h:128
index
Definition: index.py:1
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
MultiDimArray::isInRange
bool isInRange(int index) const
Check that an index is in the range of the this field.
Definition: MultiDimArray.h:223
MultiDimArray::m_data
SubType * m_data
Definition: MultiDimArray.h:127
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
MultiDimArray::m_size
unsigned int m_size
Definition: MultiDimArray.h:129
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MultiDimArray::maxIndex
int maxIndex() const
Definition: MultiDimArray.h:208
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
MultiDimArray::dumpOneEntry
void dumpOneEntry(const K &indices, std::ostream &os=std::cout) const
Dump one entry with given indices to an output stream.
Definition: MultiDimArray.h:423
MultiDimArray::dump
void dump(std::ostream &os=std::cout) const
Dump the complete table to an output stream.
Definition: MultiDimArray.h:380
DeMoScan.index
string index
Definition: DeMoScan.py:362
MultiDimArray::s_invalidSubType
static SubType s_invalidSubType
Definition: MultiDimArray.h:130
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MultiDimArray::operator=
MultiDimArray & operator=(const MultiDimArray &)
Definition: MultiDimArray.h:228
MultiDimArray::SubType
MultiDimArrayTypes< T, N >::SubType SubType
Definition: MultiDimArray.h:79
MultiDimArrayTypes::defaultThisType
static ThisType defaultThisType()
Definition: MultiDimArray.h:137