ATLAS Offline Software
Loading...
Searching...
No Matches
AsgTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5// System include(s):
6#include <iostream>
7
8// Local include(s):
9#include "AsgTools/AsgTool.h"
10#include "AsgTools/ToolStore.h"
11
12#ifndef XAOD_STANDALONE
13namespace {
14
15// Helpers to pack/unpack the PTR#TYPE/NAME string set up by the macros
16// in AsgToolMacros.h.
17
18std::string getType (const std::string& s)
19{
20 std::string::size_type pos1 = s.find('#');
21 if (pos1 == std::string::npos)
22 pos1 = 0;
23 else
24 ++pos1;
25 std::string::size_type pos2 = s.find('/', pos1);
26 if (pos2 != std::string::npos)
27 return s.substr (pos1, pos2-pos1);
28 return "";
29}
30
31std::string getName (const std::string& s)
32{
33 std::string::size_type pos = s.find('/');
34 if (pos == std::string::npos)
35 return s;
36 return s.substr (pos+1, std::string::npos);
37}
38
39const IInterface* getParent (const std::string& s)
40{
41 std::string::size_type pos = s.find('#');
42 if (pos == std::string::npos)
43 return Gaudi::svcLocator()->service( "ToolSvc" );
44 void* p;
45 std::string ss = s.substr (0, pos);
46 sscanf (ss.c_str(), "%p", &p);
47 if (p != nullptr)
48 return reinterpret_cast<IInterface*>(p);
49 return Gaudi::svcLocator()->service( "ToolSvc" );
50}
52} // anonymous namespace
53#endif // not XAOD_STANDALONE
54
55
56namespace asg {
57
58 AsgTool::AsgTool( const std::string& name )
60#ifndef XAOD_STANDALONE
61 ::getType(name), ::getName(name), ::getParent(name)
62#else // not XAOD_STANDALONE
63 name
64#endif // not XAOD_STANDALONE
65 )
66#ifdef XAOD_STANDALONE
67 , m_event()
68#endif // XAOD_STANDALONE
69 {
70 ToolStore::put( this ).ignore(); // Register the tool in the ToolStore
71 }
72
74
75 ToolStore::remove( this ).ignore(); // Remove the tool from the ToolStore
76 }
77
78#ifdef XAOD_STANDALONE
79
81
82 return &m_event;
83 }
84
85#endif // XAOD_STANDALONE
101 const std::string& AsgTool::msg_level_name() const {
102
103 return MSG::name( msg().level() );
104 }
106 const std::string& AsgTool::getName( const void* ptr ) const {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::TEvent, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }
118
119 SG::sgkey_t AsgTool::getKey( const void* ptr ) const {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::TEvent, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
130
131 void AsgTool::print() const {
132
133 ATH_MSG_INFO( "AsgTool " << name() << " @ " << this );
134 return;
135 }
137} // namespace asg
#define ATH_MSG_INFO(x)
static Double_t ss
ServiceHandle< StoreGateSvc > & evtStore()
MsgStream & msg() const
const std::string & msg_level_name() const __attribute__((deprecated))
A deprecated function for getting the message level's name.
Definition AsgTool.cxx:101
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
~AsgTool()
Destructor.
Definition AsgTool.cxx:73
virtual void print() const
Print the state of the tool.
Definition AsgTool.cxx:131
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
Wrapper for TEvent to make it look like StoreGate.
Definition SgTEvent.h:44
static StatusCode remove(const IAsgTool *tool)
Remove the specified tool from the store.
Definition ToolStore.cxx:77
static StatusCode put(IAsgTool *ptool)
Store a named tool by its name.
Definition ToolStore.cxx:28
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19
T getType(const char *cStr)
Return Ringer enumeration of type T identifying string type:
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
::AthAlgTool AsgToolBase
Definition AsgTool.h:33