ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthToolSupport
AsgExampleTools
Root
EventStoreTestTool.cxx
Go to the documentation of this file.
1
//
2
// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
//
4
5
// Local include(s).
6
#include "
AsgExampleTools/EventStoreTestTool.h
"
7
8
// Athena include(s);
9
#include "
AsgDataHandles/WriteHandle.h
"
10
11
// EDM include(s).
12
#include "
xAODCore/CLASS_DEF.h
"
13
14
// System include(s).
15
#include <memory>
16
#include <string>
17
18
namespace
asg
{
19
20
EventStoreTestTool::EventStoreTestTool
(
const
std::string& toolName )
21
:
asg
::
AsgTool
( toolName ) {
22
23
}
24
25
StatusCode
EventStoreTestTool::initialize
() {
26
27
// Initialize the key.
28
ATH_CHECK
(
m_containerKey
.initialize() );
29
30
return
StatusCode::SUCCESS;
31
}
32
33
StatusCode
EventStoreTestTool::performTest
()
const
{
34
35
// Create an IParticle container.
36
auto
particles = std::make_unique< xAOD::IParticleContainer >();
37
const
xAOD::IParticleContainer
* particlesPtr = particles.get();
38
39
// Make sure that the getName(...) and getKey(...) functions don't
40
// know about it at this point yet.
41
if
(
getName
( particlesPtr ) !=
""
) {
42
ATH_MSG_ERROR
(
"There is a problem with the asg::AsgTool::getName "
43
"function"
);
44
return
StatusCode::FAILURE;
45
}
46
if
(
getKey
( particlesPtr ) != 0 ) {
47
ATH_MSG_ERROR
(
"There is a problem with the asg::AsgTool::getKey "
48
"function"
);
49
return
StatusCode::FAILURE;
50
}
51
52
// Record the container into the event store.
53
SG::WriteHandle<xAOD::IParticleContainer>
writeHandle(
m_containerKey
);
54
ATH_CHECK
( writeHandle.
record
( std::move( particles) ) );
55
56
// Depending on the environment, figure out what the hashed key for this
57
// object is supposed to be.
58
#ifdef XAOD_STANDALONE
59
const
SG::sgkey_t
particlesKey =
60
evtStore
()->event()->getHash(
m_containerKey
.key() );
61
#else
62
static
const
CLID
IPARTICLE_CLID =
63
ClassID_traits< xAOD::IParticleContainer >::ID
();
64
const
SG::sgkey_t
particlesKey =
65
evtStore
()->stringToKey(
m_containerKey
.key(), IPARTICLE_CLID );
66
#endif
// XAOD_STANDALONE
67
68
// Now check that the getName(...) and getKey(...) functions would
69
// return the expected values.
70
if
(
getName
( particlesPtr ) !=
m_containerKey
.key() ) {
71
ATH_MSG_ERROR
(
"There is a problem with the asg::AsgTool::getName "
72
"function"
);
73
return
StatusCode::FAILURE;
74
}
75
if
(
getKey
( particlesPtr ) != particlesKey ) {
76
ATH_MSG_ERROR
(
"There is a problem with the asg::AsgTool::getKey "
77
"function"
);
78
return
StatusCode::FAILURE;
79
}
80
81
// Return gracefully.
82
return
StatusCode::SUCCESS;
83
}
84
85
}
// namespace asg
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
WriteHandle.h
Handle class for recording to StoreGate.
EventStoreTestTool.h
CLASS_DEF.h
File providing the different SG_BASE macros.
CLID
uint32_t CLID
The Class ID type.
Definition
Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
asg::AsgTool::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition
AsgTool.cxx:58
asg::AsgTool::getName
const std::string & getName(const void *ptr) const
Get the name of an object that is / should be in the event store.
Definition
AsgTool.cxx:106
asg::AsgTool::getKey
SG::sgkey_t getKey(const void *ptr) const
Get the (hashed) key of an object that is in the event store.
Definition
AsgTool.cxx:119
asg::EventStoreTestTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition
EventStoreTestTool.cxx:25
asg::EventStoreTestTool::performTest
virtual StatusCode performTest() const override
Function performing (a) test(s) with the event store.
Definition
EventStoreTestTool.cxx:33
asg::EventStoreTestTool::EventStoreTestTool
EventStoreTestTool(const std::string &toolName)
Constructor.
Definition
EventStoreTestTool.cxx:20
asg::EventStoreTestTool::m_containerKey
SG::WriteHandleKey< xAOD::IParticleContainer > m_containerKey
Definition
EventStoreTestTool.h:41
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition
sgkey_t.h:32
asg
Definition
DataHandleTestTool.h:28
xAOD::IParticleContainer
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
Definition
xAOD/xAODBase/xAODBase/IParticleContainer.h:32
ClassID_traits::ID
static constexpr CLID ID()
Definition
Control/AthenaKernel/AthenaKernel/ClassID_traits.h:44
Generated on
for ATLAS Offline Software by
1.17.0