ATLAS Offline Software
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
13 namespace {
14 
15 // Helpers to pack/unpack the PTR#TYPE/NAME string set up by the macros
16 // in AsgToolMacros.h.
17 
18 std::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 
31 std::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 
39 const 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 }
51 
52 } // anonymous namespace
53 #endif // not XAOD_STANDALONE
54 
55 
56 namespace asg {
57 
58  AsgTool::AsgTool( const std::string& name )
59  : AsgToolBase(
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 
80  SgTEvent* AsgTool::evtStore() const {
81 
82  return &m_event;
83  }
84 
85 #endif // XAOD_STANDALONE
86 
101  const std::string& AsgTool::msg_level_name() const {
102 
103  return MSG::name( msg().level() );
104  }
105 
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  }
136 
137 } // namespace asg
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
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
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
asg
Definition: DataHandleTestTool.h:28
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
asg::AsgTool::~AsgTool
~AsgTool()
Destructor.
Definition: AsgTool.cxx:73
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::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition: AsgTool.cxx:58
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
python.xAODType.dummy
dummy
Definition: xAODType.py:4
MSG::name
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition: MsgLevel.cxx:19
asg::ToolStore::put
static StatusCode put(IAsgTool *ptool)
Store a named tool by its name.
Definition: ToolStore.cxx:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
asg::AsgTool::msg_level_name
const std::string & msg_level_name() const __attribute__((deprecated))
A deprecated function for getting the message level's name.
Definition: AsgTool.cxx:101
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
asg::SgTEvent
Wrapper for TEvent to make it look like StoreGate.
Definition: SgTEvent.h:44
asg::ToolStore::remove
static StatusCode remove(const IAsgTool *tool)
Remove the specified tool from the store.
Definition: ToolStore.cxx:77
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ToolStore.h
AthAlgTool
Definition: AthAlgTool.h:26
AsgTool.h
SG::DataProxy
Definition: DataProxy.h:44
asg::AsgTool::print
virtual void print() const
Print the state of the tool.
Definition: AsgTool.cxx:131
Ringer::getType
T getType(const char *cStr)
Return Ringer enumeration of type T identifying string type: