TrackerHitCollection.cc
Go to the documentation of this file.
1 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2 
4 
5 
6 // standard includes
7 #include <stdexcept>
8 #include <iomanip>
9 
10 namespace dd4pod {
11 
12 
14  m_isValid(false), m_isReadFromFile(false), m_collectionID(0), m_entries(),
15  m_data(new TrackerHitDataContainer()) {
16 }
17 
19  clear();
20  if (m_data) delete m_data;
21 }
22 
23 const TrackerHit TrackerHitCollection::operator[](unsigned int index) const {
24  return TrackerHit(m_entries[index]);
25 }
26 
27 const TrackerHit TrackerHitCollection::at(unsigned int index) const {
28  return TrackerHit(m_entries.at(index));
29 }
30 
32  return TrackerHit(m_entries[index]);
33 }
34 
35 TrackerHit TrackerHitCollection::at(unsigned int index) {
36  return TrackerHit(m_entries.at(index));
37 }
38 
40  return m_entries.size();
41 }
42 
44  auto obj = m_entries.emplace_back(new TrackerHitObj());
45 
46  obj->id = {int(m_entries.size() - 1), m_collectionID};
47  return TrackerHit(obj);
48 }
49 
51  m_data->clear();
52  for (auto& obj : m_entries) { delete obj; }
53  m_entries.clear();
54 }
55 
57  const auto size = m_entries.size();
58  m_data->reserve(size);
59  for (auto& obj : m_entries) { m_data->push_back(obj->data); }
60 
61  // if the collection has been read from a file the rest of the information is
62  // already in the correct format and we have to skip it, since the temporary
63  // buffers are invalid
64  if (m_isReadFromFile) return;
65  for (auto& pointer : m_refCollections) { pointer->clear(); }
66 
67 
68 }
69 
71  int index = 0;
72  for (auto& data : *m_data) {
73  auto obj = new TrackerHitObj({index, m_collectionID}, data);
74 
75  m_entries.emplace_back(obj);
76  ++index;
77  }
78 
79  // at this point we are done with the I/O buffer and can safely clear it to not
80  // have a redundant (but now useless) copy of the data
81  m_data->clear();
82  m_isValid = true;
83  m_isReadFromFile = true;
84 }
85 
86 bool TrackerHitCollection::setReferences(const podio::ICollectionProvider* collectionProvider) {
87 
88  return true; //TODO: check success
89 }
90 
92  const int size = m_entries.size();
93  auto obj = object.m_obj;
94  if (obj->id.index == podio::ObjectID::untracked) {
95  obj->id = {size, m_collectionID};
96  m_entries.push_back(obj);
97 
98  } else {
99  throw std::invalid_argument("Object already in a collection. Cannot add it to a second collection");
100  }
101 }
102 
103 void TrackerHitCollection::setBuffer(void* address) {
104  if (m_data) delete m_data;
105  m_data = static_cast<TrackerHitDataContainer*>(address);
106 }
107 
109  m_object.m_obj = (*m_collection)[m_index];
110  return m_object;
111 }
112 
114  m_object.m_obj = (*m_collection)[m_index];
115  return &m_object;
116 }
117 
119  ++m_index;
120  return *this;
121 }
122 
123 std::ostream& operator<<(std::ostream& o, const TrackerHitCollection& v) {
124  const auto old_flags = o.flags();
125  o << " id: cellID: flag: g4ID: position [ x, y, z, t]: momentum [ x, y, z, t]: length: truth [ trackID, pdgID, deposit, time, length, x, y, z]:energyDeposit:" << '\n';
126 
127  for (size_t i = 0; i < v.size(); ++i) {
128  o << std::scientific << std::showpos << std::setw(12) << v[i].id() << " "
129  << std::setw(12) << v[i].cellID() << " "
130  << std::setw(12) << v[i].flag() << " "
131  << std::setw(12) << v[i].g4ID() << " "
132  << std::setw(12) << v[i].position() << " "
133  << std::setw(12) << v[i].momentum() << " "
134  << std::setw(12) << v[i].length() << " "
135  << std::setw(12) << v[i].truth() << " "
136  << std::setw(12) << v[i].energyDeposit() << " "
137  << std::endl;
138 
139 
140 
141 
142  }
143 
144  o.flags(old_flags);
145  return o;
146 }
147 
148 } // namespace dd4pod
149 
void push_back(ConstTrackerHit object)
Append object to the collection.
const std::array< long, arraysize > g4ID() const
const std::array< dd4pod::FourVector, arraysize > momentum() const
const std::array< long long, arraysize > cellID() const
const TrackerHitCollectionIterator & operator++() const
const std::array< dd4pod::MonteCarloContrib, arraysize > truth() const
A Collection is identified by an ID.
const TrackerHit at(unsigned int index) const
Returns the const object of given index.
const std::array< double, arraysize > length() const
const std::array< long, arraysize > flag() const
bool setReferences(const podio::ICollectionProvider *collectionProvider) override final
void prepareForWrite() override final
size_t size() const override final
number of elements in the collection
TrackerHit create()
Append a new object to the collection, and return this object.
void setBuffer(void *address) override final
std::vector< TrackerHitData > TrackerHitDataContainer
std::ostream & operator<<(std::ostream &o, const ConstCalorimeterHit &value)
const TrackerHit operator[](unsigned int index) const
Returns the const object of given index.
const std::array< double, arraysize > energyDeposit() const
void prepareAfterRead() override final
const std::array< dd4pod::FourVector, arraysize > position() const