Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SvtxTrackMap_v2.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SvtxTrackMap_v2.cc
1 #include "SvtxTrackMap_v2.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 
13  : _map()
14 {
15 }
16 
18  : _map()
19 {
20  for (ConstIter iter = trackmap.begin();
21  iter != trackmap.end();
22  ++iter)
23  {
24  auto track = static_cast<SvtxTrack*> (iter->second->CloneMe());
25  _map.insert(std::make_pair(track->get_id(), track));
26  }
27 }
28 
30 {
31 
32  // do nothing if same copying map onto itself
33  if( &trackmap == this ) return *this;
34 
35  Reset();
36  for (ConstIter iter = trackmap.begin();
37  iter != trackmap.end();
38  ++iter)
39  {
40  auto track = static_cast<SvtxTrack*> (iter->second->CloneMe());
41  _map.insert(std::make_pair(track->get_id(), track));
42  }
43  return *this;
44 }
45 
47 {
48  Reset();
49 }
50 
52 {
53  for (Iter iter = _map.begin();
54  iter != _map.end();
55  ++iter)
56  {
57  SvtxTrack* track = iter->second;
58  delete track;
59  }
60  _map.clear();
61 }
62 
63 void SvtxTrackMap_v2::identify(std::ostream& os) const
64 {
65  os << "SvtxTrackMap_v2: size = " << _map.size() << std::endl;
66  return;
67 }
68 
69 const SvtxTrack* SvtxTrackMap_v2::get(unsigned int id) const
70 {
71  ConstIter iter = _map.find(id);
72  if (iter == _map.end()) return nullptr;
73  return iter->second;
74 }
75 
77 {
78  Iter iter = _map.find(id);
79  if (iter == _map.end()) return nullptr;
80  return iter->second;
81 }
82 
84 {
85  unsigned int index = 0;
86  if (!_map.empty()) index = _map.rbegin()->first + 1;
87  auto copy = static_cast<SvtxTrack*>( track->CloneMe() );
88  copy->set_id(index);
89 
90  const auto result = _map.insert(std::make_pair(index, copy ));
91  if( !result.second )
92  {
93  std::cout << "SvtxTrackMap_v2::insert - duplicated key. track not inserted" << std::endl;
94  delete copy;
95  return nullptr;
96  } else {
97  return copy;
98  }
99 }
100 
102 {
103  auto copy = static_cast<SvtxTrack*>( track->CloneMe() );
104  copy->set_id(index);
105  const auto result = _map.insert(std::make_pair(index, copy ));
106  if( !result.second )
107  {
108  std::cout << "SvtxTrackMap_v2::insertWithKey - duplicated key. track not inserted" << std::endl;
109  delete copy;
110  return nullptr;
111  } else {
112  return copy;
113  }
114 }