ATLAS Offline Software
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 
16 #include "GaudiKernel/IToolSvc.h"
17 #include <sstream>
18 
19 
20 namespace 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 
49 {
51  CHECK( m_jos.retrieve() );
52  CHECK( m_toolsvc.retrieve() );
53  return StatusCode::SUCCESS;
54 }
55 
56 
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 
89  const INamedInterface* parent,
91 {
92  // Loop up the tool in the map.
93  tool = 0;
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
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
D3PD::CollectionGetterRegistryTool::CollectionGetterRegistryTool
CollectionGetterRegistryTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: CollectionGetterRegistryTool.cxx:30
initialize
void initialize()
Definition: run_EoverP.cxx:894
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
ICollectionGetterTool.h
Abstract interface to get a collection of objects and iterate over it.
D3PD::CollectionGetterRegistryTool::m_jos
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jos
Property: The job options service.
Definition: CollectionGetterRegistryTool.h:89
D3PD::ICollectionGetterTool
Abstract interface to get a collection of objects and iterate over it.
Definition: ICollectionGetterTool.h:39
CollectionGetterRegistryTool.h
Tool to keep a registry of collection getter tools.
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
D3PD::CollectionGetterRegistryTool::m_collection_map
map_t m_collection_map
Definition: CollectionGetterRegistryTool.h:96
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
add-xsec-uncert-quadrature-N.label
label
Definition: add-xsec-uncert-quadrature-N.py:104
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
D3PD::CollectionGetterRegistryTool::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition: CollectionGetterRegistryTool.cxx:48
D3PD::CollectionGetterRegistryTool::add
virtual StatusCode add(const std::string &label, ICollectionGetterTool *tool)
Register a new collection getter tool.
Definition: CollectionGetterRegistryTool.cxx:62
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::CollectionGetterRegistryTool::m_toolsvc
ServiceHandle< IToolSvc > m_toolsvc
Property: The tool service.
Definition: CollectionGetterRegistryTool.h:92
createCoolChannelIdFile.oldname
oldname
Definition: createCoolChannelIdFile.py:105