ATLAS Offline Software
Loading...
Searching...
No Matches
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.
static IAsgToolget (const std::string &name, bool silent=false)
 Retrieve a tool by name.
template<typename T>
static T * get (const std::string &name)
 Retrieve a tool by name and interface.
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.
static StatusCode remove (const IAsgTool *tool)
 Remove the specified tool from the store.
static StatusCode remove (const std::string &name)
 Remove a tool with a given name from the store.

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>
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 51 of file ToolStore.h.

51 {
52
53 return ( dynamic_cast< T* >( get( name, true ) ) != 0 );
54 }
static IAsgTool * get(const std::string &name, bool silent=false)
Retrieve a tool by name.
Definition ToolStore.cxx:57
unsigned long long T

◆ get() [1/2]

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

Retrieve a tool by name and interface.

Definition at line 44 of file ToolStore.h.

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

◆ 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 }
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.

◆ 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 }
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.

◆ 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 }
static StatusCode remove(const IAsgTool *tool)
Remove the specified tool from the store.
Definition ToolStore.cxx:77

◆ 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: