2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 * @file D3PDMakerUtils/SGCollectionGetterTool.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Collection getter tool retrieving a container from StoreGate.
16 * @brief Standard Gaudi tool constructor.
17 * @param type The name of the tool type.
18 * @param name The tool name.
19 * @param parent The tool's Gaudi parent.
22 SGCollectionGetterTool<CONT>::SGCollectionGetterTool
23 (const std::string& type,
24 const std::string& name,
25 const IInterface* parent)
26 : SGGetterImpl (name, this->evtStore()),
27 CollectionGetterTool<CONT> (type, name, parent)
31 if (this->setProperty ("TypeName",
32 ClassID_traits<CONT>::typeName()).isFailure())
34 REPORT_MESSAGE (MSG::ERROR) << "Can't set TypeName property for tool "
35 << type << "/" << name;
36 // cppcheck-suppress missingReturn; false positive
42 * @brief Standard Gaudi initialize method.
45 StatusCode SGCollectionGetterTool<CONT>::initialize()
47 if (this->getProperty ("TypeName").toString() !=
48 ClassID_traits<CONT>::typeName())
50 REPORT_MESSAGE (MSG::ERROR) << "TypeName property for tool "
51 << this->type() << "/" << this->name()
53 << this->getProperty ("TypeName").toString()
55 << ClassID_traits<CONT>::typeName();
58 CHECK( SGGetterImpl::initializeImpl() );
59 return CollectionGetterToolImpl::initialize();
64 * @brief Return the type of object retrieved by this tool.
67 const std::type_info& SGCollectionGetterTool<CONT>::typeinfo() const
74 * @brief Return the target object.
75 * @param allowMissing If true, then we should not generate errors
76 * if the requested object is missing.
78 * Should be of the type given by @c typeinfo.
79 * Return 0 on failure.
83 SGCollectionGetterTool<CONT>::getUntyped (bool allowMissing /*= false*/)
85 return SGGetterImpl::getUntyped (allowMissing);
90 * @brief Type-safe wrapper for @c get.
91 * @param allowMissing If true, then we should not generate errors
92 * if the requested object is missing.
94 * Return the object as a pointer to @c T.
95 * Return 0 if the get fails or if the pointer can't be converted.
98 const CONT* SGCollectionGetterTool<CONT>::get (bool allowMissing /*= false*/)
100 return reinterpret_cast<const CONT*> (getUntyped (allowMissing));