ATLAS Offline Software
DataLinkVector.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef EVENTCONTAINERS_DATALINKVECTOR_H
6 #define EVENTCONTAINERS_DATALINKVECTOR_H
7 
17 #include "GaudiKernel/DataObject.h"
18 #include <vector>
19 
20 
32 template < class DC >
33 class DataLinkVector :public DataObject
34 {
35 public:
36 
37  typedef DC value_type;
38  typedef DC* pointer;
39  typedef const DC* const_pointer;
40  typedef DC& reference;
41  typedef const DC& const_reference;
42 
47  class DataHolder
48  {
49  public:
51  DataHolder();
52 
54  bool hasData() const;
55 
57  const_pointer operator->() const;
58 
60  operator const_pointer () const { return this->getDataPtr(); }
61 
63  const_pointer cptr() const;
64 
66  void reset();
67 
69  void setDataPtr(const DC* obj);
70 
72  pointer getDataPtr() const;
73 
74  private:
75 
77  };
78 
79 
82 
87  class Entry
88  {
89  public:
91  Entry();
92 
94  Entry& operator = (const Entry& e);
95 
98 
100  DataLinkT& dataLink();
101 
103  bool ownObject() const;
104 
107 
109  void setDataLink (const DataLinkT& link);
110 
112  void setOwnObject(bool owns);
113 
114  private:
117  // ownObject is true if this object should be deleted by DLV.
118  // May be false if object is managed by a data pool
120  };
121  typedef std::vector<Entry> EntryVector;
123 
127  class iterator
128  {
129  public:
131  iterator();
132 
134  bool operator != ( const iterator it ) const;
135 
137  bool operator == ( const iterator it ) const;
138 
140  iterator& operator = ( const iterator it );
141 
144 
146  iterator operator ++ ( int );
147 
150 
153 
155  bool hasData();
156 
157  protected:
158  friend class DataLinkVector<DC>;
159 
160  iterator( const MyType* dlv,
161  EntryVectorIt it );
162 
163 
166  void checkChain();
167 
170 
171  const MyType* m_dlv;
173  };
174 
175  friend class iterator;
176 
177 
179  DataLinkVector();
180 
182  ~DataLinkVector();
183 
185  void init( unsigned int nbr );
186 
188  iterator begin() const;
189 
191  iterator end() const;
192 
194  iterator find( IdentifierHash id ) const;
195 
197  bool setObjectOwnership(IdentifierHash idhash, bool flag);
198 
201  DataLinkT& operator [] ( int id );
202 
206  virtual void cleanup();
207 
209  int size() const;
210 
211 protected:
212 
214  void chainEntry( Entry* e ) const;
215 
217  mutable Entry* m_last;
218 };
219 
221 
222 template <class DC>
224  :
225  m_obj(0)
226 {}
227 
228 template <class DC>
229 bool
231 {
232  return (m_obj != 0);
233 }
234 
235 template <class DC>
238 {
239  return this->getDataPtr();
240 }
241 
242 template <class DC>
245 {
246  return this->getDataPtr();
247 }
248 
249 template <class DC>
250 void
252 {
253  m_obj = 0;
254 }
255 
256 template <class DC>
257 void
259 {
260  m_obj = const_cast<pointer>(obj);
261 }
262 
263 template <class DC>
266 {
267  return (m_obj);
268 }
269 
270 template <class DC>
272  :
273  m_previousEntry(NULL),
274  m_ownObject(false)
275 {
276  m_dataLink = DataLinkT();
277 }
278 
279 template <class DC>
280 typename DataLinkVector<DC>::Entry&
282  m_dataLink = e.m_dataLink ;
283  m_previousEntry = e.m_previousEntry;
284  m_ownObject = e.m_ownObject;
285  return *this;
286 }
287 
288 template <class DC>
289 typename DataLinkVector<DC>::Entry*
291 {
292  return m_previousEntry;
293 }
294 
295 template <class DC>
298 {
299  return m_dataLink;
300 }
301 
302 template <class DC>
303 bool
305 {
306  return m_ownObject;
307 }
308 
309 template <class DC>
310 void
312 {
313  m_previousEntry = entry;
314 }
315 
316 template <class DC>
317 void
319 {
320  m_dataLink = link;
321 }
322 
323 template <class DC>
324 void
326 {
327  m_ownObject = owns;
328 }
329 
330 
331 
332 template <class DC>
334  : m_dlv(NULL) {}
335 
336 
337 template <class DC>
338 bool
340 { return it.m_it != m_it; }
341 
342 template <class DC>
343 bool
345 { return it.m_it == m_it; }
346 
347 template <class DC>
350 { m_dlv = it.m_dlv; m_it = it.m_it; return *this; }
351 
352 template <class DC>
355 { ++m_it; return *this; }
356 
357 template <class DC>
360 { return iterator( m_dlv, m_it++ ); }
361 
362 template <class DC>
365 { checkChain(); return m_it->dataLink(); }
366 
367 template <class DC>
370 { checkChain(); return &m_it->dataLink(); }
371 
372 template <class DC>
373 bool
375 {
376  // check if DL is valid, and cash the state
377  checkChain(); // this entry has been touched.
378  Entry& e = *m_it;
379  bool DL_valid = e.dataLink().hasData();
380  return DL_valid;
381 }
382 
383 template <class DC>
385  EntryVectorIt it )
386  : m_dlv(dlv), m_it(it) {}
387 
388 // make sur entry is chained
389 // If not, add entry to the chain otherwise do nothing because
390 
391 template <class DC>
392 void
394 { if( m_it->previousEntry() == NULL ) m_dlv->chainEntry( &(*m_it) ) ; }
395 
396 // protected method for derived class to access m_vect
397 
398 template <class DC>
401 {
402  return m_dlv->m_vect ;
403 }
404 
405 // Default constructor
406 template <class DC>
408  : m_last(NULL) { }
409 
410 // Default constructor
411 template <class DC>
413 {
414  this->cleanup();
415 }
416 
417 // initialize vector with nbr DataLinks
418 template <class DC>
419 void
420 DataLinkVector<DC>::init( unsigned int nbr )
421 {
422  // fill in vector of Entry
423  m_vect.resize(nbr);
424 }
425 
426 // return iterator on m_previousEntry entry
427 template <class DC>
430 { return iterator( this, m_vect.begin() ); }
431 
432 // return iterator on after last entry
433 template <class DC>
436 { return iterator( this, m_vect.end()); }
437 
438 // return iterator on the found entry or end() if out of range
439 template <class DC>
442 { return ( (id >= m_vect.size() )
443  ?end():iterator(this,m_vect.begin()+id));}
444 
445 // set object ownership
446 template <class DC>
447 bool
449 {
450  if ( idhash >= m_vect.size() )
451  return false;
452  Entry& e = *(m_vect.begin()+idhash);
453  e.setOwnObject(flag);
454  return true;
455 }
456 
457 // return reference on DataLink
458 // BEWARE: Doesn't check for boundary limits !
459 template <class DC>
462 {
463  Entry* e = &(m_vect[id]);
464  if( !e->previousEntry() )
465  chainEntry( e );
466  return e->dataLink();
467 }
468 
469 // cleans up the DataLinkVector
470 // goes trough all chained entries and call clear() method of DataLink
471 // and clear chain of course.
472 template <class DC>
473 void
475 {
476  Entry *e;
477  // assign last to e and check if it is not NULL
478  if( (e = m_last) )
479  {
480  // for chained entries
481  do {
482  Entry * tmp = e->previousEntry();
483  e->setPreviousEntry(NULL); // clear chain pointer
484  if (e->ownObject()) // delete object
485  delete (e->dataLink()).getDataPtr();
486  e->dataLink().reset(); // reset keeps it in identified state.
487  e->setOwnObject(false); // doesn't own object
488  e = tmp; // go to next entry
489  } while( e != m_last ); // until we end where we started
490  m_last = NULL; // clear chain hook
491  }
492 }
493 
494 template <class DC>
495 int
497  return m_vect.size();
498 }
499 
500 template <class DC>
501 void
503 {
504  if( m_last == NULL ) {
505  e->setPreviousEntry(e);
506  m_last = e;
507  }
508  else {
509  e->setPreviousEntry(m_last->previousEntry());
510  m_last->setPreviousEntry(e);
511  }
512 }
513 
514 
515 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DataLinkVector::iterator::m_it
EntryVectorIt m_it
Definition: DataLinkVector.h:172
DataLinkVector::Entry::m_dataLink
DataLinkT m_dataLink
Definition: DataLinkVector.h:116
DataLinkVector::iterator::hasData
bool hasData()
test if DataHolder has data
Definition: DataLinkVector.h:374
DataLinkVector::begin
iterator begin() const
return iterator on first entry
Definition: DataLinkVector.h:429
DataLinkVector::Entry::previousEntry
Entry * previousEntry()
access to next entry
Definition: DataLinkVector.h:290
DataLinkVector::find
iterator find(IdentifierHash id) const
return iterator on the found entry or end() if out of range
Definition: DataLinkVector.h:441
DataLinkVector::iterator::operator->
DataLinkT * operator->()
access to object by pointer
Definition: DataLinkVector.h:369
DataLinkVector
This class is a a vector of DataLink for objects of type DC It uses an internal chain to keep track o...
Definition: DataLinkVector.h:34
DataLinkVector::EntryVectorIt
EntryVector::iterator EntryVectorIt
Definition: DataLinkVector.h:122
skel.it
it
Definition: skel.GENtoEVGEN.py:423
DataLinkVector::init
void init(unsigned int nbr)
initialize vector with nbr DataLinks
Definition: DataLinkVector.h:420
DataLinkVector::chainEntry
void chainEntry(Entry *e) const
add pointed entry in chain of modified entries
Definition: DataLinkVector.h:502
DataLinkVector::DataHolder::reset
void reset()
reset pointer to 0
Definition: DataLinkVector.h:251
DataLinkVector::iterator::operator=
iterator & operator=(const iterator it)
assignment operator
Definition: DataLinkVector.h:349
DataLinkVector::DataHolder::operator->
const_pointer operator->() const
access to pointer
Definition: DataLinkVector.h:237
DataLinkVector::Entry
class Entry is a link in a chained list, used for efficient cleanup of vectors.
Definition: DataLinkVector.h:88
DataLinkVector::iterator::entryVector
EntryVector & entryVector()
protected method for derived class to access m_vect
Definition: DataLinkVector.h:400
DataLinkVector::iterator::operator*
DataLinkT & operator*()
access to object by ref
Definition: DataLinkVector.h:364
DataLinkVector::Entry::ownObject
bool ownObject() const
ownObject is true if this object should be deleted by DLV.
Definition: DataLinkVector.h:304
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
DataLinkVector::DataHolder::DataHolder
DataHolder()
contructor
Definition: DataLinkVector.h:223
DataLinkVector::DataHolder::m_obj
pointer m_obj
Definition: DataLinkVector.h:76
DataLinkVector::m_last
Entry * m_last
Definition: DataLinkVector.h:217
DataLinkVector::Entry::setPreviousEntry
void setPreviousEntry(Entry *entry)
set previous entry
Definition: DataLinkVector.h:311
DataLinkVector::m_vect
EntryVector m_vect
Definition: DataLinkVector.h:216
DataLinkVector::DataLinkT
DataHolder DataLinkT
Definition: DataLinkVector.h:80
DataLinkVector::const_pointer
const DC * const_pointer
Definition: DataLinkVector.h:39
DataLinkVector::iterator
class iterator - iterator over elements in DataLinkVector which manages the Entry objects
Definition: DataLinkVector.h:128
DataLinkVector::DataHolder::getDataPtr
pointer getDataPtr() const
access to pointer
Definition: DataLinkVector.h:265
DataLinkVector::Entry::Entry
Entry()
constructor
Definition: DataLinkVector.h:271
DataLinkVector::Entry::m_previousEntry
Entry * m_previousEntry
Definition: DataLinkVector.h:115
master.flag
bool flag
Definition: master.py:29
DataLinkVector::Entry::setDataLink
void setDataLink(const DataLinkT &link)
set data link
Definition: DataLinkVector.h:318
DataLinkVector::DataHolder::cptr
const_pointer cptr() const
access to pointer
Definition: DataLinkVector.h:244
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
DataLinkVector::DataLinkVector
DataLinkVector()
Default constructor.
Definition: DataLinkVector.h:407
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
DataLinkVector::pointer
DC * pointer
Definition: DataLinkVector.h:38
DataLinkVector::DataHolder
class DataHolder is a simple class which holds a pointer to an object of type DC.
Definition: DataLinkVector.h:48
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
DataLinkVector::iterator::operator==
bool operator==(const iterator it) const
comparison operator
Definition: DataLinkVector.h:344
DataLinkVector::Entry::setOwnObject
void setOwnObject(bool owns)
set object ownership
Definition: DataLinkVector.h:325
DataLinkVector::cleanup
virtual void cleanup()
cleans up the DataLinkVector goes trough all chained entries and call clear() method of DataLink and ...
Definition: DataLinkVector.h:474
DataLinkVector::value_type
DC value_type
Definition: DataLinkVector.h:37
DataLinkVector::DataHolder::setDataPtr
void setDataPtr(const DC *obj)
set pointer
Definition: DataLinkVector.h:258
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
DataLinkVector::iterator::m_dlv
const MyType * m_dlv
Definition: DataLinkVector.h:171
DataLinkVector::setObjectOwnership
bool setObjectOwnership(IdentifierHash idhash, bool flag)
set object ownership
Definition: DataLinkVector.h:448
DataLinkVector::Entry::m_ownObject
bool m_ownObject
Definition: DataLinkVector.h:119
DataLinkVector::Entry::operator=
Entry & operator=(const Entry &e)
assignement operator
Definition: DataLinkVector.h:281
DataLinkVector::size
int size() const
access to size of vector
Definition: DataLinkVector.h:496
DataLinkVector::iterator::operator++
iterator & operator++()
increment operator
Definition: DataLinkVector.h:354
DataLinkVector::iterator::iterator
iterator()
constructor
Definition: DataLinkVector.h:333
DataLinkVector::operator[]
DataLinkT & operator[](int id)
return reference on DataLink BEWARE: Doesn't check for boundary limits !
Definition: DataLinkVector.h:461
DataLinkVector::Entry::dataLink
DataLinkT & dataLink()
access to the DataLink
Definition: DataLinkVector.h:297
DataLinkVector::MyType
DataLinkVector< DC > MyType
Definition: DataLinkVector.h:81
IdentifierHash
Definition: IdentifierHash.h:38
DataLinkVector::DataHolder::hasData
bool hasData() const
is pointer set
Definition: DataLinkVector.h:230
DataLinkVector::reference
DC & reference
Definition: DataLinkVector.h:40
python.PyAthena.obj
obj
Definition: PyAthena.py:135
DataLinkVector::end
iterator end() const
return iterator on after last entry
Definition: DataLinkVector.h:435
DataLinkVector::iterator
friend class iterator
Definition: DataLinkVector.h:175
DataLinkVector::EntryVector
std::vector< Entry > EntryVector
Definition: DataLinkVector.h:121
DataLinkVector::const_reference
const DC & const_reference
Definition: DataLinkVector.h:41
DataLinkVector::~DataLinkVector
~DataLinkVector()
Default destructor.
Definition: DataLinkVector.h:412
DataLinkVector::iterator::checkChain
void checkChain()
make sure entry is chained If not, add entry to the chain otherwise do nothing because
Definition: DataLinkVector.h:393
DataLinkVector::iterator::operator!=
bool operator!=(const iterator it) const
comparison operator
Definition: DataLinkVector.h:339