ATLAS Offline Software
Loading...
Searching...
No Matches
D3PD::CollectionGetterRegistryTool Class Reference

Tool to keep a registry of collection getter tools. More...

#include <CollectionGetterRegistryTool.h>

Inheritance diagram for D3PD::CollectionGetterRegistryTool:
Collaboration diagram for D3PD::CollectionGetterRegistryTool:

Public Member Functions

 CollectionGetterRegistryTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard Gaudi tool constructor.
virtual StatusCode initialize ()
 Standard Gaudi initialize method.
virtual StatusCode add (const std::string &label, ICollectionGetterTool *tool)
 Register a new collection getter tool.
virtual StatusCode get (const std::string &label, const INamedInterface *parent, ICollectionGetterTool *&tool)
 Get a copy of a registered collection getter tool.

Private Types

typedef std::unordered_map< std::string, D3PD::ICollectionGetterTool * > map_t
 Map from getter labels to instances.

Private Attributes

ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jos
 Property: The job options service.
ServiceHandle< IToolSvc > m_toolsvc
 Property: The tool service.
map_t m_collection_map

Detailed Description

Tool to keep a registry of collection getter tools.

In order to represent associations by an index, we need to be able to get access to the collection within which we're indexing. We do this by optionally associating a label with a collection getter tool (this will typically be the object prefix). We can then look up the label here and make a copy of the matching getter tool. (We make a copy rather than using the original instance since the collection getters are stateful.)

Definition at line 45 of file CollectionGetterRegistryTool.h.

Member Typedef Documentation

◆ map_t

typedef std::unordered_map<std::string, D3PD::ICollectionGetterTool*> D3PD::CollectionGetterRegistryTool::map_t
private

Map from getter labels to instances.

Definition at line 95 of file CollectionGetterRegistryTool.h.

Constructor & Destructor Documentation

◆ CollectionGetterRegistryTool()

D3PD::CollectionGetterRegistryTool::CollectionGetterRegistryTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Standard Gaudi tool constructor.

Parameters
typeThe name of the tool type.
nameThe tool name.
parentThe tool's Gaudi parent.

Definition at line 29 of file CollectionGetterRegistryTool.cxx.

33 : base_class (type, name, parent),
34 m_jos ("JobOptionsSvc", name),
35 m_toolsvc ("ToolSvc", name)
36{
37 declareProperty ("JobOptionsSvc", m_jos,
38 "The JobOptionsSvc instance.");
39 declareProperty ("ToolSvc", m_toolsvc,
40 "The ToolSvc instance.");
41}
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jos
Property: The job options service.
ServiceHandle< IToolSvc > m_toolsvc
Property: The tool service.

Member Function Documentation

◆ add()

StatusCode D3PD::CollectionGetterRegistryTool::add ( const std::string & label,
ICollectionGetterTool * tool )
virtual

Register a new collection getter tool.

Parameters
labelLabel for the tool.
toolThe tool instance.

Definition at line 62 of file CollectionGetterRegistryTool.cxx.

64{
65 std::pair<map_t::iterator, bool> res =
66 m_collection_map.insert (std::make_pair (label, tool));
67 if (!res.second) {
69 "D3PD::CollectionGetterRegistryTool")
70 << "Duplicate collection label " << label
71 << " for tools " << res.first->second->name()
72 << " and " << tool->name();
73 return StatusCode::FAILURE;
74 }
75 return StatusCode::SUCCESS;
76}
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
std::pair< std::vector< unsigned int >, bool > res
std::string label(const std::string &format, int i)
Definition label.h:19

◆ get()

StatusCode D3PD::CollectionGetterRegistryTool::get ( const std::string & label,
const INamedInterface * parent,
ICollectionGetterTool *& tool )
virtual

Get a copy of a registered collection getter tool.

Parameters
labelLabel for the tool.
parentParent for the new tool.
toolThe new tool instance.

The new tool will be a private tool, owned by parent.

Definition at line 88 of file CollectionGetterRegistryTool.cxx.

91{
92 // Loop up the tool in the map.
93 tool = 0;
94 map_t::iterator i = m_collection_map.find (label);
95 if (i == m_collection_map.end()) {
96 REPORT_MESSAGE_WITH_CONTEXT (MSG::WARNING,
97 "D3PD::CollectionGetterRegistryTool")
98 << "Can't find collection label " << label;
99 std::ostringstream os;
100 os << " Known collections:";
101 for (const auto& p : m_collection_map) {
102 os << " " << p.first;
103 }
104 REPORT_MESSAGE_WITH_CONTEXT (MSG::WARNING,
105 "D3PD::CollectionGetterRegistryTool")
106 << os.str();
107 return StatusCode::SUCCESS;
108 }
109
110 // Get the properties for the source tool.
111 const auto& props = m_jos->items([&i](const auto& p) {
112 return std::get<0>(p).starts_with( i->second->name()+".");
113 });
114
115 // Copy them to the destination tool (except for Label).
116 std::string fullname = parent->name() + "." + label;
117 for (const auto& p : props) {
118 const std::string& oldname = std::get<0>(p);
119 std::string::size_type ipos = oldname.rfind ('.');
120 if (ipos != std::string::npos) {
121 std::string pname = oldname.substr (ipos, std::string::npos);
122 if (pname != ".Label") {
123 m_jos->set(fullname + pname, std::get<1>(p));
124 }
125 }
126 }
127
128 // Create the new tool.
129 return m_toolsvc->retrieveTool (i->second->type(), label, tool, parent);
130}

◆ initialize()

StatusCode D3PD::CollectionGetterRegistryTool::initialize ( )
virtual

Standard Gaudi initialize method.

Definition at line 48 of file CollectionGetterRegistryTool.cxx.

49{
50 CHECK( AthAlgTool::initialize() );
51 CHECK( m_jos.retrieve() );
52 CHECK( m_toolsvc.retrieve() );
53 return StatusCode::SUCCESS;
54}
#define CHECK(...)
Evaluate an expression and check for errors.

Member Data Documentation

◆ m_collection_map

map_t D3PD::CollectionGetterRegistryTool::m_collection_map
private

Definition at line 96 of file CollectionGetterRegistryTool.h.

◆ m_jos

ServiceHandle<Gaudi::Interfaces::IOptionsSvc> D3PD::CollectionGetterRegistryTool::m_jos
private

Property: The job options service.

Definition at line 89 of file CollectionGetterRegistryTool.h.

◆ m_toolsvc

ServiceHandle<IToolSvc> D3PD::CollectionGetterRegistryTool::m_toolsvc
private

Property: The tool service.

Definition at line 92 of file CollectionGetterRegistryTool.h.


The documentation for this class was generated from the following files: