ATLAS Offline Software
Static Public Member Functions | List of all members
asg::ToolStore Class Reference

A light-weight replacement for ToolSvc for ROOT analysis. More...

#include <ToolStore.h>

Collaboration diagram for asg::ToolStore:

Static Public Member Functions

static StatusCode put (IAsgTool *ptool)
 Store a named tool by its name. More...
 
static IAsgToolget (const std::string &name, bool silent=false)
 Retrieve a tool by name. More...
 
template<typename T >
static T * get (const std::string &name)
 Retrieve a tool by name and interface. More...
 
template<typename T >
static bool contains (const std::string &name)
 Check whether a tool with a given type and name is known in the store. More...
 
static StatusCode remove (const IAsgTool *tool)
 Remove the specified tool from the store. More...
 
static StatusCode remove (const std::string &name)
 Remove a tool with a given name from the store. More...
 

Detailed Description

A light-weight replacement for ToolSvc for ROOT analysis.

In order to allow tools to find each other through ToolHandles, just like in Athena, we need a global registry of all of the tools that the user instantiates in his/her job.

This class does exactly this. All created dual-use tools register themselves in it, so that other components could later on find them.

Author
David Adams dlada.nosp@m.ms@b.nosp@m.nl.go.nosp@m.v
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h
Revision
802972
Date
2017-04-15 20:13:17 +0200 (Sat, 15 Apr 2017)

Definition at line 32 of file ToolStore.h.

Member Function Documentation

◆ contains()

template<typename T >
static bool asg::ToolStore::contains ( const std::string &  name)
inlinestatic

Check whether a tool with a given type and name is known in the store.

Definition at line 52 of file ToolStore.h.

52  {
53 
54  return ( dynamic_cast< T* >( get( name, true ) ) != 0 );
55  }

◆ get() [1/2]

template<typename T >
static T* asg::ToolStore::get ( const std::string &  name)
inlinestatic

Retrieve a tool by name and interface.

Definition at line 45 of file ToolStore.h.

45  {
46 
47  return dynamic_cast< T* >( get( name ) );
48  }

◆ get() [2/2]

IAsgTool * asg::ToolStore::get ( const std::string &  name,
bool  silent = false 
)
static

Retrieve a tool by name.

Definition at line 57 of file ToolStore.cxx.

57  {
58  using namespace msgToolStore;
59 
60  std::lock_guard<std::mutex> lock (s_toolMutex);
61  ToolMap_t::const_iterator itool = s_tools.find( name );
62  if( itool != s_tools.end() )
63  return itool->second;
64 
65  if (name.compare(0, 8, "ToolSvc.") != 0) {
66  itool = s_tools.find( "ToolSvc." + name );
67  if( itool != s_tools.end() )
68  return itool->second;
69  }
70 
71  if( ! silent ) {
72  ANA_MSG_WARNING ("Tool with name \"" << name << "\" not found");
73  }
74  return nullptr;
75  }

◆ put()

StatusCode asg::ToolStore::put ( IAsgTool ptool)
static

Store a named tool by its name.

The name must be non-blank and not already exist in the store.

Definition at line 28 of file ToolStore.cxx.

28  {
29  using namespace msgToolStore;
30 
31  // Start with a little sanity check:
32  if( ! ptool ) {
33  ANA_MSG_ERROR( "asg::ToolStore::put: Received a null pointer" );
34  return StatusCode::FAILURE;
35  }
36 
37  // Get and check the name of the tool:
38  const std::string& name = ptool->name();
39  if( ! name.size() ) {
40  ANA_MSG_ERROR( "asg::ToolStore::put: The received tool doesn't have a name" );
41  return StatusCode::FAILURE;
42  }
43 
44  std::lock_guard<std::mutex> lock (s_toolMutex);
45  // Check whether we already have a tool with this name:
46  if( s_tools.find( name ) != s_tools.end() ) {
47  ANA_MSG_WARNING ("asg::ToolStore::put: Tool with name \""
48  << name << "\" already registered");
49  return StatusCode::FAILURE;
50  }
51 
52  // Remember the tool:
53  s_tools[ name ] = ptool;
54  return StatusCode::SUCCESS;
55  }

◆ remove() [1/2]

StatusCode asg::ToolStore::remove ( const IAsgTool tool)
static

Remove the specified tool from the store.

Definition at line 77 of file ToolStore.cxx.

77  {
78 
79  // Delegate the call to the other function:
80  return remove( tool->name() );
81  }

◆ remove() [2/2]

StatusCode asg::ToolStore::remove ( const std::string &  name)
static

Remove a tool with a given name from the store.

Definition at line 83 of file ToolStore.cxx.

83  {
84 
85  std::lock_guard<std::mutex> lock (s_toolMutex);
86  // Remove the tool, not checking if the call was successful or not:
87  s_tools.erase( name );
88  return StatusCode::SUCCESS;
89  }

The documentation for this class was generated from the following files:
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
asg::ToolStore::get
static IAsgTool * get(const std::string &name, bool silent=false)
Retrieve a tool by name.
Definition: ToolStore.cxx:57
asg::ToolStore::remove
static StatusCode remove(const IAsgTool *tool)
Remove the specified tool from the store.
Definition: ToolStore.cxx:77
python.trfDecorators.silent
def silent(func)
Redirect stdout/err to /dev/null Useful wrapper to get rid of ROOT verbosity...
Definition: trfDecorators.py:24
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35