CalorimeterHitCollection.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 CalorimeterHitDataContainer()) {
16 }
17 
19  clear();
20  if (m_data) delete m_data;
21 }
22 
23 const CalorimeterHit CalorimeterHitCollection::operator[](unsigned int index) const {
24  return CalorimeterHit(m_entries[index]);
25 }
26 
27 const CalorimeterHit CalorimeterHitCollection::at(unsigned int index) const {
28  return CalorimeterHit(m_entries.at(index));
29 }
30 
32  return CalorimeterHit(m_entries[index]);
33 }
34 
36  return CalorimeterHit(m_entries.at(index));
37 }
38 
40  return m_entries.size();
41 }
42 
44  auto obj = m_entries.emplace_back(new CalorimeterHitObj());
45 
46  obj->id = {int(m_entries.size() - 1), m_collectionID};
47  return CalorimeterHit(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 CalorimeterHitObj({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 CalorimeterHitCollection::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 
104  if (m_data) delete m_data;
105  m_data = static_cast<CalorimeterHitDataContainer*>(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 CalorimeterHitCollection& v) {
124  const auto old_flags = o.flags();
125  o << " id: cellID: flag: g4ID: position [ x, y, z, t]: 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].truth() << " "
134  << std::setw(12) << v[i].energyDeposit() << " "
135  << std::endl;
136 
137 
138 
139 
140  }
141 
142  o.flags(old_flags);
143  return o;
144 }
145 
146 } // namespace dd4pod
147 
void setBuffer(void *address) override final
CalorimeterHit create()
Append a new object to the collection, and return this object.
const std::array< long, arraysize > flag() const
const CalorimeterHit operator[](unsigned int index) const
Returns the const object of given index.
A Collection is identified by an ID.
const std::array< dd4pod::FourVector, arraysize > position() const
const std::array< long, arraysize > g4ID() const
bool setReferences(const podio::ICollectionProvider *collectionProvider) override final
std::vector< CalorimeterHitData > CalorimeterHitDataContainer
const CalorimeterHitCollectionIterator & operator++() const
size_t size() const override final
number of elements in the collection
const std::array< dd4pod::MonteCarloContrib, arraysize > truth() const
const std::array< long long, arraysize > cellID() const
const CalorimeterHit at(unsigned int index) const
Returns the const object of given index.
const std::array< double, arraysize > energyDeposit() const
void push_back(ConstCalorimeterHit object)
Append object to the collection.
std::ostream & operator<<(std::ostream &o, const ConstCalorimeterHit &value)