ATLAS Offline Software
TrackPtr.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef _Trk_TrackPtr_h_
5 #define _Trk_TrackPtr_h_
6 
7 #include "TrkTrack/Track.h"
8 
9 namespace Trk {
10  class TrackPtr {
11  public:
12  TrackPtr() = delete;
13 
14  // disallow copying
15  TrackPtr( const TrackPtr &) = delete;
16  TrackPtr &operator=(const TrackPtr &) = delete;
17 
18  // allow moving
20  if (a.m_owner) {
21  a.m_owner = false;
22  a.m_track.m_ownedTrack = nullptr;
23  }
24  }
25 
27  if (a.m_owner) {
28  a.m_owner = false;
29  a.m_track.m_ownedTrack = nullptr;
30  }
31  }
32 
33  TrackPtr( const Trk::Track *orig_track) : m_uid(-1), m_owner(false), m_fitted(false) { m_track.m_origTrack = orig_track; }
34  TrackPtr( Trk::Track *new_track, bool fitted) : m_uid(-1), m_owner(true), m_fitted(fitted) { m_track.m_ownedTrack = new_track; }
35  TrackPtr( const Trk::Track *orig_track, int uid) : m_uid(uid), m_owner(false), m_fitted(false) { m_track.m_origTrack = orig_track; }
36  TrackPtr( Trk::Track *new_track, bool fitted, int uid) : m_uid(uid), m_owner(true), m_fitted(fitted) { m_track.m_ownedTrack = new_track; }
38  if (m_owner) delete m_track.m_ownedTrack;
39  }
40 
42  assert( (m_owner && m_track.m_ownedTrack) || (!m_owner && m_track.m_origTrack) );
43  Trk::Track *tmp = (m_owner ? m_track.m_ownedTrack : new Trk::Track( *m_track.m_origTrack) );
44  if (m_owner) {
45  m_track.m_ownedTrack = nullptr;
46  m_owner=false;
47  m_fitted=false;
48  }
49  return tmp;
50  }
51 
52  const Trk::Track *operator->() const { assert(track()); return track(); }
53  const Trk::Track &operator*() const { assert(track()); return *track(); }
54  const Trk::Track *track() const {
55  return (m_owner ? m_track.m_ownedTrack : m_track.m_origTrack);
56  }
57 
59  return (m_owner ? m_track.m_ownedTrack : nullptr);
60  }
61 
63  if (m_owner) {
64  delete m_track.m_ownedTrack;
65  }
66  m_track.m_ownedTrack = track;
67  if (track) {
68  m_owner=true;
70  }
71  else {
72  m_owner=false;
73  m_fitted=false;
74  }
75  }
76  bool fitted() const { return m_fitted; }
77  void forceFitted() { m_fitted=true; }
78  int getUid() const { return m_uid; }
79 
80  private:
81  union {
85  const int m_uid;
86  bool m_owner;
87  bool m_fitted;
88  };
89 }
90 #endif
Trk::TrackPtr::TrackPtr
TrackPtr(const Trk::Track *orig_track, int uid)
Definition: TrackPtr.h:35
Trk::TrackPtr::release
Trk::Track * release()
Definition: TrackPtr.h:41
Trk::TrackPtr::TrackPtr
TrackPtr()=delete
Trk::TrackPtr::m_owner
bool m_owner
Definition: TrackPtr.h:86
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Trk::TrackPtr::setNewTrack
void setNewTrack(Trk::Track *track, bool fitted)
Definition: TrackPtr.h:62
Trk::TrackPtr::operator->
const Trk::Track * operator->() const
Definition: TrackPtr.h:52
xAOD::JetInput::Track
@ Track
Definition: JetContainerInfo.h:61
Trk::TrackPtr::~TrackPtr
~TrackPtr()
Definition: TrackPtr.h:37
Trk::TrackPtr::TrackPtr
TrackPtr(TrackPtr &&a)
Definition: TrackPtr.h:19
Trk::TrackPtr::getUid
int getUid() const
Definition: TrackPtr.h:78
Trk::TrackPtr::newTrack
Trk::Track * newTrack()
Definition: TrackPtr.h:58
Trk::TrackPtr::forceFitted
void forceFitted()
Definition: TrackPtr.h:77
Trk::TrackPtr::track
const Trk::Track * track() const
Definition: TrackPtr.h:54
Track.h
Trk::TrackPtr::TrackPtr
TrackPtr(Trk::Track *new_track, bool fitted)
Definition: TrackPtr.h:34
Trk::TrackPtr::TrackPtr
TrackPtr(Trk::Track *new_track, bool fitted, int uid)
Definition: TrackPtr.h:36
Trk::TrackPtr::operator=
TrackPtr & operator=(const TrackPtr &)=delete
Trk::TrackPtr
Definition: TrackPtr.h:10
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
Trk::TrackPtr::TrackPtr
TrackPtr(TrackPtr &&a, int uid)
Definition: TrackPtr.h:26
Trk::TrackPtr::TrackPtr
TrackPtr(const Trk::Track *orig_track)
Definition: TrackPtr.h:33
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::TrackPtr::TrackPtr
TrackPtr(const TrackPtr &)=delete
a
TList * a
Definition: liststreamerinfos.cxx:10
Trk::TrackPtr::m_track
union Trk::TrackPtr::@214 m_track
Trk::TrackPtr::fitted
bool fitted() const
Definition: TrackPtr.h:76
Trk::TrackPtr::m_fitted
bool m_fitted
Definition: TrackPtr.h:87
Trk::TrackPtr::m_ownedTrack
Trk::Track * m_ownedTrack
Definition: TrackPtr.h:82
Trk::TrackPtr::operator*
const Trk::Track & operator*() const
Definition: TrackPtr.h:53
Trk::TrackPtr::m_uid
const int m_uid
Definition: TrackPtr.h:85
Trk::TrackPtr::m_origTrack
const Trk::Track * m_origTrack
Definition: TrackPtr.h:83