ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrkrClusterContainerv3.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrkrClusterContainerv3.cc
1 
8 #include "TrkrCluster.h"
9 #include "TrkrClusterv3.h"
10 #include "TrkrDefs.h"
11 
12 #include <cstdlib>
13 
14 namespace
15 {
16  TrkrClusterContainer::Map dummy_map;
17 }
18 
19 //_________________________________________________________________
21 {
22  // delete all clusters
23  for( const auto& map_pair:m_clusmap )
24  for( const auto& pair:map_pair.second )
25  { delete pair.second; }
26 
27  // clear the maps
28  m_clusmap.clear();
29 }
30 
31 //_________________________________________________________________
32 void TrkrClusterContainerv3::identify(std::ostream& os) const
33 {
34  os << "-----TrkrClusterContainerv3-----" << std::endl;
35  os << "Number of clusters: " << size() << std::endl;
36 
37  for( const auto& map_pair:m_clusmap )
38  {
39 
40  const unsigned int layer = TrkrDefs::getLayer(map_pair.first);
41  std::cout << "layer: " << layer << " hitsetkey: " << map_pair.first << std::endl;
42 
43  for( const auto& pair:map_pair.second )
44  {
45  int layer = TrkrDefs::getLayer(pair.first);
46  os << "clus key " << pair.first << " layer " << layer << std::endl;
47  (pair.second)->identify();
48  }
49  }
50 
51  os << "------------------------------" << std::endl;
52 }
53 
54 //_________________________________________________________________
56 {
57  // get hitset key from cluster
59 
60  // find relevant cluster map if any and remove corresponding cluster
61  auto iter = m_clusmap.find( hitsetkey );
62  if( iter != m_clusmap.end() ) iter->second.erase( key );
63 }
64 
65 //_________________________________________________________________
67 { removeCluster( clus->getClusKey() ); }
68 
69 //_________________________________________________________________
72 { return addClusterSpecifyKey(newclus->getClusKey(), newclus); }
73 
74 //_________________________________________________________________
77 {
78  // get hitsetkey from cluster
80 
81  // find relevant cluster map or create one if not found
82  Map& map = m_clusmap[hitsetkey];
83  const auto ret = map.insert(std::make_pair(key, newclus));
84  if ( !ret.second )
85  {
86  std::cout << "TrkrClusterContainerv3::AddClusterSpecifyKey: duplicate key: " << key << " exiting now" << std::endl;
87  exit(1);
88  } else {
89  ret.first->second->setClusKey( key );
90  return ret.first;
91  }
92 }
93 
94 //_________________________________________________________________
97 {
98  // find relevant association map
99  const auto iter = m_clusmap.find(hitsetkey);
100  if( iter != m_clusmap.end() )
101  {
102  return std::make_pair( iter->second.cbegin(), iter->second.cend() );
103  } else {
104  return std::make_pair( dummy_map.cbegin(), dummy_map.cend() );
105  }
106 }
107 
108 //_________________________________________________________________
111 { return &m_clusmap[hitsetkey]; }
112 
113 //_________________________________________________________________
116 {
117  // get hitsetkey from cluster
119 
120  // find relevant cluster map or create one if not found
121  Map& map = m_clusmap[hitsetkey];
122  auto it = map.lower_bound(key);
123  if( it == map.end() || (key<it->first) )
124  {
125  // add new cluster and set its key
126  it = map.insert(it, std::make_pair(key, new TrkrClusterv3()));
127  it->second->setClusKey( key );
128  }
129 
130  return it;
131 }
132 
133 //_________________________________________________________________
135 {
136 
137  // get hitsetkey from cluster
139 
140  const auto map_iter = m_clusmap.find(hitsetkey);
141  if( map_iter != m_clusmap.end() )
142  {
143  const auto clus_iter = map_iter->second.find( key );
144  if( clus_iter != map_iter->second.end() )
145  {
146  return clus_iter->second;
147  } else {
148  return nullptr;
149  }
150  } else {
151  return nullptr;
152  }
153 }
154 
155 //_________________________________________________________________
156 unsigned int TrkrClusterContainerv3::size(void) const
157 {
158  unsigned int size = 0;
159  for( const auto& map_pair:m_clusmap )
160  { size += map_pair.second.size(); }
161 
162  return size;
163 }