ATLAS Offline Software
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 
16 namespace 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
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
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
EventStoreTestTool.h
asg
Definition: DataHandleTestTool.h:28
asg::EventStoreTestTool::performTest
virtual StatusCode performTest() const override
Function performing (a) test(s) with the event store.
Definition: EventStoreTestTool.cxx:23
asg::EventStoreTestTool::EventStoreTestTool
EventStoreTestTool(const std::string &toolName)
Constructor.
Definition: EventStoreTestTool.cxx:18
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IParticleContainer.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
CLASS_DEF.h
File providing the different SG_BASE macros.
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84