ATLAS Offline Software
Loading...
Searching...
No Matches
D3PD::IndexMap Class Reference

#include <IndexMap.h>

Inheritance diagram for D3PD::IndexMap:
Collaboration diagram for D3PD::IndexMap:

Public Member Functions

 IndexMap (INamedInterface *parent, const std::string &targetLabel, ToolHandle< ICollectionGetterRegistryTool > &registry, const bool &allowMissing)
 Constructor: for a single target.
 IndexMap (INamedInterface *parent, const std::string &targetLabel, const std::vector< std::string > &targetLabels, ToolHandle< ICollectionGetterRegistryTool > &registry, const bool &allowMissing)
 Constructor: for multiple targets.
 IndexMap (INamedInterface *parent, ToolHandleArray< ICollectionGetterTool > &getters, const bool &allowMissing)
 Constructor: passing the list of getters directly.
StatusCode configureD3PD ()
 Configure during initialization: type-check.
StatusCode configureD3PD (const std::type_info &ti)
 Configure during initialization: type-check.
ICollectionGetterTooltarget ()
 Return the getter defining the first collection within which to index.
ICollectionGetterTooltarget (unsigned int i)
 Return the getter defining the i'th collection within which to index.
int ntargets ()
 Return the number of valid targets.
virtual void handle (const Incident &inc)
 Incident handler.
StatusCode reset ()
 Call before asking for an index. Rebuilds cache if needed.
int findIndex (const void *p)
 Find the index corresponding to an element.
int findIndex (const void *p, unsigned int i)
 Find the index corresponding to an element within a specific container.
std::pair< int, int > findIndexPair (const void *p)
 Find the (index,container) pair corresponding to an element.
bool valid () const
 Return the valid flag.
std::string formatLabels () const
 Return list of all configured targets as a comma-separated string.

Private Types

typedef std::unordered_multimap< const void *, std::pair< int, int > > map_t
 The pointer -> (index,target) map.

Private Member Functions

StatusCode configureCommon ()
 Common part of configuration.

Private Attributes

INamedInterface * m_parent
 The parent tool.
const std::string * m_targetLabel
 Property for the label of the getter defining the target collection.
const std::vector< std::string > * m_targetLabels
 Property for the label of the getter defining the list of target collections.
ToolHandle< ICollectionGetterRegistryTool > * m_registry
 Property for the ICollectionGetterRegistryTool instance.
ToolHandleArray< ICollectionGetterTool > * m_getters
 Property for a direct list of getters.
const bool & m_allowMissing
 Property for the allowMissing flag.
std::vector< ICollectionGetterTool * > m_targets
 Getters defining the collections within which to index.
map_t m_map
bool m_valid
 Flag if the map is valid.
std::vector< TypeConverterm_converters
 Converter for each target.

Detailed Description

Definition at line 42 of file IndexMap.h.

Member Typedef Documentation

◆ map_t

typedef std::unordered_multimap<const void*, std::pair<int, int> > D3PD::IndexMap::map_t
private

The pointer -> (index,target) map.

Definition at line 190 of file IndexMap.h.

Constructor & Destructor Documentation

◆ IndexMap() [1/3]

D3PD::IndexMap::IndexMap ( INamedInterface * parent,
const std::string & targetLabel,
ToolHandle< ICollectionGetterRegistryTool > & registry,
const bool & allowMissing )

Constructor: for a single target.

Parameters
parentThe parent tool.
targetLabelProperty for the label of the getter defining the target collection.
registryProperty for the ICollectionGetterRegistryTool instance.
allowMissingProperty for the allowMissing flag.

Definition at line 31 of file IndexMap.cxx.

35 : m_parent (parent),
36 m_targetLabel (&targetLabel),
38 m_registry (&registry),
39 m_getters (0),
40 m_allowMissing (allowMissing),
41 m_valid (false)
42{
43}
ToolHandleArray< ICollectionGetterTool > * m_getters
Property for a direct list of getters.
Definition IndexMap.h:181
const bool & m_allowMissing
Property for the allowMissing flag.
Definition IndexMap.h:184
const std::string * m_targetLabel
Property for the label of the getter defining the target collection.
Definition IndexMap.h:171
bool m_valid
Flag if the map is valid.
Definition IndexMap.h:194
INamedInterface * m_parent
The parent tool.
Definition IndexMap.h:168
ToolHandle< ICollectionGetterRegistryTool > * m_registry
Property for the ICollectionGetterRegistryTool instance.
Definition IndexMap.h:178
const std::vector< std::string > * m_targetLabels
Property for the label of the getter defining the list of target collections.
Definition IndexMap.h:175

