Geant4ParticleCollection.cc
Go to the documentation of this file.
1 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2 
4 
5 #include <numeric>
6 
7 // standard includes
8 #include <stdexcept>
9 #include <iomanip>
10 
11 namespace dd4pod {
12 
13 
15  m_isValid(false), m_isReadFromFile(false), m_collectionID(0), m_entries(),
16  m_data(new Geant4ParticleDataContainer()) {
17  m_vecmem_info.emplace_back("int", &m_vec_parents);
18  m_vec_parents = new std::vector<int>();
19  m_vecmem_info.emplace_back("int", &m_vec_daughters);
20  m_vec_daughters = new std::vector<int>();
21 }
22 
24  clear();
25  if (m_data) delete m_data;
26  if (m_vec_parents) delete m_vec_parents;
27  if (m_vec_daughters) delete m_vec_daughters;
28 }
29 
30 const Geant4Particle Geant4ParticleCollection::operator[](unsigned int index) const {
31  return Geant4Particle(m_entries[index]);
32 }
33 
34 const Geant4Particle Geant4ParticleCollection::at(unsigned int index) const {
35  return Geant4Particle(m_entries.at(index));
36 }
37 
39  return Geant4Particle(m_entries[index]);
40 }
41 
43  return Geant4Particle(m_entries.at(index));
44 }
45 
47  return m_entries.size();
48 }
49 
51  auto obj = m_entries.emplace_back(new Geant4ParticleObj());
52  m_vecs_parents.push_back(obj->m_parents);
53  m_vecs_daughters.push_back(obj->m_daughters);
54 
55  obj->id = {int(m_entries.size() - 1), m_collectionID};
56  return Geant4Particle(obj);
57 }
58 
60  m_data->clear();
61  m_vec_parents->clear();
62  for (auto& vec : m_vecs_parents) { delete vec; }
63  m_vecs_parents.clear();
64 
65  m_vec_daughters->clear();
66  for (auto& vec : m_vecs_daughters) { delete vec; }
67  m_vecs_daughters.clear();
68 
69  for (auto& obj : m_entries) { delete obj; }
70  m_entries.clear();
71 }
72 
74  const auto size = m_entries.size();
75  m_data->reserve(size);
76  for (auto& obj : m_entries) { m_data->push_back(obj->data); }
77 
78  // if the collection has been read from a file the rest of the information is
79  // already in the correct format and we have to skip it, since the temporary
80  // buffers are invalid
81  if (m_isReadFromFile) return;
82  for (auto& pointer : m_refCollections) { pointer->clear(); }
83 
84  const int parents_size = std::accumulate(m_entries.begin(), m_entries.end(), 0, [](int sum, const Geant4ParticleObj* obj) { return sum + obj->m_parents->size(); });
85  m_vec_parents->reserve(parents_size);
86  int parents_index = 0;
87  const int daughters_size = std::accumulate(m_entries.begin(), m_entries.end(), 0, [](int sum, const Geant4ParticleObj* obj) { return sum + obj->m_daughters->size(); });
88  m_vec_daughters->reserve(daughters_size);
89  int daughters_index = 0;
90  for (int i = 0, size = m_data->size(); i != size; ++i) {
91  (*m_data)[i].parents_begin = parents_index;
92  (*m_data)[i].parents_end += parents_index;
93  parents_index = (*m_data)[i].parents_end;
94  for (const auto& it : (*m_vecs_parents[i])) { m_vec_parents->push_back(it); }
95 
96  (*m_data)[i].daughters_begin = daughters_index;
97  (*m_data)[i].daughters_end += daughters_index;
98  daughters_index = (*m_data)[i].daughters_end;
99  for (const auto& it : (*m_vecs_daughters[i])) { m_vec_daughters->push_back(it); }
100 
101  }
102 }
103 
105  int index = 0;
106  for (auto& data : *m_data) {
107  auto obj = new Geant4ParticleObj({index, m_collectionID}, data);
108 
109  obj->m_parents = m_vec_parents;
110  obj->m_daughters = m_vec_daughters;
111  m_entries.emplace_back(obj);
112  ++index;
113  }
114 
115  // at this point we are done with the I/O buffer and can safely clear it to not
116  // have a redundant (but now useless) copy of the data
117  m_data->clear();
118  m_isValid = true;
119  m_isReadFromFile = true;
120 }
121 
122 bool Geant4ParticleCollection::setReferences(const podio::ICollectionProvider* collectionProvider) {
123 
124  return true; //TODO: check success
125 }
126 
128  const int size = m_entries.size();
129  auto obj = object.m_obj;
130  if (obj->id.index == podio::ObjectID::untracked) {
131  obj->id = {size, m_collectionID};
132  m_entries.push_back(obj);
133 
134  m_vecs_parents.push_back(obj->m_parents);
135  m_vecs_daughters.push_back(obj->m_daughters);
136  } else {
137  throw std::invalid_argument("Object already in a collection. Cannot add it to a second collection");
138  }
139 }
140 
142  if (m_data) delete m_data;
143  m_data = static_cast<Geant4ParticleDataContainer*>(address);
144 }
145 
147  m_object.m_obj = (*m_collection)[m_index];
148  return m_object;
149 }
150 
152  m_object.m_obj = (*m_collection)[m_index];
153  return &m_object;
154 }
155 
157  ++m_index;
158  return *this;
159 }
160 
161 std::ostream& operator<<(std::ostream& o, const Geant4ParticleCollection& v) {
162  const auto old_flags = o.flags();
163  o << " id: ID: g4Parent: reason: mask: steps: secondaries: pdgID: status: colorFlow: genStatus: charge: spare: spin: vsx: vsy: vsz: vex: vey: vez: psx: psy: psz: pex: pey: pez: mass: time: properTime:" << '\n';
164 
165  for (size_t i = 0; i < v.size(); ++i) {
166  o << std::scientific << std::showpos << std::setw(12) << v[i].id() << " "
167  << std::setw(12) << v[i].ID() << " "
168  << std::setw(12) << v[i].g4Parent() << " "
169  << std::setw(12) << v[i].reason() << " "
170  << std::setw(12) << v[i].mask() << " "
171  << std::setw(12) << v[i].steps() << " "
172  << std::setw(12) << v[i].secondaries() << " "
173  << std::setw(12) << v[i].pdgID() << " "
174  << std::setw(12) << v[i].status() << " "
175  << std::setw(12) << v[i].genStatus() << " "
176  << std::setw(12) << v[i].charge() << " "
177  << std::setw(12) << v[i].vsx() << " "
178  << std::setw(12) << v[i].vsy() << " "
179  << std::setw(12) << v[i].vsz() << " "
180  << std::setw(12) << v[i].vex() << " "
181  << std::setw(12) << v[i].vey() << " "
182  << std::setw(12) << v[i].vez() << " "
183  << std::setw(12) << v[i].psx() << " "
184  << std::setw(12) << v[i].psy() << " "
185  << std::setw(12) << v[i].psz() << " "
186  << std::setw(12) << v[i].pex() << " "
187  << std::setw(12) << v[i].pey() << " "
188  << std::setw(12) << v[i].pez() << " "
189  << std::setw(12) << v[i].mass() << " "
190  << std::setw(12) << v[i].time() << " "
191  << std::setw(12) << v[i].properTime() << " "
192  << std::endl;
193 
194 
195 
196  o << " parents : ";
197  for (unsigned j = 0, N = v[i].parents_size(); j < N; ++j) {
198  o << v[i].parents(j) << " ";
199  }
200  o << std::endl;
201  o << " daughters : ";
202  for (unsigned j = 0, N = v[i].daughters_size(); j < N; ++j) {
203  o << v[i].daughters(j) << " ";
204  }
205  o << std::endl;
206 
207  }
208 
209  o.flags(old_flags);
210  return o;
211 }
212 
213 } // namespace dd4pod
214 
const std::array< double, arraysize > vsy() const
const std::array< double, arraysize > pez() const
const std::array< int, arraysize > g4Parent() const
size_t size() const override final
number of elements in the collection
const std::array< double, arraysize > properTime() const
Geant4Particle create()
Append a new object to the collection, and return this object.
const std::array< int, arraysize > ID() const
const std::array< double, arraysize > vey() const
const std::array< double, arraysize > psy() const
const std::array< double, arraysize > vsx() const
const Geant4ParticleCollectionIterator & operator++() const
const std::array< double, arraysize > vez() const
std::vector< Geant4ParticleData > Geant4ParticleDataContainer
const std::array< double, arraysize > mass() const
const std::array< int, arraysize > steps() const
const std::array< int, arraysize > mask() const
const std::array< int, arraysize > reason() const
const std::array< int, arraysize > genStatus() const
const std::array< double, arraysize > psx() const
const std::array< int, arraysize > charge() const
void setBuffer(void *address) override final
std::vector< int > * m_parents
const std::array< double, arraysize > vsz() const
const std::array< double, arraysize > psz() const
const std::array< int, arraysize > secondaries() const
const std::array< int, arraysize > status() const
const std::array< double, arraysize > pex() const
const std::array< int, arraysize > pdgID() const
std::ostream & operator<<(std::ostream &o, const ConstCalorimeterHit &value)
const Geant4Particle operator[](unsigned int index) const
Returns the const object of given index.
void push_back(ConstGeant4Particle object)
Append object to the collection.
const std::array< double, arraysize > pey() const
const Geant4Particle at(unsigned int index) const
Returns the const object of given index.
const std::array< double, arraysize > vex() const
A Collection is identified by an ID.
const std::array< double, arraysize > time() const
bool setReferences(const podio::ICollectionProvider *collectionProvider) override final