ATLAS Offline Software
Public Member Functions | Private Types | Private Attributes | List of all members
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. More...
 
virtual StatusCode initialize ()
 Standard Gaudi initialize method. More...
 
virtual StatusCode add (const std::string &label, ICollectionGetterTool *tool)
 Register a new collection getter tool. More...
 
virtual StatusCode get (const std::string &label, const INamedInterface *parent, ICollectionGetterTool *&tool)
 Get a copy of a registered collection getter tool. More...
 

Private Types

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

Private Attributes

ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jos
 Property: The job options service. More...
 
ServiceHandle< IToolSvc > m_toolsvc
 Property: The tool service. More...
 
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 30 of file CollectionGetterRegistryTool.cxx.

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 }

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 63 of file CollectionGetterRegistryTool.cxx.

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 }

◆ 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 89 of file CollectionGetterRegistryTool.cxx.

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 }

◆ initialize()

StatusCode D3PD::CollectionGetterRegistryTool::initialize ( )
virtual

Standard Gaudi initialize method.

Definition at line 49 of file CollectionGetterRegistryTool.cxx.

50 {
52  CHECK( m_jos.retrieve() );
53  CHECK( m_toolsvc.retrieve() );
54  return StatusCode::SUCCESS;
55 }

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:
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
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
initialize
void initialize()
Definition: run_EoverP.cxx:894
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
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
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
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
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