ATLAS Offline Software
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 $
14 #include "IndexFillerTool.h"
18 #include <sstream>
19 
20 
21 namespace D3PD {
22 
23 
31  const std::string& name,
32  const IInterface* parent)
34  m_index (0),
35  m_containerIndex (0),
36  m_map (this, m_targetLabel, m_targetLabels, m_registry, m_allowMissing)
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 
81  const std::type_info& ti)
82 {
83  CHECK( m_map.configureD3PD (ti) );
84  if (m_map.target()) {
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 
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;
172  if (m_containerIndex)
173  *m_containerIndex = out.second;
174  }
175 
176  return StatusCode::SUCCESS;
177 }
178 
179 
180 
181 } // namespace D3PD
182 
183 
D3PD::IndexMap::target
ICollectionGetterTool * target()
Return the getter defining the first collection within which to index.
Definition: IndexMap.cxx:175
D3PD::IndexMap::formatLabels
std::string formatLabels() const
Return list of all configured targets as a comma-separated string.
Definition: IndexMap.cxx:325
D3PD::IAddVariable
Common interface for adding a variable to a tuple.
Definition: IAddVariable.h:70
ICollectionGetterRegistryTool.h
Abstract interface to keep a registry of collection getter tools.
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
D3PD::IIteration::elementTypeinfo
virtual const std::type_info & elementTypeinfo() const =0
Return the element type of the collection.
D3PD::IndexFillerTool::m_targetLabels
std::vector< std::string > m_targetLabels
Property: The list of labels of collection getters defining the collections within which to index.
Definition: IndexFillerTool.h:107
D3PD::IndexFillerTool::m_map
IndexMap m_map
Map from objects to indices.
Definition: IndexFillerTool.h:128
D3PD::IndexFillerTool::m_containerIndexName
std::string m_containerIndexName
Variable name to use for the index of the container in which the object was found.
Definition: IndexFillerTool.h:112
D3PD::IndexMap::findIndexPair
std::pair< int, int > findIndexPair(const void *p)
Find the (index,container) pair corresponding to an element.
Definition: IndexMap.cxx:293
tree
TChain * tree
Definition: tile_monitor.h:30
D3PD::IndexFillerTool::book
virtual StatusCode book() override
Declare tuple variables.
Definition: IndexFillerTool.cxx:102
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
ICollectionGetterTool.h
Abstract interface to get a collection of objects and iterate over it.
D3PD::IndexFillerTool::configureD3PD
virtual StatusCode configureD3PD(IAddVariable *tree, const std::type_info &ti) override
Configure during initialization: type-check.
Definition: IndexFillerTool.cxx:80
D3PD::IndexMap::reset
StatusCode reset()
Call before asking for an index. Rebuilds cache if needed.
Definition: IndexMap.cxx:227
D3PD::AddVariable::addVariable
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.
Definition: AddVariable.cxx:85
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
D3PD::IndexMap::configureD3PD
StatusCode configureD3PD()
Configure during initialization: type-check.
Definition: IndexMap.cxx:137
D3PD::IndexFillerTool::initialize
virtual StatusCode initialize() override
Standard Gaudi initialize method.
Definition: IndexFillerTool.cxx:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
D3PD::IndexFillerTool::m_registry
ToolHandle< ICollectionGetterRegistryTool > m_registry
Property: The ICollectionGetterRegistryTool instance.
Definition: IndexFillerTool.h:115
errorcheck.h
Helpers for checking error return status codes and reporting errors.
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
D3PD::IndexFillerTool::fillUntyped
virtual StatusCode fillUntyped(const void *p, bool again=false) override
Fill one block.
Definition: IndexFillerTool.cxx:162
D3PD::IndexFillerTool::IndexFillerTool
IndexFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: IndexFillerTool.cxx:30
D3PD::IndexFillerTool::m_index
int * m_index
Index variable.
Definition: IndexFillerTool.h:122
D3PD::IndexFillerTool::m_targetLabel
std::string m_targetLabel
Property: The label of the collection getter defining the collection within which to index.
Definition: IndexFillerTool.h:102
IndexFillerTool.h
Fill an index of an object within a container.
D3PD::BlockFillerToolImpl
Non-template parts of BlockFillerTool.
Definition: BlockFillerToolImpl.h:44
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::IndexFillerTool::m_allowMissing
bool m_allowMissing
Property: Don't give an error if the target getter fails to find the input objects.
Definition: IndexFillerTool.h:119
D3PD::IndexFillerTool::m_containerIndex
int * m_containerIndex
Container index variable.
Definition: IndexFillerTool.h:125
D3PD::BlockFillerToolImpl::configureImpl
StatusCode configureImpl(IAddVariable *tree, const std::type_info &ti, const std::type_info &fill_ti)
Configure during initialization: type-check.
Definition: BlockFillerToolImpl.cxx:55