60#ifndef TRTConditionsData_NestedContainer_h
61#define TRTConditionsData_NestedContainer_h
69#include "GaudiKernel/MsgStream.h"
78 template <
class Daughter,
class T,
class Trait>
84 static const T&
get(
const Daughter& d,
const ExpandedIdentifier&
id ,
size_t& resolvelevel) {
return d.get(
id,resolvelevel) ; }
86 static const T&
get(
const Daughter& d) {
return d.get() ; }
90 static bool empty(Daughter& d) {
return d.daughters().empty() ; }
94 static void clear(Daughter& d) { d.clear() ; } ;
96 static void print(
const Daughter& d) { d.print() ; }
98 static void getall(
const Daughter& d, std::vector< std::pair<ExpandedIdentifier, const T*> >&
entries) {
103 static void copy(Daughter& out,
const Daughter& in) { out = in ; }
105 static size_t footprint(
const Daughter& d) {
return d.footprint() ; }
107 static void crunch(Daughter& d) {
return d.crunch() ; }
109 static bool isequal(
const Daughter& lhs,
const Daughter& rhs) {
return lhs==rhs ; }
111 static size_t numObjects(
const Daughter& d) {
return d.numObjects() ; }
118 template <
class T,
class Trait>
123 static const T&
get(
const T& d) {
return d ; }
125 static bool empty(T&) {
return true ; }
127 static void clear(T& d) { Trait::erase(d) ; }
128 static void print(
const T& d) { Trait::print(d) ; }
129 static void getall(
const T& d, std::vector< std::pair<ExpandedIdentifier, const T*> >&
entries) {
130 if(Trait::isvalid(d) ) {
132 entries.push_back(std::pair<ExpandedIdentifier, const T*>(
id,&d)) ;
136 static void copy(T& out,
const T& in) { Trait::copy(out,in) ; }
137 static size_t footprint(
const T& d) {
return Trait::footprint(d) ; }
139 static bool isequal(
const T& lhs,
const T& rhs) {
return Trait::isequal(lhs,rhs) ; }
140 static size_t numObjects(
const T& d) {
return Trait::isvalid(d) ? 1 : 0 ; }
149 template <
int NestingLevel,
class Daughter,
class T,
class Trait>
192 if( NestingLevel ==
id.level() ) {
196 unsigned int thisindex =
id.index(NestingLevel+1) ;
206 if( NestingLevel <
id.level() ) {
207 unsigned int thisindex =
id.index(NestingLevel+1) ;
211 if( Trait::isvalid(
rc) )
return rc ;
219 if( NestingLevel <
id.level() ) {
220 unsigned int thisindex =
id.index(NestingLevel+1) ;
223 if( Trait::isvalid(
rc) )
return rc ;
226 resolvelevel = NestingLevel ;
247 if( NestingLevel ==
id.level() )
clear() ;
249 unsigned int thisindex =
id.index(NestingLevel+1) ;
264 for(
typename DaughterContainer::const_iterator it =
m_daughters.begin() ; it !=
m_daughters.end(); ++it )
284 for(
typename DaughterContainer::const_iterator it =
m_daughters.begin() ; it !=
m_daughters.end(); ++it )
299 size_t firstvaliddaughter(0);
300 bool allequal(
true) ;
301 for(
size_t idau=0; idau<
m_daughters.size() && allequal; ++idau) {
306 if( firstvaliddaughter==0 ) firstvaliddaughter = idau ;
314 T defaultvalue(Trait::initialvalue()) ;
331 for(
int i=0; i<NestingLevel; ++i)
337 std::cout <<
"level = " <<
id.name(NestingLevel) <<
" (" << NestingLevel <<
")" << std::endl ;
338 for(
unsigned int i=0; i<
m_daughters.size(); ++i) {
340 std::cout <<
"daughter " << i << std::endl ;
346 typedef std::vector< std::pair<ExpandedIdentifier, const T*> >
FlatContainer ;
349 for(
unsigned int idau = 0; idau<
m_daughters.size(); ++idau) {
354 for(
unsigned int j=0; j< dauentries.size(); ++j )
355 dauentries[j].first.index(NestingLevel+1) = idau ;
357 entries.insert(
entries.end(),dauentries.begin(),dauentries.end()) ;
362 entries.push_back( std::pair<ExpandedIdentifier, const T*>(
id,&
m_default)) ;
370 template <
int NestingLevel,
class T,
class Trait>
372 :
public NestedContainerBase<NestingLevel, NestedContainer<NestingLevel+1,T,Trait>, T, Trait>
378 template <
class T,
class Trait>
Identifier for TRT detector elements in the conditions code.
void clear()
clear entire container
bool operator==(const NestedContainerBase &rhs) const
equality operator, used for compressing
void crunch()
reduce the footprint as much as possible by removing the extra space allocated by the vectors
std::vector< std::pair< ExpandedIdentifier, const T * > > FlatContainer
fill vector with all entries in the container. needed to dump to Peter's flat file format
T m_default
Type of atomic element.
~NestedContainerBase()=default
destructor
bool operator==(const T &rhs) const
another equality operator, used for compressing
void set(const T &t)
set the default value
void clear(const ExpandedIdentifier &id)
clear only entries specified
Trait trait_type
Type of trait.
DaughterContainer m_daughters
Container of Daughters.
const T & get() const
get the default value
T value_type
Type of atomic element.
size_t numObjects() const
return the total number of valid calibration objects
NestedContainerBase()
constructor
const T const_value_type
const Type of atomic element.
const DaughterContainer & daughters() const
return the vector of daughters
const T & get(const ExpandedIdentifier &id, size_t &resolvelevel) const
std::vector< Daughter > DaughterContainer
typedef of container
const T & get(const ExpandedIdentifier &id) const
get a value.
void getall(FlatContainer &entries) const
size_t footprint() const
return the memory allocated by the container and its daughters
void printindent() const
some IO for debugging
void set(const ExpandedIdentifier &id, const T &t)
set a value.
Default trait class if T is an owned pointer.
static pointer initialvalue()
static void print(const_pointer x)
static void initialize(pointer &x)
static void erase(pointer &x)
static bool isvalid(const_pointer x)
static bool isequal(const_pointer lhs, const_pointer rhs)
static void copy(pointer &out, const_pointer in)
std::remove_pointer_t< pointer > base_type
static size_t footprint(const_pointer x)
const base_type * const_pointer
Nested container class, ie a base class at level l with daugthers at level l+1.
singleton-like access to IMessageSvc via open function and helper
static size_t numObjects(const T &d)
static void getall(const T &d, std::vector< std::pair< ExpandedIdentifier, const T * > > &entries)
static const T & get(const T &d, const ExpandedIdentifier &)
static size_t footprint(const T &d)
static const T & get(const T &d)
static void set(T &d, const ExpandedIdentifier &, const T &t)
static void copy(T &out, const T &in)
static const T & get(const T &d, const ExpandedIdentifier &, size_t &)
static void clear(T &d, const ExpandedIdentifier &)
static bool isequal(const T &lhs, const T &rhs)
static void print(const T &d)
static void print(const Daughter &d)
print daugther info
static bool empty(Daughter &d)
empty daughter container
static void copy(Daughter &out, const Daughter &in)
copy daugthers
static void clear(Daughter &d)
clear container
static const T & get(const Daughter &d, const ExpandedIdentifier &id, size_t &resolvelevel)
resolve the nesting level for a given id
static bool isequal(const Daughter &lhs, const Daughter &rhs)
equality operator
static void getall(const Daughter &d, std::vector< std::pair< ExpandedIdentifier, const T * > > &entries)
copy all object pointers into a vector of (id,pointer) pairs
static const T & get(const Daughter &d)
get default for daughter container
static void clear(Daughter &d, const ExpandedIdentifier &id)
clear container for given id
static Daughter initialvalue()
make a default daugther
static void crunch(Daughter &d)
compress daugther size
static size_t numObjects(const Daughter &d)
total number of atomic objects in daugther
static size_t footprint(const Daughter &d)
return allocated memory
static void set(Daughter &d, const ExpandedIdentifier &id, const T &t)
set value for given id
static const T & get(const Daughter &d, const ExpandedIdentifier &id)
get value for given id