ATLAS Offline Software
Loading...
Searching...
No Matches
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).
7
8// Athena include(s);
10
11// EDM include(s).
12#include "xAODCore/CLASS_DEF.h"
13
14// System include(s).
15#include <memory>
16#include <string>
17
18namespace asg {
19
20 EventStoreTestTool::EventStoreTestTool( const std::string& toolName )
21 : asg::AsgTool( toolName ) {
22
23 }
24
26
27 // Initialize the key.
28 ATH_CHECK( m_containerKey.initialize() );
29
30 return StatusCode::SUCCESS;
31 }
32
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.
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 =
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Handle class for recording to StoreGate.
File providing the different SG_BASE macros.
uint32_t CLID
The Class ID type.
ServiceHandle< StoreGateSvc > & evtStore()
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
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
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
virtual StatusCode initialize() override
Initialize.
virtual StatusCode performTest() const override
Function performing (a) test(s) with the event store.
EventStoreTestTool(const std::string &toolName)
Constructor.
SG::WriteHandleKey< xAOD::IParticleContainer > m_containerKey
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.