ATLAS Offline Software
ObjGetterToolImpl.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
16 #include "GaudiKernel/System.h"
17 
18 
19 namespace D3PD {
20 
21 
29  const std::string& name,
30  const IInterface* parent)
31  : base_class (type, name, parent)
32 {
33 }
34 
35 
45 const void* ObjGetterToolImpl::getTypeinfo (const std::type_info& ti,
46  bool allowMissing /*= false*/)
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 }
70 
71 
83  const std::type_info& ti)
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 }
113 
114 
124 ObjGetterToolImpl::configureTypeinfo (const std::type_info& ti)
125 {
126  return this->m_converter.init(this->typeinfo(), ti);
127 }
128 
129 
130 } // namespace D3PD
D3PD::ObjGetterToolImpl::m_backConverter
TypeConverter m_backConverter
Helper to convert pointers back, for releaseObject.
Definition: ObjGetterToolImpl.h:97
D3PD::TypeConverter::dstName
std::string dstName() const
Return the name of the destination type, or an empty string.
Definition: TypeConverter.cxx:151
D3PD::ObjGetterToolImpl::getTypeinfo
virtual const void * getTypeinfo(const std::type_info &ti, bool allowMissing=false)
Return the target object cast to a different pointer type.
Definition: ObjGetterToolImpl.cxx:45
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::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
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ObjGetterToolImpl.h
Non-template parts of ObjGetterTool.
D3PD::ObjGetterToolImpl::ObjGetterToolImpl
ObjGetterToolImpl(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: ObjGetterToolImpl.cxx:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
errorcheck.h
Helpers for checking error return status codes and reporting errors.
D3PD::TypeConverter::isValid
bool isValid() const
Test to see if this converter has been properly initialized.
D3PD::ObjGetterToolImpl::releaseObjectTypeinfo
void releaseObjectTypeinfo(const void *p, const std::type_info &ti)
Release an object retrieved from the getter.
Definition: ObjGetterToolImpl.cxx:82
D3PD::ObjGetterToolImpl::configureTypeinfo
virtual StatusCode configureTypeinfo(const std::type_info &ti)
Test type compatibility.
Definition: ObjGetterToolImpl.cxx:124
D3PD::ObjGetterToolImpl::m_converter
TypeConverter m_converter
Helper to convert pointers.
Definition: ObjGetterToolImpl.h:94
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78