5#ifndef MUONCALIBIDENTIFIER_MULTIDIMARRAY_H
6#define MUONCALIBIDENTIFIER_MULTIDIMARRAY_H
29template <
class T,
unsigned int I>
72template <
class T,
unsigned int N>
113 void dump( std::ostream& os = std::cout )
const;
115 void dump(
const std::string& prefix, std::ostream& os = std::cout )
const;
122 void dumpOneEntry(
const K& indices, std::ostream& os = std::cout )
const;
131#ifdef MULTIDIMARRAY_DEBUG
132 static unsigned int s_objectCount;
136template <
class T,
unsigned int I>
146template <
class T,
unsigned int N>
151template <
class T,
unsigned int N>
156template <
class T,
unsigned int N>
161template <
class T,
unsigned int N>
165#ifdef MULTIDIMARRAY_DEBUG
168 log<<MSG::DEBUG<<
"Creating MultiDimArray<" << N <<
">" <<
" at " <<
this <<
" #objects: " << s_objectCount<<
endmsg;
172template <
class T,
unsigned int N>
174#ifdef MULTIDIMARRAY_DEBUG
177 log<<MSG::DEBUG<<
"Deleting MultiDimArray<" << N <<
">" <<
" at " <<
this <<
" #objects: " << s_objectCount<<
endmsg;
182template <
class T,
unsigned int N>
186#ifdef MULTIDIMARRAY_DEBUG
189 log<<MSG::DEBUG<<
"Copying MultiDimArray<" << N <<
">" <<
" at " <<
this <<
" #objects: " << s_objectCount<<
endmsg;
194template <
class T,
unsigned int N>
202template <
class T,
unsigned int N>
207template <
class T,
unsigned int N>
212template <
class T,
unsigned int N>
217template <
class T,
unsigned int N>
222template <
class T,
unsigned int N>
227template <
class T,
unsigned int N>
229#ifdef MULTIDIMARRAY_DEBUG
231 log<<MSG::DEBUG<<
"Assigning MultiDimArray<" << N <<
">" <<
" to " <<
this <<
" from " << &rhs<<
endmsg;
251template <
class T,
unsigned int N>
255 log<<MSG::WARNING<<
"MultiDimArray<" << N <<
">::operator["<<
index <<
"]" <<
" index out of range (" <<
minIndex() <<
"," <<
maxIndex() <<
")"<<
endmsg;
261template <
class T,
unsigned int N>
263#ifdef MULTIDIMARRAY_DEBUG
265#endif if ( !m_data ) {
270#ifdef MULTIDIMARRAY_DEBUG
271 log<<MSG::DEBUG<<
"MultiDimArray<" << N <<
">::operator["<<
index <<
"]" <<
" at " <<
this <<
":" <<
" new data array. size=" <<
m_size <<
" range=(" <<
minIndex() <<
"," <<
maxIndex() <<
")"<<
endmsg;
273 }
else if (
index > maxIndex() ) {
275 unsigned int oldSize = m_size;
276 int nAdd =
index - maxIndex();
281 for ( ; i < oldSize; ++i ) newData[i] = m_data[i];
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;
288 }
else if (
index < minIndex() ) {
290 unsigned int nAdd = minIndex() -
index;
296 for ( ;
i < m_size; ++
i ) newData[i] = m_data[i-nAdd];
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;
305 return m_data[
index - m_minIndex];
309template <
class T,
unsigned int N>
311 unsigned int nTotal = 0;
314 for (
int idx = idxMin; idx <= idxMax; ++idx ) {
320template <
class T,
unsigned int N>
322 unsigned int nTotal = 0;
325 for (
int idx = idxMin; idx <= idxMax; ++idx ) {
338 unsigned int cnt = 0;
341 for (
int idx = idxMin; idx <= idxMax; ++idx ) {
347template <
class T,
unsigned int N>
349 return ::totalSize( *
this );
352template <
class T,
unsigned int N>
354 return ::validSize( *
this );
357template <
class T,
unsigned int N>
359 const std::string& prefix =
"(" ) {
362 for (
int idx = idxMin; idx <= idxMax; ++idx ) {
363 std::ostringstream oss;
365 dump( idh[idx], os, prefix + oss.str() );
371 const std::string& prefix =
"(" ) {
374 for (
int idx = idxMin; idx <= idxMax; ++idx ) {
375 os << prefix << idx <<
"): hash=" << idh[idx] <<
"\n";
379template <
class T,
unsigned int N>
385template <
class T,
unsigned int N>
387 ::dump( *
this, os, prefix +
"(" );
391template <
class T,
unsigned int N>
393 std::ostringstream oss;
398template <
class T,
unsigned int N>
400 std::ostringstream oss;
405template <
class T,
unsigned int N,
class K>
407 std::ostream& os = std::cout,
const std::string& prefix =
"(" ) {
408 int idx = indices[N-1];
409 std::ostringstream oss;
411 dumpOneEntry( idh[idx], indices, os, prefix + oss.str() );
414template<
class T,
class K>
416 std::ostream& os = std::cout,
const std::string& prefix =
"(" ) {
417 int idx = indices[0];
418 os << prefix << idx <<
")=" << idh[idx];
421template <
class T,
unsigned int N>
427template <
class T,
unsigned int N>
430 std::ostringstream oss;
436template <
class T,
unsigned int N>
445template <
class T,
unsigned int N>
448#ifdef MULTIDIMARRAY_DEBUG
449template <
class T,
unsigned int N>
std::ostream & operator<<(std::ostream &os, const MultiDimArray< T, N > &idh)
static unsigned int validSize(const MultiDimArray< T, N > &ht)
MultiDimArray< T, N >::SubType MultiDimArray< T, N >::s_invalidSubType
static unsigned int totalSize(const MultiDimArray< T, N > &ht)
void dumpOneEntry(const MultiDimArray< T, N > &idh, const K &indices, std::ostream &os=std::cout, const std::string &prefix="(")
T::ValueType ThisType
define ThisType as T::ValueType
static ThisType defaultThisType()
MultiDimArrayTypes< T, 0 >::ThisType SubType
define the SubType as MultiDimArrayTypes<T,0>::ThisType
MultiDimArray< T, 1 > ThisType
define ThisType as a MultiDimArray<T,N> with N=1
General recursive subtyping trait.
MultiDimArray< T, I > ThisType
define ThisType as a MultiDimArray<T,I>
MultiDimArray< T, I-1 > SubType
define the SubType as MultiDimArrayTypes<T,I-1>
static ThisType defaultThisType()
Multi-dimensional array with a compile-time number of dimensions, and a run-time complete freedom ove...
static ValueType defaultValueType()
static const SubType & invalidSubType()
unsigned int totalSize() const
The total number of elements, including invalid (=default) holes, from this field downwards.
MultiDimArray(const MultiDimArray &)
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.
SubType & operator[](int index)
bool isInRange(int index) const
Check that an index is in the range of the this field.
unsigned int size() const
Size of this field.
void dump(std::ostream &os=std::cout) const
Dump the complete table to an output stream.
MultiDimArray & operator=(const MultiDimArray &)
static SubType s_invalidSubType
std::string dumpToString() const
Dump the complete table into a string.
void dumpOneEntry(const K &indices, std::ostream &os=std::cout) const
Dump one entry with given indices to an output stream.
const SubType & operator[](int index) const
MultiDimArray< T, N > ThisType
static SubType defaultSubType()
std::string dumpToString(const std::string &prefix) const
Dump the complete table into a string, with an additional prefix before each line.
MultiDimArrayTypes< T, N >::SubType SubType
unsigned int validSize() const
The total number of valid (=non-default) elements from this field downwards.
unsigned int depth() const
Depth of this field, i.e.
std::string dumpOneEntryToString(const K &indices) const
Dump one entry with given indices into a string.
IMessageSvc * getMessageSvc(bool quiet=false)