ATLAS Offline Software
IndexMap.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
16 #include "GaudiKernel/ServiceHandle.h"
17 #include "GaudiKernel/IIncidentSvc.h"
18 
19 
20 namespace D3PD {
21 
22 
31 IndexMap::IndexMap (INamedInterface* parent,
32  const std::string& targetLabel,
33  ToolHandle<ICollectionGetterRegistryTool>& registry,
34  const bool& allowMissing)
35  : m_parent (parent),
36  m_targetLabel (&targetLabel),
37  m_targetLabels (0),
38  m_registry (&registry),
39  m_getters (0),
40  m_allowMissing (allowMissing),
41  m_valid (false)
42 {
43 }
44 
45 
58 IndexMap::IndexMap (INamedInterface* parent,
59  const std::string& targetLabel,
60  const std::vector<std::string>& targetLabels,
61  ToolHandle<ICollectionGetterRegistryTool>& registry,
62  const bool& allowMissing)
63  : m_parent (parent),
64  m_targetLabel (&targetLabel),
65  m_targetLabels (&targetLabels),
66  m_registry (&registry),
67  m_getters (0),
68  m_allowMissing (allowMissing),
69  m_valid (false)
70 {
71 }
72 
73 
80 IndexMap::IndexMap (INamedInterface* parent,
81  ToolHandleArray<ICollectionGetterTool>& getters,
82  const bool& allowMissing)
83  : m_parent (parent),
84  m_targetLabel (0),
85  m_targetLabels (0),
86  m_registry (0),
87  m_getters (&getters),
88  m_allowMissing (allowMissing),
89  m_valid (false)
90 {
91 }
92 
93 
98 {
99  ServiceHandle<IIncidentSvc> incSvc ("IncidentSvc", "IndexMap");
100  CHECK( incSvc.retrieve() );
101  incSvc->addListener (this, "EndEvent");
102 
103  if (m_registry) {
104  // Look up targets by label.
105  CHECK( m_registry->retrieve() );
106 
107  if (!m_targetLabel->empty()) {
109  CHECK( (*m_registry)->get (*m_targetLabel, m_parent, target) );
110  m_targets.push_back (target);
111  }
112  if (m_targetLabels) {
113  for (size_t i = 0; i < m_targetLabels->size(); i++) {
115  CHECK( (*m_registry)->get ((*m_targetLabels)[i], m_parent, target) );
116  m_targets.push_back (target);
117  }
118  }
119  }
120  else {
121  // Use direct list of getters.
122  CHECK( m_getters->retrieve() );
123  for (size_t i = 0; i < m_getters->size(); i++)
124  m_targets.push_back (&*(*m_getters)[i]);
125  }
126 
127  m_converters.resize (m_targets.size());
128  return StatusCode::SUCCESS;
129 }
130 
131 
138 {
139  CHECK( configureCommon() );
140 
141  // Configure the converters to expect the types of the
142  // target containers.
143  for (size_t i = 0; i < m_targets.size(); i++) {
144  if (m_targets[i])
145  CHECK( m_converters[i].init (m_targets[i]->elementTypeinfo(),
146  m_targets[i]->elementTypeinfo()) );
147  }
148  return StatusCode::SUCCESS;
149 }
150 
151 
159 StatusCode IndexMap::configureD3PD (const std::type_info& ti)
160 {
161  CHECK( configureCommon() );
162 
163  // Configure the converters.
164  for (size_t i = 0; i < m_targets.size(); i++) {
165  if (m_targets[i])
166  CHECK( m_converters[i].init (m_targets[i]->elementTypeinfo(), ti) );
167  }
168  return StatusCode::SUCCESS;
169 }
170 
171 
176 {
177  for (size_t i = 0; i < m_targets.size(); i++) {
178  if (m_targets[i])
179  return m_targets[i];
180  }
181  return 0;
182 }
183 
184 
189 {
190  if (i >= m_targets.size())
191  return 0;
192  return m_targets[i];
193 }
194 
195 
200 {
201  int n = 0;
202  for (size_t i = 0; i < m_targets.size(); i++) {
203  if (m_targets[i])
204  ++n;
205  }
206  return n;
207 }
208 
209 
214 void IndexMap::handle (const Incident &inc)
215 {
216  if (inc.type() == "EndEvent")
217  {
218  m_map.clear();
219  m_valid = false;
220  }
221 }
222 
223 
228 {
229  if (!m_valid) {
230  for (size_t i = 0; i < m_targets.size(); i++) {
232  if (target) {
234  int idx = 0;
235  while (const void* obj = target->nextUntyped() ) {
236  const void* cobj = m_converters[i].convertUntyped (obj);
237  if (cobj)
238  m_map.insert (std::make_pair (cobj, std::make_pair(idx++, (int)i)));
240  }
241  }
242  }
243  m_valid = true;
244  }
245  return StatusCode::SUCCESS;
246 }
247 
248 
255 int IndexMap::findIndex (const void* p)
256 {
257  return findIndexPair(p).first;
258 }
259 
260 
261 
270 int IndexMap::findIndex (const void* p, unsigned int i)
271 {
272  int ret = -1;
273  for (map_t::iterator it = m_map.find (p);
274  it != m_map.end() && it->first == p;
275  ++it)
276  {
277  if (it->second.second == static_cast<int>(i)) {
278  ret = it->second.first;
279  break;
280  }
281  }
282  return ret;
283 }
284 
285 
286 
293 std::pair<int,int> IndexMap::findIndexPair (const void* p)
294 {
295  map_t::iterator it = m_map.find (p);
296  std::pair<int, int> ret (-1, -1);
297  if (it == m_map.end())
298  return ret;
299 
300  // In case of multiple matches, return the first (smallest index)
301  // matching container.
302  ret = it->second;
303  for (++it; it != m_map.end() && it->first == p; ++it) {
304  if (it->second.second < ret.second)
305  ret = it->second;
306  }
307 
308  return ret;
309 }
310 
311 
312 
316 bool IndexMap::valid() const
317 {
318  return m_valid;
319 }
320 
321 
325 std::string IndexMap::formatLabels() const
326 {
327  std::string out = *m_targetLabel;
328  if (m_targetLabels) {
329  for (const std::string& l : *m_targetLabels) {
330  if (!out.empty())
331  out += ",";
332  out += l;
333  }
334  }
335  return out;
336 }
337 
338 
340 unsigned long IndexMap::addRef() { return 0; }
341 unsigned long IndexMap::release() { return 0; }
342 StatusCode IndexMap::queryInterface(const InterfaceID& /*riid*/,
343  void** /*ppvInterface*/)
344 { return StatusCode::FAILURE; }
345 
346 
347 
348 } // namespace D3PD
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
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
ICollectionGetterRegistryTool.h
Abstract interface to keep a registry of collection getter tools.
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
D3PD::IndexMap::findIndex
int findIndex(const void *p)
Find the index corresponding to an element.
Definition: IndexMap.cxx:255
D3PD::IndexMap::m_parent
INamedInterface * m_parent
The parent tool.
Definition: IndexMap.h:177
D3PD::IndexMap::m_map
map_t m_map
Definition: IndexMap.h:200
D3PD::IndexMap::findIndexPair
std::pair< int, int > findIndexPair(const void *p)
Find the (index,container) pair corresponding to an element.
Definition: IndexMap.cxx:293
skel.it
it
Definition: skel.GENtoEVGEN.py:423
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
ICollectionGetterTool.h
Abstract interface to get a collection of objects and iterate over it.
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
D3PD::IndexMap::reset
StatusCode reset()
Call before asking for an index. Rebuilds cache if needed.
Definition: IndexMap.cxx:227
D3PD::IndexMap::ntargets
int ntargets()
Return the number of valid targets.
Definition: IndexMap.cxx:199
D3PD::IndexMap::configureCommon
StatusCode configureCommon()
Common part of configuration.
Definition: IndexMap.cxx:97
D3PD::ICollectionGetterTool
Abstract interface to get a collection of objects and iterate over it.
Definition: ICollectionGetterTool.h:39
D3PD::IndexMap::valid
bool valid() const
Return the valid flag.
Definition: IndexMap.cxx:316
D3PD::IndexMap::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Definition: IndexMap.cxx:342
D3PD
Block filler tool for noisy FEB information.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:21
lumiFormat.i
int i
Definition: lumiFormat.py:92
D3PD::IndexMap::release
virtual unsigned long release()
Definition: IndexMap.cxx:341
ret
T ret(T t)
Definition: rootspy.cxx:260
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
D3PD::IndexMap::IndexMap
IndexMap(INamedInterface *parent, const std::string &targetLabel, ToolHandle< ICollectionGetterRegistryTool > &registry, const bool &allowMissing)
Constructor: for a single target.
Definition: IndexMap.cxx:31
test_pyathena.parent
parent
Definition: test_pyathena.py:15
D3PD::IndexMap::m_getters
ToolHandleArray< ICollectionGetterTool > * m_getters
Property for a direct list of getters.
Definition: IndexMap.h:190
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
D3PD::IndexMap::m_targetLabels
const std::vector< std::string > * m_targetLabels
Property for the label of the getter defining the list of target collections.
Definition: IndexMap.h:184
D3PD::IndexMap::m_targets
std::vector< ICollectionGetterTool * > m_targets
Getters defining the collections within which to index.
Definition: IndexMap.h:196
D3PD::IndexMap::configureD3PD
StatusCode configureD3PD()
Configure during initialization: type-check.
Definition: IndexMap.cxx:137
D3PD::IObjGetterTool::releaseObjectUntyped
virtual void releaseObjectUntyped(const void *p)
Release an object retrieved from the getter.
D3PD::ICollectionGetterTool::reset
virtual StatusCode reset(bool allowMissing=false)=0
Reset the iteration to the start of the collection.
errorcheck.h
Helpers for checking error return status codes and reporting errors.
IndexMap.h
Cache pointer -> index mappings for a Getter used for index assocs.
python.PyKernel.init
def init(v_theApp, v_rootStream=None)
Definition: PyKernel.py:45
D3PD::IndexMap::m_allowMissing
const bool & m_allowMissing
Property for the allowMissing flag.
Definition: IndexMap.h:193
D3PD::IndexMap::m_valid
bool m_valid
Flag if the map is valid.
Definition: IndexMap.h:203
D3PD::IndexMap::addRef
virtual unsigned long addRef()
Dummies needed to satisfy IInterface requirements.
Definition: IndexMap.cxx:340
D3PD::IndexMap::m_targetLabel
const std::string * m_targetLabel
Property for the label of the getter defining the target collection.
Definition: IndexMap.h:180
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
D3PD::IndexMap::m_converters
std::vector< TypeConverter > m_converters
Converter for each target.
Definition: IndexMap.h:206
D3PD::IIteration::nextUntyped
virtual const void * nextUntyped()=0
Return a pointer to the next element in the iteration.
python.PyAthena.obj
obj
Definition: PyAthena.py:135
D3PD::IndexMap::handle
virtual void handle(const Incident &inc)
Incident handler.
Definition: IndexMap.cxx:214
D3PD::IndexMap::m_registry
ToolHandle< ICollectionGetterRegistryTool > * m_registry
Property for the ICollectionGetterRegistryTool instance.
Definition: IndexMap.h:187
ServiceHandle< IIncidentSvc >