ATLAS Offline Software
Loading...
Searching...
No Matches
IndexFillerTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: IndexFillerTool.cxx 491462 2012-03-28 23:35:19Z ssnyder $
12
13
14#include "IndexFillerTool.h"
18#include <sstream>
19
20
21namespace D3PD {
22
23
31 const std::string& name,
32 const IInterface* parent)
33 : BlockFillerToolImpl (type, name, parent),
34 m_index (0),
37{
38 declareProperty ("Target", m_targetLabel,
39 "Label of the collection getter defining the collection "
40 "within which to index.");
41 declareProperty ("Targets", m_targetLabels,
42 "List of labels of collection getters defining the "
43 "collections within which to index. "
44 "If Target is non-empty, it is considered to come "
45 "at the start of this list.");
46 declareProperty ("ContainerIndexName", m_containerIndexName,
47 "Variable name to use for the index of the container "
48 "in which the object was found. Useful if more than "
49 "one target container is specified. Omitted if this "
50 "is empty.");
51 declareProperty ("CollectionGetterRegistry", m_registry,
52 "The ICollectionGetterRegistryTool instance.");
53 declareProperty ("AllowMissing", m_allowMissing = false,
54 "If true, then it is not considered an error for the "
55 "target getter to fail to find the input objects.");
56}
57
58
63{
64 // Be sure the registry is retrieved, to avoid warnings from Gaudi
65 // that the tool is unused.
66 ATH_CHECK( m_registry.retrieve() );
67 return StatusCode::SUCCESS;
68}
69
70
79StatusCode
81 const std::type_info& ti)
82{
83 CHECK( m_map.configureD3PD (ti) );
84 if (m_map.target()) {
85 CHECK( configureImpl (tree, ti, m_map.target()->elementTypeinfo()) );
86 }
87 else {
88 REPORT_MESSAGE (MSG::WARNING)
89 << "Not booking index variable because no association targets exist: "
90 << m_map.formatLabels();
91 }
92
93 return StatusCode::SUCCESS;
94}
95
96
103{
104 if (m_map.target()) {
105 std::string indexdoc = "Index in ";
106 std::string contdoc = "Container index: ";
107 int n = 0;
108 if (!m_targetLabel.empty()) {
109 indexdoc += m_targetLabel;
110 contdoc += "0 - " + m_targetLabel;
111 ++n;
112 }
113 for (size_t i = 0; i < m_targetLabels.size(); i++) {
114 if (n > 0) {
115 indexdoc += ", ";
116 contdoc += ", ";
117 }
118 indexdoc += m_targetLabels[i];
119 std::ostringstream s;
120 s << n << " - " << m_targetLabels[i];
121 contdoc += s.str();
122 ++n;
123 }
124
125 CHECK( addVariable ("index", m_index, indexdoc, -1) );
126
127 if (!m_containerIndexName.empty())
129 }
130
131 return StatusCode::SUCCESS;
132}
133
134
161StatusCode
163 bool /*again = false*/)
164{
165 if (m_index) {
166 // Build the map if it doesn't exist.
167 CHECK( m_map.reset() );
168
169 // Search the index container for the pointer.
170 std::pair<int, int> out = m_map.findIndexPair (p);
171 *m_index = out.first;
173 *m_containerIndex = out.second;
174 }
175
176 return StatusCode::SUCCESS;
177}
178
179
180
181} // namespace D3PD
182
183
#define ATH_CHECK
Evaluate an expression and check for errors.
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
Abstract interface to keep a registry of collection getter tools.
Abstract interface to get a collection of objects and iterate over it.
Fill an index of an object within a container.
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
Add a variable to the tuple.
StatusCode configureImpl(IAddVariable *tree, const std::type_info &ti, const std::type_info &fill_ti)
Configure during initialization: type-check.
BlockFillerToolImpl(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Common interface for adding a variable to a tuple.
std::string m_containerIndexName
Variable name to use for the index of the container in which the object was found.
std::string m_targetLabel
Property: The label of the collection getter defining the collection within which to index.
virtual StatusCode initialize() override
Standard Gaudi initialize method.
virtual StatusCode configureD3PD(IAddVariable *tree, const std::type_info &ti) override
Configure during initialization: type-check.
bool m_allowMissing
Property: Don't give an error if the target getter fails to find the input objects.
IndexMap m_map
Map from objects to indices.
int * m_index
Index variable.
ToolHandle< ICollectionGetterRegistryTool > m_registry
Property: The ICollectionGetterRegistryTool instance.
virtual StatusCode fillUntyped(const void *p, bool again=false) override
Fill one block.
std::vector< std::string > m_targetLabels
Property: The list of labels of collection getters defining the collections within which to index.
IndexFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
int * m_containerIndex
Container index variable.
virtual StatusCode book() override
Declare tuple variables.
Block filler tool for noisy FEB information.
TChain * tree