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 "CxxUtils/starts_with.h"
18 #include <sstream>
19 
20 
21 namespace D3PD {
22 
23 
31  (const std::string& type,
32  const std::string& name,
33  const IInterface* parent)
34  : base_class (type, name, parent),
35  m_jos ("JobOptionsSvc", name),
36  m_toolsvc ("ToolSvc", name)
37 {
38  declareProperty ("JobOptionsSvc", m_jos,
39  "The JobOptionsSvc instance.");
40  declareProperty ("ToolSvc", m_toolsvc,
41  "The ToolSvc instance.");
42 }
43 
44 
50 {
52  CHECK( m_jos.retrieve() );
53  CHECK( m_toolsvc.retrieve() );
54  return StatusCode::SUCCESS;
55 }
56 
57 
65 {
66  std::pair<map_t::iterator, bool> res =
67  m_collection_map.insert (std::make_pair (label, tool));
68  if (!res.second) {
69  REPORT_MESSAGE_WITH_CONTEXT (MSG::ERROR,
70  "D3PD::CollectionGetterRegistryTool")
71  << "Duplicate collection label " << label
72  << " for tools " << res.first->second->name()
73  << " and " << tool->name();
74  return StatusCode::FAILURE;
75  }
76  return StatusCode::SUCCESS;
77 }
78 
79 
90  const INamedInterface* parent,
92 {
93  // Loop up the tool in the map.
94  tool = 0;
96  if (i == m_collection_map.end()) {
97  REPORT_MESSAGE_WITH_CONTEXT (MSG::WARNING,
98  "D3PD::CollectionGetterRegistryTool")
99  << "Can't find collection label " << label;
100  std::ostringstream os;
101  os << " Known collections:";
102  for (const auto& p : m_collection_map) {
103  os << " " << p.first;
104  }
105  REPORT_MESSAGE_WITH_CONTEXT (MSG::WARNING,
106  "D3PD::CollectionGetterRegistryTool")
107  << os.str();
108  return StatusCode::SUCCESS;
109  }
110 
111  // Get the properties for the source tool.
112  const auto& props = m_jos->items([&i](const auto& p) {
113  return CxxUtils::starts_with(std::get<0>(p), i->second->name()+".");
114  });
115 
116  // Copy them to the destination tool (except for Label).
117  std::string fullname = parent->name() + "." + label;
118  for (const auto& p : props) {
119  const std::string& oldname = std::get<0>(p);
120  std::string::size_type ipos = oldname.rfind ('.');
121  if (ipos != std::string::npos) {
122  std::string pname = oldname.substr (ipos, std::string::npos);
123  if (pname != ".Label") {
124  m_jos->set(fullname + pname, std::get<1>(p));
125  }
126  }
127  }
128 
129  // Create the new tool.
130  return m_toolsvc->retrieveTool (i->second->type(), label, tool, parent);
131 }
132 
133 
134 } // namespace D3PD
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CxxUtils::starts_with
bool starts_with(const char *s, const char *prefix)
Test whether one null-terminated byte string starts with another.
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
D3PD::CollectionGetterRegistryTool::CollectionGetterRegistryTool
CollectionGetterRegistryTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: CollectionGetterRegistryTool.cxx:31
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
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:89
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: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:21
D3PD::CollectionGetterRegistryTool::m_collection_map
map_t m_collection_map
Definition: CollectionGetterRegistryTool.h:96
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
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
starts_with.h
C++20-like starts_with/ends_with for strings.
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:195
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:49
D3PD::CollectionGetterRegistryTool::add
virtual StatusCode add(const std::string &label, ICollectionGetterTool *tool)
Register a new collection getter tool.
Definition: CollectionGetterRegistryTool.cxx:63
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
D3PD::CollectionGetterRegistryTool::m_toolsvc
ServiceHandle< IToolSvc > m_toolsvc
Property: The tool service.
Definition: CollectionGetterRegistryTool.h:92
createCoolChannelIdFile.oldname
oldname
Definition: createCoolChannelIdFile.py:105