Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SvtxTrackMap_v1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SvtxTrackMap_v1.cc
1 #include "SvtxTrackMap_v1.h"
2 
3 #include "SvtxTrack.h"
4 
5 #include <phool/PHObject.h> // for PHObject
6 
7 #include <iterator> // for reverse_iterator
8 #include <map> // for _Rb_tree_const_iterator, _Rb_tree_iterator
9 #include <ostream> // for operator<<, endl, ostream, basic_ostream, bas...
10 #include <utility> // for pair, make_pair
11 
12 using namespace std;
13 
14 
16  : _map()
17 {
18 }
19 
21  : _map()
22 {
23  for (ConstIter iter = trackmap.begin();
24  iter != trackmap.end();
25  ++iter)
26  {
27  SvtxTrack* track = dynamic_cast<SvtxTrack*> (iter->second->CloneMe());
28  _map.insert(make_pair(track->get_id(), track));
29  }
30 }
31 
33 {
34  Reset();
35  for (ConstIter iter = trackmap.begin();
36  iter != trackmap.end();
37  ++iter)
38  {
39  SvtxTrack* track = dynamic_cast<SvtxTrack*> (iter->second->CloneMe());
40  _map.insert(make_pair(track->get_id(), track));
41  }
42  return *this;
43 }
44 
46 {
47  Reset();
48 }
49 
51 {
52  for (Iter iter = _map.begin();
53  iter != _map.end();
54  ++iter)
55  {
56  SvtxTrack* track = iter->second;
57  delete track;
58  }
59  _map.clear();
60 }
61 
62 void SvtxTrackMap_v1::identify(ostream& os) const
63 {
64  os << "SvtxTrackMap_v1: size = " << _map.size() << endl;
65  return;
66 }
67 
68 const SvtxTrack* SvtxTrackMap_v1::get(unsigned int id) const
69 {
70  ConstIter iter = _map.find(id);
71  if (iter == _map.end()) return nullptr;
72  return iter->second;
73 }
74 
76 {
77  Iter iter = _map.find(id);
78  if (iter == _map.end()) return nullptr;
79  return iter->second;
80 }
81 
83 {
84  unsigned int index = 0;
85  if (!_map.empty()) index = _map.rbegin()->first + 1;
86  _map.insert(make_pair(index, dynamic_cast<SvtxTrack*> (track->CloneMe())));
87  _map[index]->set_id(index);
88  return _map[index];
89 }
90 
91 size_t SvtxTrackMap_v1::erase(unsigned int idkey)
92 {
93  const auto iter = _map.find(idkey);
94  if( iter != _map.end() )
95  {
96 
97  delete iter->second;
98  _map.erase( iter );
99  return 1;
100 
101  } else return 0;
102 }
103