ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
D3PD::CollectionGetterTool< CONT > Class Template Referenceabstract

Type-safe wrapper for ICollectionGetterTool. More...

#include <CollectionGetterTool.h>

Inheritance diagram for D3PD::CollectionGetterTool< CONT >:
Collaboration diagram for D3PD::CollectionGetterTool< CONT >:

Public Member Functions

 CollectionGetterTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard Gaudi tool constructor. More...
 
virtual const void * getUntyped (bool allowMissing=false)
 Return the target object. More...
 
virtual const std::type_info & typeinfo () const
 Return the type of the collection object retrieved by this tool. More...
 
virtual const std::type_info & elementTypeinfo () const
 Return the element type of the collection. More...
 
virtual StatusCode reset (bool allowMissing=false)
 Reset the iteration to the start of the collection. More...
 
virtual const void * nextUntyped ()
 Return a pointer to the next element in the collection. More...
 
virtual size_t sizeHint (bool allowMissing=false)
 Return an estimate of the number of elements in the iteration. More...
 
virtual const CONT * get (bool allowMissing=false)=0
 Return the collection object. More...
 
virtual void releaseObject (const CONT *p)
 Release an object retrieved from the getter. More...
 
virtual void releaseObjectUntyped (const void *p)
 Release an object retrieved from the getter. More...
 
StatusCode initialize ()
 Standard Gaudi initialize method. More...
 
const void * nextTypeinfo (const std::type_info &ti)
 Return the next object cast to a different pointer type. More...
 
StatusCode configureElementTypeinfo (const std::type_info &ti)
 Test type compatibility. More...
 
void releaseElementTypeinfo (const void *p, const std::type_info &ti)
 Release an element retrieved from the getter. More...
 

Private Attributes

CONT::const_iterator m_it
 The current iterator. More...
 
CONT::const_iterator m_end
 The iterator at the end of the container. More...
 
std::string m_label
 Property: label to assign to this getter (or null). More...
 
ToolHandle< ICollectionGetterRegistryToolm_registry
 The collection getter registry tool. More...
 
TypeConverter m_converter
 Helper to convert pointers. More...
 
TypeConverter m_backConverter
 Helper to convert pointers back, for releaseElement. More...
 

Detailed Description

template<class CONT>
class D3PD::CollectionGetterTool< CONT >

Type-safe wrapper for ICollectionGetterTool.

The template argument gives the type of the container that we're returning. This class implements the iteration over the container. If your container obeys the standard iteration protocol (for a forward_iterator), then you just need to derive from this class and implement get(), and optionally releaseObject().

Definition at line 38 of file CollectionGetterTool.h.

Constructor & Destructor Documentation

◆ CollectionGetterTool()

template<class CONT >
D3PD::CollectionGetterTool< CONT >::CollectionGetterTool ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Standard Gaudi tool constructor.

Parameters
typeThe name of the tool type.
nameThe tool name.
parentThe tool's Gaudi parent.

Member Function Documentation

◆ configureElementTypeinfo()

StatusCode D3PD::CollectionGetterToolImpl::configureElementTypeinfo ( const std::type_info &  ti)
inherited

Test type compatibility.

Parameters
tiThe desired type.

Test to see if the object being returned by the tool can be converted to a pointer to T. This can be used to perform type checks during job initialization.

Definition at line 146 of file CollectionGetterToolImpl.cxx.

148 {
149  return this->m_converter.init(this->elementTypeinfo(), ti);
150 }

◆ elementTypeinfo()

template<class CONT >
virtual const std::type_info& D3PD::CollectionGetterTool< CONT >::elementTypeinfo ( ) const
virtual

Return the element type of the collection.

I.e., nextUntyped returns a pointer to this type.

◆ get()

template<class CONT >
virtual const CONT* D3PD::CollectionGetterTool< CONT >::get ( bool  allowMissing = false)
pure virtual

◆ getUntyped()

template<class CONT >
virtual const void* D3PD::CollectionGetterTool< CONT >::getUntyped ( bool  allowMissing = false)
virtual

◆ initialize()

StatusCode D3PD::CollectionGetterToolImpl::initialize ( )
inherited

Standard Gaudi initialize method.

Definition at line 45 of file CollectionGetterToolImpl.cxx.

