Analysis Software
Documentation for sPHENIX simulation 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 <KFParticle.h>
12 
13 #include <cstdlib>
14 #include <iterator> // for reverse_iterator
15 #include <map> // for _Rb_tree_const_iterator, _Rb_tree_iterator
16 #include <ostream> // for operator<<, endl, ostream, basic_ostream, bas...
17 #include <utility> // for pair, make_pair
18 
20  : m_kfpmap()
21 {
22 }
23 
25  : m_kfpmap()
26 {
27  for (auto& iter : kfparticlemap)
28  {
29  KFParticle* particle = dynamic_cast<KFParticle*>(iter.second->Clone());
30  m_kfpmap.insert(std::make_pair(particle->Id(), particle));
31  }
32 }
33 
35 {
36  Reset();
37  for (auto& iter : kfparticlemap)
38  {
39  KFParticle* particle = dynamic_cast<KFParticle*>(iter.second->Clone());
40  m_kfpmap.insert(std::make_pair(particle->Id(), particle));
41  }
42  return *this;
43 }
44 
46 {
47  Reset();
48 }
49 
51 {
52  for (auto& iter : m_kfpmap)
53  {
54  KFParticle* particle = iter.second;
55  delete particle;
56  }
57  m_kfpmap.clear();
58 }
59 
60 void KFParticle_Container::identify(std::ostream& os) const
61 {
62  os << "KFParticle_Container: size = " << m_kfpmap.size() << std::endl;
63  return;
64 }
65 
66 const KFParticle* KFParticle_Container::get(unsigned int id) const
67 {
68  ConstIter iter = m_kfpmap.find(id);
69  if (iter == m_kfpmap.end())
70  {
71  return nullptr;
72  }
73  return iter->second;
74 }
75 
77 {
78  Iter iter = m_kfpmap.find(id);
79  if (iter == m_kfpmap.end())
80  {
81  return nullptr;
82  }
83  return iter->second;
84 }
85 
87 {
88  unsigned int index = 0;
89  if (!m_kfpmap.empty())
90  {
91  index = m_kfpmap.rbegin()->first + 1;
92  }
93  m_kfpmap.insert(std::make_pair(index, dynamic_cast<KFParticle*>(particle->Clone())));
94  // m_kfpmap[index]->SetId(index);
95  return m_kfpmap[index];
96 }
97 
100 {
101  return addParticleSpecifyKey(particle->Id(), particle);
102 }
103 
106 {
107  auto ret = m_kfpmap.insert(std::make_pair(id, particle));
108  if (!ret.second)
109  {
110  std::cout << "KFParticle_Container::AddParticleSpecifyKey: duplicate id: " << id << " exiting now" << std::endl;
111  exit(1);
112  }
113  else
114  {
115  return ret.first;
116  }
117 }
118 
121 {
122  Map requiredParticles;
123 
124  for (auto& iter : m_kfpmap)
125  {
126  if (iter.second->GetPDG() == PDGid)
127  {
128  requiredParticles.insert(std::make_pair(iter.first, iter.second));
129  }
130  }
131 
132  return requiredParticles;
133 }
134 
135 size_t KFParticle_Container::erase(unsigned int key)
136 {
137  delete m_kfpmap[key];
138  return m_kfpmap.erase(key);
139 }