ATLAS Offline Software
Loading...
Searching...
No Matches
D3PD::CollectionGetterToolImpl Class Reference

Non-template parts of CollectionGetterTool. More...

#include <CollectionGetterToolImpl.h>

Inherits extends< ObjGetterToolImpl, ICollectionGetterTool >.

Inherited by D3PD::CollectionGetterTool< CaloCalibrationHitContainer >, D3PD::CollectionGetterTool< INav4MomLinkContainer >, D3PD::CollectionGetterTool< LArHitContainer >, D3PD::CollectionGetterTool< LArRawChannelContainer >, D3PD::CollectionGetterTool< TrackRecordCollection >, D3PD::CollectionGetterTool< Obj4Container >, D3PD::CollectionGetterFilterToolImpl, D3PD::CollectionGetterTool< CONT >, and D3PD::SGDataVectorGetterTool.

Collaboration diagram for D3PD::CollectionGetterToolImpl:

Public Member Functions

 CollectionGetterToolImpl (const std::string &type, const std::string &name, const IInterface *parent)
 Standard Gaudi tool constructor.
StatusCode initialize ()
 Standard Gaudi initialize method.
const void * nextTypeinfo (const std::type_info &ti)
 Return the next object cast to a different pointer type.
StatusCode configureElementTypeinfo (const std::type_info &ti)
 Test type compatibility.
void releaseElementTypeinfo (const void *p, const std::type_info &ti)
 Release an element retrieved from the getter.

Private Attributes

std::string m_label
 Property: label to assign to this getter (or null).
ToolHandle< ICollectionGetterRegistryToolm_registry
 The collection getter registry tool.
TypeConverter m_converter
 Helper to convert pointers.
TypeConverter m_backConverter
 Helper to convert pointers back, for releaseElement.

Detailed Description

Non-template parts of CollectionGetterTool.

CollectionGetterTool extends ObjGetterTool to allow iterating over the objects within a container. CollectionGetterTool is templated on the collection type. This class factors out the pieces that don't depend on the template argument.

Definition at line 40 of file CollectionGetterToolImpl.h.

Constructor & Destructor Documentation

◆ CollectionGetterToolImpl()

D3PD::CollectionGetterToolImpl::CollectionGetterToolImpl ( 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.

Definition at line 28 of file CollectionGetterToolImpl.cxx.

31 : base_class (type, name, parent)
32{
33 declareProperty ("Label", m_label,
34 "Label to assign to this getter, to be able to reference "
35 "it from an association tool. Leave blank if no label "
36 "is needed.");
37 declareProperty ("CollectionGetterRegistry", m_registry,
38 "Collection getter registry tool");
39}
std::string m_label
Property: label to assign to this getter (or null).
ToolHandle< ICollectionGetterRegistryTool > m_registry
The collection getter registry tool.

Member Function Documentation

◆ configureElementTypeinfo()

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

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}
TypeConverter m_converter
Helper to convert pointers.

◆ initialize()

StatusCode D3PD::CollectionGetterToolImpl::initialize ( )

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 }
55 return ObjGetterToolImpl::initialize();
56}
#define CHECK(...)
Evaluate an expression and check for errors.

◆ nextTypeinfo()

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

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}
#define REPORT_MESSAGE(LVL)
Report a message.
StatusCode configureElementTypeinfo(const std::type_info &ti)
Test type compatibility.

◆ releaseElementTypeinfo()

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

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}
TypeConverter m_backConverter
Helper to convert pointers back, for releaseElement.

Member Data Documentation

◆ m_backConverter

TypeConverter D3PD::CollectionGetterToolImpl::m_backConverter
private

Helper to convert pointers back, for releaseElement.

Definition at line 106 of file CollectionGetterToolImpl.h.

◆ m_converter

TypeConverter D3PD::CollectionGetterToolImpl::m_converter
private

Helper to convert pointers.

Definition at line 103 of file CollectionGetterToolImpl.h.

◆ m_label

std::string D3PD::CollectionGetterToolImpl::m_label
private

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
private

The collection getter registry tool.

Definition at line 100 of file CollectionGetterToolImpl.h.


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