46 {
47  // If a label was provided, add ourselves to the registry.
48  if (!m_label.empty()) {
49  CHECK( m_registry.retrieve() );
50  CHECK( m_registry->add (m_label, this) );
51  }
52  else {
53  m_registry.disable();
54  }
56 }

◆ nextTypeinfo()

const void * D3PD::CollectionGetterToolImpl::nextTypeinfo ( const std::type_info &  ti)
inherited

Return the next object cast to a different pointer type.

Return the next element from the collection as a pointer to the ti type. Return 0 if the pointer can't be converted or at the end of the iteration.

Definition at line 68 of file CollectionGetterToolImpl.cxx.

69 {
70  // Configure the converter.
71  if (!this->m_converter.isValid() ||
72  this->m_converter.dstTypeinfo() != ti)
73  {
74  if (this->configureElementTypeinfo(ti).isFailure())
75  return 0;
76  }
77 
78  // Get the next object. If the conversion fails, loop until we get
79  // a good one.
80  while (true) {
81  const void* p = this->nextUntyped();
82  if (!p) return 0;
83  const void* pconv = this->m_converter.convertUntyped (p);
84  if (pconv) return pconv;
85  this->releaseElementUntyped (p);
86  REPORT_MESSAGE (MSG::WARNING)
87  << "Pointer conversion from " << m_converter.srcName() << " to "
88  << m_converter.dstName() << "failed.";
89  }
90 }

◆ nextUntyped()

template<class CONT >
virtual const void* D3PD::CollectionGetterTool< CONT >::nextUntyped ( )
virtual

Return a pointer to the next element in the collection.

Return 0 when the collection has been exhausted.

Reimplemented in D3PD::SGTileDigitsGetterTool, D3PD::SGTileHitGetterTool, D3PD::SGTileModuleBitsGetterTool, and D3PD::SGTileRawChannelGetterTool.

◆ releaseElementTypeinfo()

void D3PD::CollectionGetterToolImpl::releaseElementTypeinfo ( const void *  p,
const std::type_info &  ti 
)
inherited

Release an element retrieved from the getter.

Parameters
pThe element to release.
tiThe type of p.

Call this when you are done with the element returned by nextUntyped(). The default implementation is a no-op, but if the getter dynamically allocated the object which it returned, this gives it a chance to free it.

Definition at line 104 of file CollectionGetterToolImpl.cxx.

106 {
107  if (!p)
108  return;
109 
110  // Configure the converter if needed.
111  if (!this->m_backConverter.isValid() ||
112  this->m_backConverter.srcTypeinfo() != ti)
113  {
114  if (this->m_backConverter.init (ti, this->typeinfo()).isFailure()) {
115  REPORT_MESSAGE (MSG::WARNING)
116  << "Can't configure pointer conversion from "
117  << System::typeinfoName (ti) << " to "
118  << System::typeinfoName (this->typeinfo());
119  return;
120  }
121  }
122 
123  // Convert to the desired type.
124  p = this->m_backConverter.convertUntyped (p);
125 
126  // Release.
127  if (p)
128  this->releaseElementUntyped (p);
129  else {
130  REPORT_MESSAGE (MSG::WARNING)
131  << "Pointer conversion from " << m_backConverter.srcName() << " to "
132  << m_backConverter.dstName() << "failed.";
133  }
134 }

◆ releaseObject()

template<class CONT >
virtual void D3PD::CollectionGetterTool< CONT >::releaseObject ( const CONT *  p)
virtual

Release an object retrieved from the getter.

Parameters
pThe object to release.

Call this when you are done with the object returned by get(). The default implementation is a no-op, but if the getter dynamically allocated the object which it returned, this gives it a chance to free it.

◆ releaseObjectUntyped()

template<class CONT >
virtual void D3PD::CollectionGetterTool< CONT >::releaseObjectUntyped ( const void *  p)
virtual

Release an object retrieved from the getter.

Parameters
pThe object to release.

Call this when you are done with the object returned by getUntyped(). The default implementation is a no-op, but if the getter dynamically allocated the object which it returned, this gives it a chance to free it.

◆ reset()

template<class CONT >
virtual StatusCode D3PD::CollectionGetterTool< CONT >::reset ( bool  allowMissing = false)
virtual

Reset the iteration to the start of the collection.

