ATLAS Offline Software
SGCollectionGetterTool.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 /**
5  * @file D3PDMakerUtils/SGCollectionGetterTool.icc
6  * @author scott snyder <snyder@bnl.gov>
7  * @date Aug, 2009
8  * @brief Collection getter tool retrieving a container from StoreGate.
9  */
10 
11 
12 namespace D3PD {
13 
14 
15 /**
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.
20  */
21 template <class CONT>
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)
28 {
29  SGGETTERIMPL_PROPS;
30 
31  if (this->setProperty ("TypeName",
32  ClassID_traits<CONT>::typeName()).isFailure())
33  {
34  REPORT_MESSAGE (MSG::ERROR) << "Can't set TypeName property for tool "
35  << type << "/" << name;
36  // cppcheck-suppress missingReturn; false positive
37  }
38 }
39 
40 
41 /**
42  * @brief Standard Gaudi initialize method.
43  */
44 template <class CONT>
45 StatusCode SGCollectionGetterTool<CONT>::initialize()
46 {
47  if (this->getProperty ("TypeName").toString() !=
48  ClassID_traits<CONT>::typeName())
49  {
50  REPORT_MESSAGE (MSG::ERROR) << "TypeName property for tool "
51  << this->type() << "/" << this->name()
52  << " was changed to "
53  << this->getProperty ("TypeName").toString()
54  << "; should be "
55  << ClassID_traits<CONT>::typeName();
56  }
57 
58  CHECK( SGGetterImpl::initializeImpl() );
59  return CollectionGetterToolImpl::initialize();
60 }
61 
62 
63 /**
64  * @brief Return the type of object retrieved by this tool.
65  */
66 template <class CONT>
67 const std::type_info& SGCollectionGetterTool<CONT>::typeinfo() const
68 {
69  return typeid(CONT);
70 }
71 
72 
73 /**
74  * @brief Return the target object.
75  * @param allowMissing If true, then we should not generate errors
76  * if the requested object is missing.
77  *
78  * Should be of the type given by @c typeinfo.
79  * Return 0 on failure.
80  */
81 template <class CONT>
82 const void*
83 SGCollectionGetterTool<CONT>::getUntyped (bool allowMissing /*= false*/)
84 {
85  return SGGetterImpl::getUntyped (allowMissing);
86 }
87 
88 
89 /**
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.
93  *
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.
96  */
97 template <class CONT>
98 const CONT* SGCollectionGetterTool<CONT>::get (bool allowMissing /*= false*/)
99 {
100  return reinterpret_cast<const CONT*> (getUntyped (allowMissing));
101 }
102 
103 
104 } // namespace D3PD