ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFParticle_Container.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFParticle_Container.cc
1 /*****************/
2 /* Cameron Dean */
3 /* LANL 2020 */
4 /* cdean@bnl.gov */
5 /*****************/
6 
7 //Ideas taken from SvtxTrackMap_v1 & TrkrClusterContainer
8 
9 #include "KFParticle_Container.h"
10 
11 #include <phool/PHObject.h> // for PHObject
12 
13 #include <KFParticle.h>
14 
15 #include <iterator> // for reverse_iterator
16 #include <map> // for _Rb_tree_const_iterator, _Rb_tree_iterator
17 #include <ostream> // for operator<<, endl, ostream, basic_ostream, bas...
18 #include <utility> // for pair, make_pair
19 
20 
22  : m_kfpmap()
23 {
24 }
25 
27  : m_kfpmap()
28 {
29  for (ConstIter iter = kfparticlemap.begin();
30  iter != kfparticlemap.end();
31  ++iter)
32  {
33  KFParticle* particle = dynamic_cast<KFParticle*>(iter->second->Clone());
34  m_kfpmap.insert(std::make_pair(particle->Id(), particle));
35  }
36 }
37 
39 {
40  Reset();
41  for (ConstIter iter = kfparticlemap.begin();
42  iter != kfparticlemap.end();
43  ++iter)
44  {
45  KFParticle* particle = dynamic_cast<KFParticle*>(iter->second->Clone());
46  m_kfpmap.insert(std::make_pair(particle->Id(), particle));
47  }
48  return *this;
49 }
50 
52 {
53  Reset();
54 }
55 
57 {
58  for (Iter iter = m_kfpmap.begin();
59  iter != m_kfpmap.end();
60  ++iter)
61  {
62  KFParticle* particle = iter->second;
63  delete particle;
64  }
65  m_kfpmap.clear();
66 }
67 
68 void KFParticle_Container::identify(std::ostream& os) const
69 {
70  os << "KFParticle_Container: size = " << m_kfpmap.size() << std::endl;
71  return;
72 }
73 
74 const KFParticle* KFParticle_Container::get(unsigned int id) const
75 {
76  ConstIter iter = m_kfpmap.find(id);
77  if (iter == m_kfpmap.end()) return nullptr;
78  return iter->second;
79 }
80 
81 KFParticle* KFParticle_Container::get(unsigned int id)
82 {
83  Iter iter = m_kfpmap.find(id);
84  if (iter == m_kfpmap.end()) return nullptr;
85  return iter->second;
86 }
87 
88 KFParticle* KFParticle_Container::insert(const KFParticle* particle)
89 {
90  unsigned int index = 0;
91  if (!m_kfpmap.empty()) index = m_kfpmap.rbegin()->first + 1;
92  m_kfpmap.insert(std::make_pair(index, dynamic_cast<KFParticle*>(particle->Clone())));
93  m_kfpmap[index]->SetId(index);
94  return m_kfpmap[index];
95 }
96 
99 {
100  return addParticleSpecifyKey(particle->Id(), particle);
101 }
102 
105 {
106  auto ret = m_kfpmap.insert(std::make_pair(id, particle));
107  if (!ret.second)
108  {
109  std::cout << "KFParticle_Container::AddParticleSpecifyKey: duplicate id: " << id << " exiting now" << std::endl;
110  exit(1);
111  }
112  else
113  {
114  return ret.first;
115  }
116 }
117 
120 {
121  Map requiredParticles;
122 
123  for (Iter iter = m_kfpmap.begin(); iter != m_kfpmap.end(); ++iter)
124  if (iter->second->GetPDG() == PDGid)
125  requiredParticles.insert(std::make_pair(iter->first, iter->second));
126 
127  return requiredParticles;
128 }
129 
130 size_t KFParticle_Container::erase(unsigned int key)
131 {
132  delete m_kfpmap[key];
133  return m_kfpmap.erase(key);
134 }