ATLAS Offline Software
Loading...
Searching...
No Matches
EventStoreTestTool.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s).
7
8// EDM include(s).
10#include "xAODCore/CLASS_DEF.h"
11
12// System include(s).
13#include <memory>
14#include <string>
15
16namespace asg {
17
18 EventStoreTestTool::EventStoreTestTool( const std::string& toolName )
19 : asg::AsgTool( toolName ) {
20
21 }
22
24
25 // Create an IParticle container.
26 auto particles = std::make_unique< xAOD::IParticleContainer >();
27 const xAOD::IParticleContainer* particlesPtr = particles.get();
28
29 // Make sure that the getName(...) and getKey(...) functions don't
30 // know about it at this point yet.
31 if( getName( particlesPtr ) != "" ) {
32 ATH_MSG_ERROR( "There is a problem with the asg::AsgTool::getName "
33 "function" );
34 return StatusCode::FAILURE;
35 }
36 if( getKey( particlesPtr ) != 0 ) {
37 ATH_MSG_ERROR( "There is a problem with the asg::AsgTool::getKey "
38 "function" );
39 return StatusCode::FAILURE;
40 }
41
42 // Record the container into the event store with some elaorate name.
43 static const std::string PARTICLES_NAME = "AsgTestIParticles";
44 ATH_CHECK( evtStore()->record( std::move( particles), PARTICLES_NAME ) );
45
46 // Depending on the environment, figure out what the hashed key for this
47 // object is supposed to be.
48#ifdef XAOD_STANDALONE
49 const SG::sgkey_t particlesKey =
50 evtStore()->event()->getHash( PARTICLES_NAME );
51#else
52 static const CLID IPARTICLE_CLID =
54 const SG::sgkey_t particlesKey =
55 evtStore()->stringToKey( PARTICLES_NAME, IPARTICLE_CLID );
56#endif // XAOD_STANDALONE
57
58 // Now check that the getName(...) and getKey(...) functions would
59 // return the expected values.
60 if( getName( particlesPtr ) != PARTICLES_NAME ) {
61 ATH_MSG_ERROR( "There is a problem with the asg::AsgTool::getName "
62 "function" );
63 return StatusCode::FAILURE;
64 }
65 if( getKey( particlesPtr ) != particlesKey ) {
66 ATH_MSG_ERROR( "There is a problem with the asg::AsgTool::getKey "
67 "function" );
68 return StatusCode::FAILURE;
69 }
70
71 // Return gracefully.
72 return StatusCode::SUCCESS;
73 }
74
75} // namespace asg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
File providing the different SG_BASE macros.
uint32_t CLID
The Class ID type.
ServiceHandle< StoreGateSvc > & evtStore()
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 performTest() const override
Function performing (a) test(s) with the event store.
EventStoreTestTool(const std::string &toolName)
Constructor.
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.