ATLAS Offline Software
Loading...
Searching...
No Matches
D3PD::SGObjGetterTool Class Referenceabstract

Getter tool to retrieve single objects from StoreGate. More...

#include <SGObjGetterTool.h>

Inheritance diagram for D3PD::SGObjGetterTool:
Collaboration diagram for D3PD::SGObjGetterTool:

Public Member Functions

 SGObjGetterTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard Gaudi tool constructor.
virtual StatusCode initialize ()
 Standard Gaudi initialize method.
virtual const std::type_info & typeinfo () const
 Return the type of object retrieved by this tool.
CLID clid () const
 Return the class ID being read by this tool.
virtual const void * getUntyped (bool allowMissing=false)
 Return the target object.
virtual const void * getTypeinfo (const std::type_info &ti, bool allowMissing=false)
 Return the target object cast to a different pointer type.
virtual StatusCode configureTypeinfo (const std::type_info &ti)
 Test type compatibility.
void releaseObjectTypeinfo (const void *p, const std::type_info &ti)
 Release an object retrieved from the getter.
 DeclareInterfaceID (IObjGetterTool, 1, 0)
 Gaudi interface definition.
template<class T>
const T * get (bool allowMissing=false)
 Type-safe wrapper for get.
virtual void releaseObjectUntyped (const void *p)
 Release an object retrieved from the getter.
template<class T>
void releaseObject (const T *p)
 Type-safe wrapper for releaseObjectUntyped.
template<class T>
StatusCode configureD3PD ()
 Test type compatibility.
virtual const void * getTypeinfo (const std::type_info &ti, bool allowMissing=false)=0
 Return the target object cast to a different pointer type.
void releaseObjectTypeinfo (const void *p, const std::type_info &ti)
 Release an object retrieved from the getter.
virtual StatusCode configureTypeinfo (const std::type_info &ti)=0
 Test type compatibility.

Protected Member Functions

StatusCode initializeImpl ()
 Initialize this mixin class.

Protected Attributes

std::string m_typename
 Property: Name of the type of the object being retrieved.
std::string m_sgkey
 Property: StoreGate key of the object being retrieved.
ServiceHandle< IClassIDSvc > m_clidsvc
 Property: Instance of the ClassIDSvc to use.
SGKeyResolver m_resolver
 Helper: Resolve the SG key to use.

Private Attributes

CLID m_clid
 CLID for the object being retrieved.
ServiceHandle< StoreGateSvc > & m_sg
 The event storage service.
TypeConverter m_converter
 Helper to convert pointers.
TypeConverter m_backConverter
 Helper to convert pointers back, for releaseObject.

Detailed Description

Getter tool to retrieve single objects from StoreGate.

This is a Getter tool that retrieves a single object from StoreGate, given the type name and SG key. This class should be able to handle any type that can be put into StoreGate.

Properties: TypeName - Name of the type of the object being retrieved. SGKey - StoreGate key of the object being retrieved. Can also be a comma or space-separated list. In that case, the first key that actually exists in the data store will be used. ClassIDSvc - ClassIDSvc instance to use.

Definition at line 46 of file SGObjGetterTool.h.

Constructor & Destructor Documentation

◆ SGObjGetterTool()

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

