EICd
EIC data model
TrackSegmentCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_TrackSegmentCollection_H
4#define EICD_TrackSegmentCollection_H
5
6// datamodel specific includes
8#include "eicd/TrackSegment.h"
12
13// podio specific includes
14#include "podio/ICollectionProvider.h"
15#include "podio/CollectionBase.h"
16#include "podio/CollectionIDTable.h"
17
18#ifdef PODIO_JSON_OUTPUT
19#include "nlohmann/json.hpp"
20#endif
21
22#include <string>
23#include <vector>
24#include <deque>
25#include <array>
26#include <algorithm>
27#include <ostream>
28#include <mutex>
29#include <memory>
30
31namespace eicd {
32
33
34
36public:
37 TrackSegmentCollectionIterator(size_t index, const TrackSegmentObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
38
41
43 return m_index != x.m_index; // TODO: may not be complete
44 }
45
49
50private:
51 size_t m_index;
52 TrackSegment m_object;
53 const TrackSegmentObjPointerContainer* m_collection;
54};
55
56
58public:
59 TrackSegmentMutableCollectionIterator(size_t index, const TrackSegmentObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
60
63
65 return m_index != x.m_index; // TODO: may not be complete
66 }
67
71
72private:
73 size_t m_index;
74 MutableTrackSegment m_object;
75 const TrackSegmentObjPointerContainer* m_collection;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class TrackSegmentCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// TrackSegmentCollection(TrackSegmentVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
100 TrackSegmentCollection* operator->() { return (TrackSegmentCollection*) this; }
101
102 /// Append a new object to the collection, and return this object.
104
105 /// Append a new object to the collection, and return this object.
106 /// Initialized with the parameters given
107 template<typename... Args>
108 MutableTrackSegment create(Args&&... args);
109
110 /// number of elements in the collection
111 size_t size() const final;
112
113 /// fully qualified type name
114 std::string getTypeName() const final { return std::string("eicd::TrackSegmentCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::TrackSegment"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::TrackSegmentData"); }
119
120 bool isSubsetCollection() const final {
121 return m_isSubsetColl;
122 }
123
124 void setSubsetCollection(bool setSubset=true) final;
125
126 /// Returns the const object of given index
127 TrackSegment operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableTrackSegment operator[](unsigned int index);
130 /// Returns the const object of given index
131 TrackSegment at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableTrackSegment at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(TrackSegment object);
138
139 void prepareForWrite() const final;
140 void prepareAfterRead() final;
141 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
142
143 /// Get the collection buffers for this collection
144 podio::CollectionBuffers getBuffers() final;
145
146 void setID(unsigned ID) final {
147 m_collectionID = ID;
148 if (!m_isSubsetColl) {
149 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
150 [ID] (TrackSegmentObj* obj) { obj->id = {obj->id.index, static_cast<int>(ID)}; }
151 );
152 }
153 m_isValid = true;
154 };
155
156 unsigned getID() const final {
157 return m_collectionID;
158 }
159
160 bool isValid() const final {
161 return m_isValid;
162 }
163
164 // support for the iterator protocol
166 return iterator(0, &m_storage.entries);
167 }
169 return const_iterator(0, &m_storage.entries);
170 }
172 return iterator(m_storage.entries.size(), &m_storage.entries);
173 }
175 return const_iterator(m_storage.entries.size(), &m_storage.entries);
176 }
177
178 template<size_t arraysize>
179 const std::array<float, arraysize> length() const;
180 template<size_t arraysize>
181 const std::array<float, arraysize> lengthError() const;
182
183private:
184 // For setReferences, we need to give our own CollectionData access to our
185 // private entries. Otherwise we would need to expose a public member function
186 // that gives access to the Obj* which is definitely not what we want
188
189 bool m_isValid{false};
190 mutable bool m_isPrepared{false};
191 bool m_isSubsetColl{false};
192 int m_collectionID{0};
193 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
194 mutable TrackSegmentCollectionData m_storage{};
195};
196
197std::ostream& operator<<(std::ostream& o, const TrackSegmentCollection& v);
198
199template<typename... Args>
200MutableTrackSegment TrackSegmentCollection::create(Args&&... args) {
201 if (m_isSubsetColl) {
202 throw std::logic_error("Cannot create new elements on a subset collection");
203 }
204 const int size = m_storage.entries.size();
205 auto obj = new TrackSegmentObj({size, m_collectionID}, {std::forward<Args>(args)...});
206 m_storage.entries.push_back(obj);
207
208 // Need to initialize the relation vectors manually for the {ObjectID, TrackSegmentData} constructor
209 obj->m_points = new std::vector<eicd::TrackPoint>();
210 m_storage.createRelations(obj);
211 return MutableTrackSegment(obj);
212}
213
214template<size_t arraysize>
215const std::array<float, arraysize> TrackSegmentCollection::length() const {
216 std::array<float, arraysize> tmp{};
217 const auto valid_size = std::min(arraysize, m_storage.entries.size());
218 for (unsigned i = 0; i < valid_size; ++i) {
219 tmp[i] = m_storage.entries[i]->data.length;
220 }
221 return tmp;
222}
223
224template<size_t arraysize>
225const std::array<float, arraysize> TrackSegmentCollection::lengthError() const {
226 std::array<float, arraysize> tmp{};
227 const auto valid_size = std::min(arraysize, m_storage.entries.size());
228 for (unsigned i = 0; i < valid_size; ++i) {
229 tmp[i] = m_storage.entries[i]->data.lengthError;
230 }
231 return tmp;
232}
233
234
235#ifdef PODIO_JSON_OUTPUT
236void to_json(nlohmann::json& j, const TrackSegmentCollection& collection);
237#endif
238
239} // namespace eicd
240
241
242#endif
Definition: MutableTrackSegment.h:34
Definition: TrackSegmentCollectionData.h:29
TrackSegmentObjPointerContainer entries
Definition: TrackSegmentCollectionData.h:34
Definition: TrackSegmentCollection.h:82
std::string getTypeName() const final
fully qualified type name
Definition: TrackSegmentCollection.h:114
TrackSegmentCollection()
Definition: TrackSegmentCollection.cc:15
TrackSegmentCollection & operator=(TrackSegmentCollection &&)=default
unsigned getID() const final
Definition: TrackSegmentCollection.h:156
TrackSegment at(unsigned int index) const
Returns the const object of given index.
Definition: TrackSegmentCollection.cc:27
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: TrackSegmentCollection.cc:137
iterator begin()
Definition: TrackSegmentCollection.h:165
~TrackSegmentCollection()
Definition: TrackSegmentCollection.cc:18
TrackSegmentCollection(TrackSegmentCollection &&)=default
MutableTrackSegment create()
Append a new object to the collection, and return this object.
Definition: TrackSegmentCollection.cc:54
void push_back(TrackSegment object)
Append object to the collection.
Definition: TrackSegmentCollection.cc:111
bool isValid() const final
Definition: TrackSegmentCollection.h:160
const_iterator end() const
Definition: TrackSegmentCollection.h:174
size_t size() const final
number of elements in the collection
Definition: TrackSegmentCollection.cc:39
void clear() final
Definition: TrackSegmentCollection.cc:66
iterator end()
Definition: TrackSegmentCollection.h:171
void prepareForWrite() const final
Definition: TrackSegmentCollection.cc:71
bool isSubsetCollection() const final
Definition: TrackSegmentCollection.h:120
void prepareAfterRead() final
Definition: TrackSegmentCollection.cc:92
void setSubsetCollection(bool setSubset=true) final
Definition: TrackSegmentCollection.cc:43
const_iterator begin() const
Definition: TrackSegmentCollection.h:168
void setID(unsigned ID) final
Definition: TrackSegmentCollection.h:146
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: TrackSegmentCollection.cc:107
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: TrackSegmentCollection.h:116
TrackSegmentCollection & operator=(const TrackSegmentCollection &)=delete
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: TrackSegmentCollection.h:118
TrackSegmentCollection(const TrackSegmentCollection &)=delete
Definition: TrackSegmentCollection.h:35
TrackSegmentCollectionIterator & operator=(const TrackSegmentCollectionIterator &)=delete
TrackSegmentCollectionIterator(const TrackSegmentCollectionIterator &)=delete
TrackSegment operator*()
Definition: TrackSegmentCollection.cc:151
bool operator!=(const TrackSegmentCollectionIterator &x) const
Definition: TrackSegmentCollection.h:42
TrackSegment * operator->()
Definition: TrackSegmentCollection.cc:156
TrackSegmentCollectionIterator(size_t index, const TrackSegmentObjPointerContainer *collection)
Definition: TrackSegmentCollection.h:37
TrackSegmentCollectionIterator & operator++()
Definition: TrackSegmentCollection.cc:161
Definition: TrackSegment.h:33
Definition: TrackSegmentCollection.h:57
TrackSegmentMutableCollectionIterator(size_t index, const TrackSegmentObjPointerContainer *collection)
Definition: TrackSegmentCollection.h:59
TrackSegmentMutableCollectionIterator & operator++()
Definition: TrackSegmentCollection.cc:178
TrackSegmentMutableCollectionIterator & operator=(const TrackSegmentMutableCollectionIterator &)=delete
TrackSegmentMutableCollectionIterator(const TrackSegmentMutableCollectionIterator &)=delete
bool operator!=(const TrackSegmentMutableCollectionIterator &x) const
Definition: TrackSegmentCollection.h:64
MutableTrackSegment operator*()
Definition: TrackSegmentCollection.cc:168
MutableTrackSegment * operator->()
Definition: TrackSegmentCollection.cc:173
Definition: TrackSegmentObj.h:23
std::vector< eicd::TrackPoint > * m_points
Definition: TrackSegmentObj.h:39
Definition: CalorimeterHit.cc:13
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93
std::deque< TrackSegmentObj * > TrackSegmentObjPointerContainer
Definition: TrackSegmentCollectionData.h:21