ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDMaker
D3PDMakerCoreComps
src
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
13
#include "
CollectionGetterRegistryTool.h
"
14
#include "
D3PDMakerInterfaces/ICollectionGetterTool.h
"
15
#include "
AthenaKernel/errorcheck.h
"
16
#include "GaudiKernel/IToolSvc.h"
17
#include <sstream>
18
19
20
namespace
D3PD
{
21
22
29
CollectionGetterRegistryTool::CollectionGetterRegistryTool
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
47
StatusCode
48
CollectionGetterRegistryTool::initialize
()
49
{
50
CHECK
( AthAlgTool::initialize() );
51
CHECK
(
m_jos
.retrieve() );
52
CHECK
(
m_toolsvc
.retrieve() );
53
return
StatusCode::SUCCESS;
54
}
55
56
62
StatusCode
CollectionGetterRegistryTool::add
(
const
std::string&
label
,
63
ICollectionGetterTool
* tool)
64
{
65
std::pair<map_t::iterator, bool>
res
=
66
m_collection_map
.insert (std::make_pair (
label
, tool));
67
if
(!
res
.second) {
68
REPORT_MESSAGE_WITH_CONTEXT
(MSG::ERROR,
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
87
StatusCode
88
CollectionGetterRegistryTool::get
(
const
std::string&
label
,
89
const
INamedInterface* parent,
90
ICollectionGetterTool
*& tool)
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
CollectionGetterRegistryTool.h
Tool to keep a registry of collection getter tools.
errorcheck.h
Helpers for checking error return status codes and reporting errors.
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:345
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
ICollectionGetterTool.h
Abstract interface to get a collection of objects and iterate over it.
res
std::pair< std::vector< unsigned int >, bool > res
Definition
JetGroupProductTest.cxx:11
D3PD::CollectionGetterRegistryTool::add
virtual StatusCode add(const std::string &label, ICollectionGetterTool *tool)
Register a new collection getter tool.
Definition
CollectionGetterRegistryTool.cxx:62
D3PD::CollectionGetterRegistryTool::m_jos
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jos
Property: The job options service.
Definition
CollectionGetterRegistryTool.h:89
D3PD::CollectionGetterRegistryTool::m_collection_map
map_t m_collection_map
Definition
CollectionGetterRegistryTool.h:96
D3PD::CollectionGetterRegistryTool::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition
CollectionGetterRegistryTool.cxx:48
D3PD::CollectionGetterRegistryTool::CollectionGetterRegistryTool
CollectionGetterRegistryTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition
CollectionGetterRegistryTool.cxx:30
D3PD::CollectionGetterRegistryTool::get
virtual StatusCode get(const std::string &label, const INamedInterface *parent, ICollectionGetterTool *&tool)
Get a copy of a registered collection getter tool.
Definition
CollectionGetterRegistryTool.cxx:88
D3PD::CollectionGetterRegistryTool::m_toolsvc
ServiceHandle< IToolSvc > m_toolsvc
Property: The tool service.
Definition
CollectionGetterRegistryTool.h:92
D3PD::ICollectionGetterTool
Abstract interface to get a collection of objects and iterate over it.
Definition
ICollectionGetterTool.h:39
label
std::string label(const std::string &format, int i)
Definition
label.h:19
D3PD
Block filler tool for noisy FEB information.
Definition
CaloCellDetailsFillerTool.cxx:29
type
Generated on
for ATLAS Offline Software by
1.17.0