31 : SGGetterImpl (name, evtStore()),
32 ObjGetterToolImpl (type, name, parent)
33{
35}
#define SGGETTERIMPL_PROPS
Use this macro in the constructor of the derived AlgTool class.
ObjGetterToolImpl(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
SGGetterImpl(const std::string &name, ServiceHandle< StoreGateSvc > &sg)
Constructor.

Member Function Documentation

◆ clid()

CLID D3PD::SGGetterImpl::clid ( ) const
inherited

Return the class ID being read by this tool.

Definition at line 54 of file SGGetterImpl.cxx.

55{
56 return m_clid;
57}
CLID m_clid
CLID for the object being retrieved.

◆ configureD3PD()

template<class T>
StatusCode D3PD::IObjGetterTool::configureD3PD ( )
inherited

Test type compatibility.

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.

This is implemented in terms of configureTypeinfo.

◆ configureTypeinfo() [1/2]

virtual StatusCode D3PD::IObjGetterTool::configureTypeinfo ( const std::type_info & ti)
pure virtualinherited

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.

◆ configureTypeinfo() [2/2]

StatusCode D3PD::ObjGetterToolImpl::configureTypeinfo ( const std::type_info & ti)
virtualinherited

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 124 of file ObjGetterToolImpl.cxx.

125{
126 return this->m_converter.init(this->typeinfo(), ti);
127}
TypeConverter m_converter
Helper to convert pointers.

◆ DeclareInterfaceID()

D3PD::IObjGetterTool::DeclareInterfaceID ( IObjGetterTool ,
1 ,
0  )
inherited

Gaudi interface definition.

◆ get()

template<class T>
const T * D3PD::IObjGetterTool::get ( bool allowMissing = false)
inherited

Type-safe wrapper for get.

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

Return the object as a pointer to T. Return 0 if the get fails or if the pointer can't be converted.

This is implemented in terms of getTypeinfo().

◆ getTypeinfo() [1/2]

virtual const void * D3PD::IObjGetterTool::getTypeinfo ( const std::type_info & ti,
bool allowMissing = false )
pure virtualinherited

Return the target object cast to a different pointer type.

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

Return the object as a pointer to the ti type. Return 0 if the get fails or if the pointer can't be converted.

◆ getTypeinfo() [2/2]

const void * D3PD::ObjGetterToolImpl::getTypeinfo ( const std::type_info & ti,
bool allowMissing = false )
virtualinherited

Return the target object cast to a different pointer type.

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

Return the object as a pointer to the ti type. Return 0 if the get fails or if the pointer can't be converted.

Definition at line 45 of file ObjGetterToolImpl.cxx.

47{
48 // Configure the converter if needed.
49 if (!this->m_converter.isValid() ||
50 this->m_converter.dstTypeinfo() != ti)
51 {
52 if (this->configureTypeinfo(ti).isFailure())
53 return 0;
54 }
55
56 // Get the object.
57 const void* p = this->getUntyped (allowMissing);
58
59 // Convert to the desired type.
60 if (p) {
61 p = this->m_converter.convertUntyped (p);
62 if (!p) {
63 REPORT_MESSAGE (MSG::WARNING)
64 << "Pointer conversion from " << m_converter.srcName() << " to "
65 << m_converter.dstName() << "failed.";
66 }
67 }
68 return p;
69}
#define REPORT_MESSAGE(LVL)
Report a message.
virtual StatusCode configureTypeinfo(const std::type_info &ti)
Test type compatibility.

◆ getUntyped()

const void * D3PD::SGGetterImpl::getUntyped ( bool allowMissing = false)
virtualinherited

Return the target object.

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

Should be of the type given by typeinfo. Return 0 on failure.

Implements D3PD::IObjGetterTool.

Reimplemented in D3PD::SGCollectionGetterTool< CONT >, D3PD::SGCollectionGetterTool< CaloCalibrationHitContainer >, D3PD::SGCollectionGetterTool< INav4MomLinkContainer >, D3PD::SGCollectionGetterTool< IParticleLinks >, D3PD::SGCollectionGetterTool< LArHitContainer >, D3PD::SGCollectionGetterTool< LArRawChannelContainer >, D3PD::SGCollectionGetterTool< Obj4Container >, D3PD::SGCollectionGetterTool< TileDigitsContainer >, D3PD::SGCollectionGetterTool< TileHitVector >, D3PD::SGCollectionGetterTool< TileRawChannelContainer >, and D3PD::SGCollectionGetterTool< TrackRecordCollection >.

Definition at line 68 of file SGGetterImpl.cxx.

69{
70 std::string key = m_resolver.key();
71 SG::DataProxy* proxy = m_sg->proxy (m_clid, key);
72 if (!proxy) {
73 if (!allowMissing) {
74 REPORT_MESSAGE (MSG::FATAL) << "Can't find object in event store for "
75 << m_typename << "(" << m_clid << ")/"
76 << key;
77 REPORT_MESSAGE (MSG::INFO) << m_sg->dump();
78 }
79 return 0;
80 }
81
82 void* ptr = SG::DataProxy_cast (proxy, m_clid);
83 if (!ptr) {
84 if (!allowMissing) {
85 REPORT_MESSAGE (MSG::FATAL)
86 << "Null object retrieved for " << m_typename << "(" << m_clid << ")/"
87 << key;
88 REPORT_MESSAGE (MSG::INFO) << m_sg->dump();
89 }
90 return 0;
91 }
92
93 // Try to retrieve a corresponding aux store as well.
94 m_sg->tryConstRetrieve<SG::IConstAuxStore> (key + "Aux.");
95
96 return ptr;
97}
std::string m_typename
Property: Name of the type of the object being retrieved.
SGKeyResolver m_resolver
Helper: Resolve the SG key to use.
ServiceHandle< StoreGateSvc > & m_sg
The event storage service.
DATA * DataProxy_cast(DataProxy *proxy)
cast the proxy into the concrete data object it proxies
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ initialize()

StatusCode D3PD::SGObjGetterTool::initialize ( )
virtual

Standard Gaudi initialize method.

Definition at line 41 of file SGObjGetterTool.cxx.

42{
44 return AthAlgTool::initialize();
45}
#define CHECK(...)
Evaluate an expression and check for errors.
StatusCode initializeImpl()
Initialize this mixin class.

◆ initializeImpl()

StatusCode D3PD::SGGetterImpl::initializeImpl ( )
protectedinherited

Initialize this mixin class.

Call this from initialize.

Definition at line 105 of file SGGetterImpl.cxx.

106{
107 CHECK( m_clidsvc.retrieve() );
108
110
111 CHECK( m_resolver.initialize (m_clid, m_typename) );
112
113 return StatusCode::SUCCESS;
114}
ServiceHandle< IClassIDSvc > m_clidsvc
Property: Instance of the ClassIDSvc to use.
StatusCode nameToCLID(const std::string &name, CLID &clid, const std::string &context, ServiceHandle< IClassIDSvc > clidsvc=ServiceHandle< IClassIDSvc >("ClassIDSvc", "TypeNameConversions"))
Convert from a class name to a CLID.

◆ releaseObject()

template<class T>
void D3PD::IObjGetterTool::releaseObject ( const T * p)
inherited

Type-safe wrapper for releaseObjectUntyped.

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.

This is implemented in terms of releaseObjectTypeinfo().

◆ releaseObjectTypeinfo() [1/2]

void D3PD::IObjGetterTool::releaseObjectTypeinfo ( const void * p,
const std::type_info & ti )
inherited

Release an object retrieved from the getter.

Parameters
pThe object to release.
tiThe type of p.

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.

◆ releaseObjectTypeinfo() [2/2]

void D3PD::ObjGetterToolImpl::releaseObjectTypeinfo ( const void * p,
const std::type_info & ti )
inherited

Release an object retrieved from the getter.

Parameters
pThe object to release.
tiThe type of p.

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.

Definition at line 82 of file ObjGetterToolImpl.cxx.

84{
85 if (!p)
86 return;
87
88 // Configure the converter if needed.
89 if (!this->m_backConverter.isValid() ||
90 this->m_backConverter.srcTypeinfo() != ti)
91 {
92 if (this->m_backConverter.init (ti, this->typeinfo()).isFailure()) {
93 REPORT_MESSAGE (MSG::WARNING)
94 << "Can't configure pointer conversion from "
95 << System::typeinfoName (ti) << " to "
96 << System::typeinfoName (this->typeinfo());
97 return;
98 }
99 }
100
101 // Convert to the desired type.
102 p = this->m_backConverter.convertUntyped (p);
103
104 // Release.
105 if (p)
106 this->releaseObjectUntyped (p);
107 else {
108 REPORT_MESSAGE (MSG::WARNING)
109 << "Pointer conversion from " << m_backConverter.srcName() << " to "
110 << m_backConverter.dstName() << "failed.";
111 }
112}
TypeConverter m_backConverter
Helper to convert pointers back, for releaseObject.

◆ releaseObjectUntyped()

virtual void D3PD::IObjGetterTool::releaseObjectUntyped ( const void * p)
virtualinherited

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.

◆ typeinfo()

const std::type_info & D3PD::SGGetterImpl::typeinfo ( ) const
virtualinherited

Return the type of object retrieved by this tool.

Implements D3PD::IObjGetterTool.

Reimplemented in D3PD::SGCollectionGetterTool< CONT >, D3PD::SGCollectionGetterTool< CaloCalibrationHitContainer >, D3PD::SGCollectionGetterTool< INav4MomLinkContainer >, D3PD::SGCollectionGetterTool< IParticleLinks >, D3PD::SGCollectionGetterTool< LArHitContainer >, D3PD::SGCollectionGetterTool< LArRawChannelContainer >, D3PD::SGCollectionGetterTool< Obj4Container >, D3PD::SGCollectionGetterTool< TileDigitsContainer >, D3PD::SGCollectionGetterTool< TileHitVector >, D3PD::SGCollectionGetterTool< TileRawChannelContainer >, D3PD::SGCollectionGetterTool< TrackRecordCollection >, D3PD::SGTileDigitsGetterTool, D3PD::SGTileHitGetterTool, D3PD::SGTileModuleBitsGetterTool, and D3PD::SGTileRawChannelGetterTool.

Definition at line 39 of file SGGetterImpl.cxx.

40{
41 const std::type_info* ti = 0;
42 if (clidToTypeinfo (m_clid, m_typename, ti, this->name()).isSuccess())
43 return *ti;
44
45 REPORT_MESSAGE (MSG::ERROR) << "Can't find typeinfo for CLID "
46 << m_clid << " (type " << m_typename << ").";
47 return typeid (void);
48}
StatusCode clidToTypeinfo(CLID clid, const std::string &nmae, std::type_info const *&ti, const std::string &context)
Convert from a CLID to a type_info; we also already know the name.

Member Data Documentation

◆ m_backConverter

TypeConverter D3PD::ObjGetterToolImpl::m_backConverter
privateinherited

Helper to convert pointers back, for releaseObject.

Definition at line 97 of file ObjGetterToolImpl.h.

◆ m_clid

CLID D3PD::SGGetterImpl::m_clid
privateinherited

CLID for the object being retrieved.

Definition at line 126 of file SGGetterImpl.h.

◆ m_clidsvc

ServiceHandle<IClassIDSvc> D3PD::SGGetterImpl::m_clidsvc
protectedinherited

Property: Instance of the ClassIDSvc to use.

Definition at line 119 of file SGGetterImpl.h.

◆ m_converter

TypeConverter D3PD::ObjGetterToolImpl::m_converter
privateinherited

Helper to convert pointers.

Definition at line 94 of file ObjGetterToolImpl.h.

◆ m_resolver

SGKeyResolver D3PD::SGGetterImpl::m_resolver
protectedinherited

Helper: Resolve the SG key to use.

Definition at line 122 of file SGGetterImpl.h.

◆ m_sg

ServiceHandle<StoreGateSvc>& D3PD::SGGetterImpl::m_sg
privateinherited

The event storage service.

Definition at line 129 of file SGGetterImpl.h.

◆ m_sgkey

std::string D3PD::SGGetterImpl::m_sgkey
protectedinherited

Property: StoreGate key of the object being retrieved.

Definition at line 116 of file SGGetterImpl.h.

◆ m_typename

std::string D3PD::SGGetterImpl::m_typename
protectedinherited

Property: Name of the type of the object being retrieved.

Definition at line 113 of file SGGetterImpl.h.


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