◆ IndexMap() [2/3]

D3PD::IndexMap::IndexMap ( INamedInterface * parent,
const std::string & targetLabel,
const std::vector< std::string > & targetLabels,
ToolHandle< ICollectionGetterRegistryTool > & registry,
const bool & allowMissing )

Constructor: for multiple targets.

Constructor.

Parameters
parentThe parent tool.
targetLabelProperty for the label of the getter defining the target collection. If non-empty, this will be considered to be at the start of targetLabels.
targetLabelsProperty for the label of the getter defining the target collection.
registryProperty for the ICollectionGetterRegistryTool instance.
allowMissingProperty for the allowMissing flag.

Constructor: for multiple targets.

Parameters
targetLabelProperty for the label of the getter defining the target collection. If non-empty, this will be considered to be at the start of targetLabels.
targetLabelsProperty for the label of the getter defining the target collection.
registryProperty for the ICollectionGetterRegistryTool instance.
allowMissingProperty for the allowMissing flag.

Definition at line 58 of file IndexMap.cxx.

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}

◆ IndexMap() [3/3]

D3PD::IndexMap::IndexMap ( INamedInterface * parent,
ToolHandleArray< ICollectionGetterTool > & getters,
const bool & allowMissing )

Constructor: passing the list of getters directly.

Parameters
parentThe parent tool.
gettersProperty for the list of getters.
allowMissingProperty for the allowMissing flag.

Definition at line 80 of file IndexMap.cxx.

83 : m_parent (parent),
84 m_targetLabel (0),
86 m_registry (0),
87 m_getters (&getters),
88 m_allowMissing (allowMissing),
89 m_valid (false)
90{
91}

Member Function Documentation

◆ configureCommon()

StatusCode D3PD::IndexMap::configureCommon ( )
private

Common part of configuration.

Definition at line 97 of file IndexMap.cxx.

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()) {
108 ICollectionGetterTool* target = 0;
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++) {
114 ICollectionGetterTool* target = 0;
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}
#define CHECK(...)
Evaluate an expression and check for errors.
std::vector< ICollectionGetterTool * > m_targets
Getters defining the collections within which to index.
Definition IndexMap.h:187
std::vector< TypeConverter > m_converters
Converter for each target.
Definition IndexMap.h:197
ICollectionGetterTool * target()
Return the getter defining the first collection within which to index.
Definition IndexMap.cxx:175

◆ configureD3PD() [1/2]

StatusCode D3PD::IndexMap::configureD3PD ( )

Configure during initialization: type-check.

If this is used, the pointer type passed in should match that of the target container(s).

Definition at line 137 of file IndexMap.cxx.

138{
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}
StatusCode configureCommon()
Common part of configuration.
Definition IndexMap.cxx:97

◆ configureD3PD() [2/2]

StatusCode D3PD::IndexMap::configureD3PD ( const std::type_info & ti)

Configure during initialization: type-check.

Parameters
Thepointer type that will be passed into the find methods.
Thepointer type that will be passed into the find methods.

If this is used, the pointer type passed in should match that of the target container(s).

Definition at line 159 of file IndexMap.cxx.

160{
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}

◆ findIndex() [1/2]

int D3PD::IndexMap::findIndex ( const void * p)

Find the index corresponding to an element.

Parameters
pThe pointer to find.

Returns -1 if the pointer isn't found.

Definition at line 255 of file IndexMap.cxx.

256{
257 return findIndexPair(p).first;
258}
std::pair< int, int > findIndexPair(const void *p)
Find the (index,container) pair corresponding to an element.
Definition IndexMap.cxx:293

◆ findIndex() [2/2]

int D3PD::IndexMap::findIndex ( const void * p,
unsigned int i )

Find the index corresponding to an element within a specific container.

Parameters
pThe pointer to find.
iThe index of the target in which to search.

Returns -1 if the pointer isn't found.

