ATLAS Offline Software
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 
13 #include "SGDataVectorGetterTool.h"
16 #include "TROOT.h"
17 #include "TMethodCall.h"
18 
19 
20 namespace D3PD {
21 
22 
30  (const std::string& type,
31  const std::string& name,
32  const IInterface* parent)
33  : SGGetterImpl (name, this->evtStore()),
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.
54  m_info = getInfo (typeinfo());
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());
62  m_info = getInfo (typeinfo());
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");
71  m_info = getInfo (typeinfo());
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();
80  m_info = getInfo (typeinfo());
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();
87  m_info = getInfo (typeinfo());
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.
98 
100 }
101 
102 
107 {
108  delete m_it;
109  m_it = 0;
110  return StatusCode::SUCCESS;
111 }
112 
113 
119 const std::type_info& SGDataVectorGetterTool::elementTypeinfo() const
120 {
121  return m_info->elt_tinfo();
122 }
123 
124 
132 StatusCode 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 
185 size_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 
199 SGDataVectorGetterTool::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.
208  const SG::BaseInfoBase* bib = SG::BaseInfoBase::find (ti);
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++) {
214  DataModel_detail::DVLInfoBase* this_info =
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
grepfile.info
info
Definition: grepfile.py:38
SG::AuxVectorData::getConstStore
const SG::IConstAuxStore * getConstStore() const
Return the current store, as a const interface.
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
DataModel_detail::DVLInfoBase::tinfo
const std::type_info & tinfo() const
Return the type_info for the container.
D3PD::SGDataVectorGetterTool::m_it
DataModel_detail::DVLIteratorBase * m_it
Current iterator over the collection.
Definition: SGDataVectorGetterTool.h:126
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
D3PD::SGDataVectorGetterTool::finalize
virtual StatusCode finalize()
Standard Gaudi finalize method.
Definition: SGDataVectorGetterTool.cxx:106
D3PD::SGDataVectorGetterTool::sizeHint
virtual size_t sizeHint(bool allowMissing=false)
Return an estimate of the number of elements in the iteration.
Definition: SGDataVectorGetterTool.cxx:185
D3PD::SGGetterImpl::typeinfo
virtual const std::type_info & typeinfo() const
Return the type of object retrieved by this tool.
Definition: SGGetterImpl.cxx:39
DataModel_detail::DVLIteratorBase::next
virtual const void * next()=0
Return the next element from the container.
D3PD::SGDataVectorGetterTool::reset
virtual StatusCode reset(bool allowMissing=false)
Reset the iteration to the start of the collection.
Definition: SGDataVectorGetterTool.cxx:132
D3PD::SGDataVectorGetterTool::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition: SGDataVectorGetterTool.cxx:46
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
SG::AuxVectorBase::setStore
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
Definition: AuxVectorBase.cxx:96
DVLInfo.h
Holder to implement conversion copies for DataVector/DataList.
SG::BaseInfoBase::get_ti_bases
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
SG::AuxVectorBase
Manage index tracking and synchronization of auxiliary data.
Definition: AuxVectorBase.h:98
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::SGDataVectorGetterTool::elementTypeinfo
virtual const std::type_info & elementTypeinfo() const
Return the element type of the collection.
Definition: SGDataVectorGetterTool.cxx:119
SGDataVectorGetterTool.h
Getter tool to retrieve DataVector/List collections from StoreGate.
DataModel_detail::DVLInfoBase
Definition: DVLInfo.h:68
D3PD::SGDataVectorGetterTool::m_athenaPoolCnvSvc
ServiceHandle< IAthenaPoolCnvSvc > m_athenaPoolCnvSvc
Used to auto-load converters, if needed.
Definition: SGDataVectorGetterTool.h:117
D3PD::SGDataVectorGetterTool::m_converter
TypeConverter m_converter
Converter from the pointer that we get from StoreGate to a pointer to the collection over which we it...
Definition: SGDataVectorGetterTool.h:131
DataModel_detail::DVLInfoBase::iterator
virtual DVLIteratorBase * iterator(const void *cont_p) const =0
Return a new iterator object.
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: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:21
DataModel_detail::DVLInfoBase::size
virtual size_t size(void *cont_p) const =0
Return the size of the container.
D3PD::SGGetterImpl::clid
CLID clid() const
Return the class ID being read by this tool.
Definition: SGGetterImpl.cxx:54
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
D3PD::CollectionGetterToolImpl::initialize
StatusCode initialize()
Standard Gaudi initialize method.
Definition: CollectionGetterToolImpl.cxx:45
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
D3PD::SGDataVectorGetterTool::m_info
const DataModel_detail::DVLInfoBase * m_info
DataVector/List information for this collection.
Definition: SGDataVectorGetterTool.h:123
DataModel_detail::DVLInfoBase::find
static DVLInfoBase * find(const std::type_info &tinfo)
Find the DVLInfo for the container tinfo.
Definition: DVLInfo.cxx:76
D3PD::SGDataVectorGetterTool::nextUntyped
virtual const void * nextUntyped()
Return a pointer to the next element in the collection.
Definition: SGDataVectorGetterTool.cxx:167
D3PD::SGKeyResolver::key
std::string key()
Return the SG key we should use.
Definition: SGKeyResolver.cxx:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::BaseInfoBase::find
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
Definition: BaseInfo.cxx:569
StoreGateSvc::tryConstRetrieve
const T * tryConstRetrieve() const
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
SGGETTERIMPL_PROPS
#define SGGETTERIMPL_PROPS
Use this macro in the constructor of the derived AlgTool class.
Definition: SGGetterImpl.h:90
D3PD::SGGetterImpl::m_typename
std::string m_typename
Property: Name of the type of the object being retrieved.
Definition: SGGetterImpl.h:113
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::SGGetterImpl::m_resolver
SGKeyResolver m_resolver
Helper: Resolve the SG key to use.
Definition: SGGetterImpl.h:122
SG::BaseInfoBase
The non-template portion of the BaseInfo implementation.
Definition: Control/AthenaKernel/AthenaKernel/BaseInfo.h:451
D3PD::SGDataVectorGetterTool::SGDataVectorGetterTool
SGDataVectorGetterTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: SGDataVectorGetterTool.cxx:30
DataModel_detail::DVLInfoBase::elt_tinfo
const std::type_info & elt_tinfo() const
Return the type_info for the container's element.
D3PD::SGDataVectorGetterTool::getInfo
const DataModel_detail::DVLInfoBase * getInfo(const std::type_info &ti)
Retrieve DataVector/List information for this collection.
Definition: SGDataVectorGetterTool.cxx:199
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
DataModel_detail::DVLInfoBase::base
virtual SG::AuxVectorBase * base(void *cont_p) const =0
Return a pointer to the container base.
SG::IConstAuxStore
Interface for const operations on an auxiliary store.
Definition: IConstAuxStore.h:64
checker_macros.h
Define macros for attributes used to control the static checker.
SG::AuxVectorBase::trackIndices
bool trackIndices() const
Return true if index tracking is enabled for this container.
D3PD::SGGetterImpl::getUntyped
virtual const void * getUntyped(bool allowMissing=false)
Return the target object.
Definition: SGGetterImpl.cxx:68
D3PD::SGGetterImpl::initializeImpl
StatusCode initializeImpl()
Initialize this mixin class.
Definition: SGGetterImpl.cxx:105
D3PD::SGGetterImpl
Common object getter code for retrieving from StoreGate.
Definition: SGGetterImpl.h:52
SG::BaseInfoBase::is_base
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
D3PD::CollectionGetterToolImpl
Non-template parts of CollectionGetterTool.
Definition: CollectionGetterToolImpl.h:42