Parameters
allowMissingIf true, then we should not generate errors if the requested object is missing.

Return failure if the container cannot be retrieved.

Reimplemented in D3PD::SGTileDigitsGetterTool, D3PD::SGTileHitGetterTool, D3PD::SGTileModuleBitsGetterTool, and D3PD::SGTileRawChannelGetterTool.

◆ sizeHint()

template<class CONT >
virtual size_t D3PD::CollectionGetterTool< CONT >::sizeHint ( bool  allowMissing = false)
virtual

Return an estimate of the number of elements in the iteration.

Parameters
allowMissingIf true, then we should not generate errors if the requested object is missing.

This can be used to pre-allocate memory. (It's possible that this isn't known in advance of iterating over the entire collection, for example if a selection is being applied, so this is only a hint.)

Reimplemented in D3PD::SGTileDigitsGetterTool, D3PD::SGTileHitGetterTool, D3PD::SGTileModuleBitsGetterTool, and D3PD::SGTileRawChannelGetterTool.

◆ typeinfo()

template<class CONT >
virtual const std::type_info& D3PD::CollectionGetterTool< CONT >::typeinfo ( ) const
virtual

Member Data Documentation

◆ m_backConverter

TypeConverter D3PD::CollectionGetterToolImpl::m_backConverter
privateinherited

Helper to convert pointers back, for releaseElement.

Definition at line 106 of file CollectionGetterToolImpl.h.

◆ m_converter

TypeConverter D3PD::CollectionGetterToolImpl::m_converter
privateinherited

Helper to convert pointers.

Definition at line 103 of file CollectionGetterToolImpl.h.

◆ m_end

template<class CONT >
CONT::const_iterator D3PD::CollectionGetterTool< CONT >::m_end
private

The iterator at the end of the container.

Definition at line 148 of file CollectionGetterTool.h.

◆ m_it

template<class CONT >
CONT::const_iterator D3PD::CollectionGetterTool< CONT >::m_it
private

The current iterator.

Definition at line 145 of file CollectionGetterTool.h.

◆ m_label

std::string D3PD::CollectionGetterToolImpl::m_label
privateinherited

Property: label to assign to this getter (or null).

Definition at line 97 of file CollectionGetterToolImpl.h.

◆ m_registry

ToolHandle<ICollectionGetterRegistryTool> D3PD::CollectionGetterToolImpl::m_registry
privateinherited

The collection getter registry tool.

Definition at line 100 of file CollectionGetterToolImpl.h.


The documentation for this class was generated from the following file:
D3PD::TypeConverter::dstName
std::string dstName() const
Return the name of the destination type, or an empty string.
Definition: TypeConverter.cxx:151
initialize
void initialize()
Definition: run_EoverP.cxx:894
D3PD::CollectionGetterToolImpl::m_converter
TypeConverter m_converter
Helper to convert pointers.
Definition: CollectionGetterToolImpl.h:103
D3PD::TypeConverter::init
StatusCode init(const std::type_info &src_ti, const std::type_info &dst_ti)
Initialize the converter.
Definition: TypeConverter.cxx:51
D3PD::CollectionGetterToolImpl::m_registry
ToolHandle< ICollectionGetterRegistryTool > m_registry
The collection getter registry tool.
Definition: CollectionGetterToolImpl.h:100
D3PD::TypeConverter::srcName
std::string srcName() const
Return the name of the source type, or an empty string.
Definition: TypeConverter.cxx:141
D3PD::TypeConverter::convertUntyped
const void * convertUntyped(const void *p) const
Convert pointer.
Definition: TypeConverter.cxx:116
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
D3PD::CollectionGetterToolImpl::m_backConverter
TypeConverter m_backConverter
Helper to convert pointers back, for releaseElement.
Definition: CollectionGetterToolImpl.h:106
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
D3PD::TypeConverter::isValid
bool isValid() const
Test to see if this converter has been properly initialized.
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
D3PD::CollectionGetterToolImpl::configureElementTypeinfo
StatusCode configureElementTypeinfo(const std::type_info &ti)
Test type compatibility.
Definition: CollectionGetterToolImpl.cxx:147
D3PD::CollectionGetterToolImpl::m_label
std::string m_label
Property: label to assign to this getter (or null).
Definition: CollectionGetterToolImpl.h:97