ATLAS Offline Software
Loading...
Searching...
No Matches
SGDataVectorGetterTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12
16#include "TROOT.h"
17#include "TMethodCall.h"
18
19
20namespace D3PD {
21
22
30 (const std::string& type,
31 const std::string& name,
32 const IInterface* parent)
33 : SGGetterImpl (name, this->evtStore()),
34 CollectionGetterToolImpl (type, name, parent),
35 m_athenaPoolCnvSvc ("AthenaPoolCnvSvc", name),
36 m_info (0),
37 m_it (0)
38{
40}
41
42
47{
48 CHECK( m_athenaPoolCnvSvc.retrieve() );
49
50 // Initialize the code getting the collection from SG.
52
53 // Find the DataVector/DataList information for this collection.
55
56 // We couldn't find it.
57 // Maybe we haven't yet loaded a library that has a complete
58 // instantiation of the DataVector class. Try loading the pool
59 // converter, and see if that'll do it.
60 if (!m_info) {
61 m_athenaPoolCnvSvc->converter (clid());
63 }
64
65 // Maybe it didn't. (Once we make the info method virtual, then loading
66 // the converter should always do it. But now, maybe not.)
67 // As a last attempt, try to load a dictionary for the class.
68 if (!m_info) {
69 TClass* cls = gROOT->GetClass (m_typename.c_str());
70 cls->GetBaseClass ("SG::AuxElement");
72 }
73
74 // Ok, one more try...
75 if (!m_info) {
76 TClass* cls = gROOT->GetClass (m_typename.c_str());
77 TMethodCall meth (cls, "initHelper", "");
78 if (meth.IsValid())
79 meth.Execute();
81 }
82 if (!m_info) {
83 TClass* cls = gROOT->GetClass (m_typename.c_str());
84 TMethodCall meth (cls, "dvlinfo", "");
85 if (meth.IsValid())
86 meth.Execute();
88 }
89
90 if (!m_info) {
91 REPORT_MESSAGE (MSG::ERROR)
92 << "Can't find DataVector/DataList info for class " << m_typename;
93 return StatusCode::FAILURE;
94 }
95
96 // We need to convert from the type we get from SG to the DV/DL base class.
97 CHECK( m_converter.init (typeinfo(), m_info->tinfo()) );
98
100}
101
102
107{
108 delete m_it;
109 m_it = 0;
110 return StatusCode::SUCCESS;
111}
112
113
119const std::type_info& SGDataVectorGetterTool::elementTypeinfo() const
120{
121 return m_info->elt_tinfo();
122}
123
124
132StatusCode SGDataVectorGetterTool::reset (bool allowMissing /*= false*/)
133{
134 delete m_it;
135 const void* p0 = getUntyped (allowMissing);
136 if (allowMissing && p0 == 0) {
137 m_it = 0;
138 return StatusCode::SUCCESS;
139 }
140 const void* p = m_converter.convertUntyped (p0);
141 if (p) {
142 // need non-const pointer to call `base`
143 void* nonconst_p ATLAS_THREAD_SAFE = const_cast<void*> (p);
144 SG::AuxVectorBase* auxbase = m_info->base (nonconst_p);
145 if (auxbase && auxbase->trackIndices() && !auxbase->getConstStore()) {
146 // Try to retrieve a corresponding aux store.
147 const SG::IConstAuxStore* store =
148 evtStore()->tryConstRetrieve<SG::IConstAuxStore> (m_resolver.key() + "Aux.");
149 if (store)
150 auxbase->setStore (store);
151 }
152 m_it = m_info->iterator (p);
153 return StatusCode::SUCCESS;
154 }
155 else {
156 m_it = 0;
157 return StatusCode::FAILURE;
158 }
159}
160
161
168{
169 if (m_it)
170 return m_it->next();
171 return 0;
172}
173
174
185size_t SGDataVectorGetterTool::sizeHint (bool allowMissing /*= false*/)
186{
187 // need non-const pointer to call `size`
188 void* p ATLAS_THREAD_SAFE = const_cast<void*>(m_converter.convertUntyped (getUntyped (allowMissing)));
189 if (!p) return 0;
190 return m_info->size (p);
191}
192
193
199SGDataVectorGetterTool::getInfo (const std::type_info& ti)
200{
201 // If we have info for this class directly, use that.
204 if (info) return info;
205
206 // We gotta check the base classes. Fail if we don't have
207 // base info.
209 if (!bib) return 0;
210
211 // Pick the most-derived class among the possible bases.
212 std::vector<const std::type_info*> bases = bib->get_ti_bases();
213 for (size_t i = 0; i < bases.size(); i++) {
216 if (this_info) {
217 if (info) {
218 bib = SG::BaseInfoBase::find (this_info->tinfo());
219 if (bib && bib->is_base (info->tinfo()))
220 info = this_info;
221 }
222 else
223 info = this_info;
224 }
225 }
226 return info;
227}
228
229
230} // namespace D3PD
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
Holder to implement conversion copies for DataVector/DataList.
Getter tool to retrieve DataVector/List collections from StoreGate.
#define SGGETTERIMPL_PROPS
Use this macro in the constructor of the derived AlgTool class.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
StatusCode initialize()
Standard Gaudi initialize method.
CollectionGetterToolImpl(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
ServiceHandle< IAthenaPoolCnvSvc > m_athenaPoolCnvSvc
Used to auto-load converters, if needed.
virtual StatusCode initialize()
Standard Gaudi initialize method.
TypeConverter m_converter
Converter from the pointer that we get from StoreGate to a pointer to the collection over which we it...
virtual size_t sizeHint(bool allowMissing=false)
Return an estimate of the number of elements in the iteration.
const DataModel_detail::DVLInfoBase * getInfo(const std::type_info &ti)
Retrieve DataVector/List information for this collection.
virtual const std::type_info & elementTypeinfo() const
Return the element type of the collection.
virtual StatusCode finalize()
Standard Gaudi finalize method.
virtual const void * nextUntyped()
Return a pointer to the next element in the collection.
DataModel_detail::DVLIteratorBase * m_it
Current iterator over the collection.
SGDataVectorGetterTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
const DataModel_detail::DVLInfoBase * m_info
DataVector/List information for this collection.
virtual StatusCode reset(bool allowMissing=false)
Reset the iteration to the start of the collection.
std::string m_typename
Property: Name of the type of the object being retrieved.
SGKeyResolver m_resolver
Helper: Resolve the SG key to use.
SGGetterImpl(const std::string &name, ServiceHandle< StoreGateSvc > &sg)
Constructor.
StatusCode initializeImpl()
Initialize this mixin class.
virtual const void * getUntyped(bool allowMissing=false)
Return the target object.
CLID clid() const
Return the class ID being read by this tool.
virtual const std::type_info & typeinfo() const
Return the type of object retrieved by this tool.
static DVLInfoBase * find(const std::type_info &tinfo)
Find the DVLInfo for the container tinfo.
Definition DVLInfo.cxx:76
const std::type_info & tinfo() const
Return the type_info for the container.
Manage index tracking and synchronization of auxiliary data.
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
bool trackIndices() const
Return true if index tracking is enabled for this container.
const SG::IConstAuxStore * getConstStore() const
Return the current store, as a const interface.
The non-template portion of the BaseInfo implementation.
std::vector< const std::type_info * > get_ti_bases() const
Return the type_info's of all known bases of T.
Definition BaseInfo.cxx:326
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
Definition BaseInfo.cxx:570
bool is_base(CLID clid) const
Return true if clid is the ID of a class that is known to be a base of T.
Definition BaseInfo.cxx:344
Interface for const operations on an auxiliary store.
Block filler tool for noisy FEB information.