ATLAS Offline Software
Loading...
Searching...
No Matches
CollectionGetterRegistryTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12
16#include "GaudiKernel/IToolSvc.h"
17#include <sstream>
18
19
20namespace D3PD {
21
22
30 (const std::string& type,
31 const std::string& name,
32 const IInterface* parent)
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}
42
43
47StatusCode
49{
50 CHECK( AthAlgTool::initialize() );
51 CHECK( m_jos.retrieve() );
52 CHECK( m_toolsvc.retrieve() );
53 return StatusCode::SUCCESS;
54}
55
56
62StatusCode CollectionGetterRegistryTool::add (const std::string& label,
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}
77
78
87StatusCode
89 const INamedInterface* parent,
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}
131
132
133} // namespace D3PD
Tool to keep a registry of collection getter tools.
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
#define CHECK(...)
Evaluate an expression and check for errors.
Abstract interface to get a collection of objects and iterate over it.
std::pair< std::vector< unsigned int >, bool > res
virtual StatusCode add(const std::string &label, ICollectionGetterTool *tool)
Register a new collection getter tool.
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jos
Property: The job options service.
virtual StatusCode initialize()
Standard Gaudi initialize method.
CollectionGetterRegistryTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
virtual StatusCode get(const std::string &label, const INamedInterface *parent, ICollectionGetterTool *&tool)
Get a copy of a registered collection getter tool.
ServiceHandle< IToolSvc > m_toolsvc
Property: The tool service.
Abstract interface to get a collection of objects and iterate over it.
std::string label(const std::string &format, int i)
Definition label.h:19
Block filler tool for noisy FEB information.