ATLAS Offline Software
Loading...
Searching...
No Matches
IndexAssociationFillerTool.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: IndexAssociationFillerTool.cxx 618070 2014-09-22 19:05:34Z ssnyder $
12
13
17
18
19namespace D3PD {
20
21
29 (const std::string& type,
30 const std::string& name,
31 const IInterface* parent)
32 : base_class (type, name, parent),
34 m_associator (this),
35 m_index (0),
37{
38 declareProperty ("Associator", m_associator,
39 "The ISingleAssociationTool instance.");
40 declareProperty ("Target", m_targetLabel,
41 "Label of the collection getter defining the collection "
42 "within which to index.");
43 declareProperty ("Prefix", m_prefix,
44 "Variable name prefix for the index variable.");
45 declareProperty ("BlockName", m_blockName = this->name(),
46 "The name of this block.");
47 declareProperty ("CollectionGetterRegistry", m_registry,
48 "The ICollectionGetterRegistryTool instance.");
49 declareProperty ("AllowMissing", m_allowMissing = false,
50 "If true, then it is not considered an error for the "
51 "target getter to fail to find the input objects.");
52}
53
54
58StatusCode
60{
61 REPORT_MESSAGE(MSG::WARNING)
62 << "IndexAssociationFillerTool is deprecated; use instead "
63 << "ContainedAssociationFillerTool with IndexFillerTool. "
64 << "IndexAssociation.py should do that for you.";
65
66 CHECK( AthAlgTool::initialize() );
67 CHECK( m_associator.retrieve() );
68
69 // Be sure the registry is retrieved, to avoid warnings from Gaudi
70 // that the tool is unused.
71 CHECK( m_registry.retrieve() );
72 return StatusCode::SUCCESS;
73}
74
75
84StatusCode
86 const std::type_info& ti)
87{
89 CHECK( m_associator->configureD3PD (this, ti) );
90 CHECK( m_map.configureD3PD() );
91
92 if (m_map.target()) {
93 CHECK( m_converter.init (m_associator->typeinfo(),
94 m_map.target()->elementTypeinfo()) );
95 }
96 else {
97 REPORT_MESSAGE_WITH_CONTEXT (MSG::WARNING,
98 "D3PD::IndexAssociationFillerTool")
99 << "Not booking index variable because association target does not exist.";
100 }
101
102 return StatusCode::SUCCESS;
103}
104
105
112{
113 CHECK( m_associator->book () );
114 if (m_map.target())
115 CHECK( addVariable ("index", m_index) );
116 else
117 m_index = 0;
118
119 return StatusCode::SUCCESS;
120}
121
122
149StatusCode
151 bool /*again = false*/)
152{
153 // Build the map if it doesn't exist.
154 CHECK( m_map.reset() );
155
156 // Default index value.
157 if (m_index)
158 *m_index = -1;
159
160 // Do the association.
161 const void* pout = m_associator->getUntyped (p);
162 if (pout) {
163
164 if (m_index) {
165 // Convert to the proper pointer type to search in the container.
166 const void* pnew = m_converter.convertUntyped (pout);
167 if (!pnew) {
168 REPORT_MESSAGE (MSG::WARNING)
169 << "Pointer conversion from " << m_converter.srcName() << " to "
170 << m_converter.dstName() << "failed.";
171 }
172 else {
173 // Search the index container for the pointer.
174 *m_index = m_map.findIndex (pnew);
175 }
176 }
177
178 m_associator->releaseObjectUntyped (pout);
179 }
180
181 return StatusCode::SUCCESS;
182}
183
184
185
186} // namespace D3PD
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
#define CHECK(...)
Evaluate an expression and check for errors.
Abstract interface to get a collection of objects and iterate over it.
Represent a single association by index.
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 configureD3PD(IAddVariable *tree)
Configure the parent tree.
AddVariable(const std::string &prefix, const std::string &blockName=s_emptyString)
Constructor.
Common interface for adding a variable to a tuple.
std::string m_blockName
Property: the name of this block.
TypeConverter m_converter
Helper to convert from pointer returned by the associator to pointer into the index container.
virtual StatusCode book() override
Declare tuple variables.
std::string m_prefix
Property: The variable name prefix.
ToolHandle< ISingleAssociationTool > m_associator
Property: The association tool instance.
bool m_allowMissing
Property: Don't give an error if the target getter fails to find the input objects.
virtual StatusCode fillUntyped(const void *p, bool again=false) override
Fill one block.
virtual StatusCode initialize() override
Standard Gaudi initialize method.
std::string m_targetLabel
Property: The label of the collection getter defining the collection within which to index.
IndexMap m_map
Map from objects to indices.
virtual StatusCode configureD3PD(IAddVariable *tree, const std::type_info &ti) override
Configure during initialization: type-check.
ToolHandle< ICollectionGetterRegistryTool > m_registry
Property: The ICollectionGetterRegistryTool instance.
IndexAssociationFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Block filler tool for noisy FEB information.
TChain * tree