ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawClusterContainer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawClusterContainer.cc
1 #include "RawClusterContainer.h"
2 
3 #include "RawCluster.h"
4 
5 #include <cstdlib>
6 #include <iostream>
7 
8 using namespace std;
9 
12 {
13  return make_pair(_clusters.begin(), _clusters.end());
14 }
15 
18 {
19  return make_pair(_clusters.begin(), _clusters.end());
20 }
21 
24 {
25  unsigned int key = _clusters.size();
26  // just to be safe in case someone deleted a cluster and key is
27  // a valid index of a cluster, increment key until there is no cluster
28  // in our map
29  while (_clusters.find(key) != _clusters.end())
30  {
31  key++;
32  }
33  rawcluster->set_id(key);
34  _clusters[key] = rawcluster;
35  return _clusters.find(key);
36 }
37 
39 RawClusterContainer::getCluster(const unsigned int key)
40 {
41  ConstIterator it = _clusters.find(key);
42  if (it != _clusters.end())
43  {
44  return it->second;
45  }
46  return NULL;
47 }
48 
49 const RawCluster*
50 RawClusterContainer::getCluster(const unsigned int key) const
51 {
52  ConstIterator it = _clusters.find(key);
53  if (it != _clusters.end())
54  {
55  return it->second;
56  }
57  return NULL;
58 }
59 
61 {
62  return (!_clusters.empty());
63 }
64 
66 {
67  while (_clusters.begin() != _clusters.end())
68  {
69  delete _clusters.begin()->second;
70  _clusters.erase(_clusters.begin());
71  }
72 }
73 
74 void RawClusterContainer::identify(std::ostream& os) const
75 {
76  os << "RawClusterContainer, number of clusters: " << size() << std::endl;
77 }
78 
79 double
81 {
82  double totalenergy = 0;
83  ConstIterator iter;
84  for (iter = _clusters.begin(); iter != _clusters.end(); ++iter)
85  {
86  totalenergy += iter->second->get_energy();
87  }
88  return totalenergy;
89 }