Definition at line 270 of file IndexMap.cxx.

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}

◆ findIndexPair()

std::pair< int, int > D3PD::IndexMap::findIndexPair ( const void * p)

Find the (index,container) pair corresponding to an element.

Parameters
pThe pointer to find.

Returns (-1,-1) if the pointer isn't found.

Definition at line 293 of file IndexMap.cxx.

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}

◆ formatLabels()

std::string D3PD::IndexMap::formatLabels ( ) const

Return list of all configured targets as a comma-separated string.

Definition at line 325 of file IndexMap.cxx.

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}
l
Printing final latex table to .tex output file.

◆ handle()

void D3PD::IndexMap::handle ( const Incident & inc)
virtual

Incident handler.

Parameters
incThe incident.

Definition at line 214 of file IndexMap.cxx.

215{
216 if (inc.type() == "EndEvent")
217 {
218 m_map.clear();
219 m_valid = false;
220 }
221}

◆ ntargets()

int D3PD::IndexMap::ntargets ( )

Return the number of valid targets.

Definition at line 199 of file IndexMap.cxx.

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}

◆ reset()

StatusCode D3PD::IndexMap::reset ( )

Call before asking for an index. Rebuilds cache if needed.

Call before asking for an index.

Rebuilds cache if needed.

Definition at line 227 of file IndexMap.cxx.

228{
229 if (!m_valid) {
230 for (size_t i = 0; i < m_targets.size(); i++) {
231 ICollectionGetterTool* target = m_targets[i];
232 if (target) {
233 CHECK( target->reset (m_allowMissing) );
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)));
239 target->releaseObjectUntyped (obj);
240 }
241 }
242 }
243 m_valid = true;
244 }
245 return StatusCode::SUCCESS;
246}

◆ target() [1/2]

ICollectionGetterTool * D3PD::IndexMap::target ( )

Return the getter defining the first collection within which to index.

Definition at line 175 of file IndexMap.cxx.

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}

◆ target() [2/2]

ICollectionGetterTool * D3PD::IndexMap::target ( unsigned int i)

Return the getter defining the i'th collection within which to index.

Definition at line 188 of file IndexMap.cxx.

189{
190 if (i >= m_targets.size())
191 return 0;
192 return m_targets[i];
193}

◆ valid()

bool D3PD::IndexMap::valid ( ) const

Return the valid flag.

Definition at line 316 of file IndexMap.cxx.

317{
318 return m_valid;
319}

Member Data Documentation

◆ m_allowMissing

const bool& D3PD::IndexMap::m_allowMissing
private

Property for the allowMissing flag.

Definition at line 184 of file IndexMap.h.

◆ m_converters

std::vector<TypeConverter> D3PD::IndexMap::m_converters
private

Converter for each target.

Definition at line 197 of file IndexMap.h.

◆ m_getters

ToolHandleArray<ICollectionGetterTool>* D3PD::IndexMap::m_getters
private

Property for a direct list of getters.

Definition at line 181 of file IndexMap.h.

◆ m_map

map_t D3PD::IndexMap::m_map
private

Definition at line 191 of file IndexMap.h.

◆ m_parent

INamedInterface* D3PD::IndexMap::m_parent
private

The parent tool.

Definition at line 168 of file IndexMap.h.

◆ m_registry

ToolHandle<ICollectionGetterRegistryTool>* D3PD::IndexMap::m_registry
private

Property for the ICollectionGetterRegistryTool instance.

Definition at line 178 of file IndexMap.h.

◆ m_targetLabel

const std::string* D3PD::IndexMap::m_targetLabel
private

Property for the label of the getter defining the target collection.

Definition at line 171 of file IndexMap.h.

◆ m_targetLabels

const std::vector<std::string>* D3PD::IndexMap::m_targetLabels
private

Property for the label of the getter defining the list of target collections.

Definition at line 175 of file IndexMap.h.

◆ m_targets

std::vector<ICollectionGetterTool*> D3PD::IndexMap::m_targets
private

Getters defining the collections within which to index.

Definition at line 187 of file IndexMap.h.

◆ m_valid

bool D3PD::IndexMap::m_valid
private

Flag if the map is valid.

Definition at line 194 of file IndexMap.h.


The documentation for this class was generated from the following files: