EICd
EIC data model
ProtoClusterCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_ProtoClusterCollection_H
4#define EICD_ProtoClusterCollection_H
5
6// datamodel specific includes
8#include "eicd/ProtoCluster.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 ProtoClusterCollectionIterator(size_t index, const ProtoClusterObjPointerContainer* 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 ProtoCluster m_object;
53 const ProtoClusterObjPointerContainer* m_collection;
54};
55
56
58public:
59 ProtoClusterMutableCollectionIterator(size_t index, const ProtoClusterObjPointerContainer* 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 MutableProtoCluster m_object;
75 const ProtoClusterObjPointerContainer* m_collection;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class ProtoClusterCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// ProtoClusterCollection(ProtoClusterVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
100 ProtoClusterCollection* operator->() { return (ProtoClusterCollection*) 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 MutableProtoCluster 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::ProtoClusterCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::ProtoCluster"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::ProtoClusterData"); }
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 ProtoCluster operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableProtoCluster operator[](unsigned int index);
130 /// Returns the const object of given index
131 ProtoCluster at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableProtoCluster at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(ProtoCluster 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] (ProtoClusterObj* 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
179private:
180 // For setReferences, we need to give our own CollectionData access to our
181 // private entries. Otherwise we would need to expose a public member function
182 // that gives access to the Obj* which is definitely not what we want
184
185 bool m_isValid{false};
186 mutable bool m_isPrepared{false};
187 bool m_isSubsetColl{false};
188 int m_collectionID{0};
189 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
190 mutable ProtoClusterCollectionData m_storage{};
191};
192
193std::ostream& operator<<(std::ostream& o, const ProtoClusterCollection& v);
194
195template<typename... Args>
196MutableProtoCluster ProtoClusterCollection::create(Args&&... args) {
197 if (m_isSubsetColl) {
198 throw std::logic_error("Cannot create new elements on a subset collection");
199 }
200 const int size = m_storage.entries.size();
201 auto obj = new ProtoClusterObj({size, m_collectionID}, {std::forward<Args>(args)...});
202 m_storage.entries.push_back(obj);
203
204 // Need to initialize the relation vectors manually for the {ObjectID, ProtoClusterData} constructor
205 obj->m_hits = new std::vector<eicd::CalorimeterHit>();
206 obj->m_weights = new std::vector<float>();
207 m_storage.createRelations(obj);
208 return MutableProtoCluster(obj);
209}
210
211
212#ifdef PODIO_JSON_OUTPUT
213void to_json(nlohmann::json& j, const ProtoClusterCollection& collection);
214#endif
215
216} // namespace eicd
217
218
219#endif
Definition: MutableProtoCluster.h:29
Definition: ProtoClusterCollectionData.h:29
ProtoClusterObjPointerContainer entries
Definition: ProtoClusterCollectionData.h:34
Definition: ProtoClusterCollection.h:82
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: ProtoClusterCollection.cc:107
bool isSubsetCollection() const final
Definition: ProtoClusterCollection.h:120
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: ProtoClusterCollection.h:118
ProtoCluster at(unsigned int index) const
Returns the const object of given index.
Definition: ProtoClusterCollection.cc:27
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: ProtoClusterCollection.cc:137
ProtoClusterCollection()
Definition: ProtoClusterCollection.cc:15
void setID(unsigned ID) final
Definition: ProtoClusterCollection.h:146
void setSubsetCollection(bool setSubset=true) final
Definition: ProtoClusterCollection.cc:43
const_iterator end() const
Definition: ProtoClusterCollection.h:174
void push_back(ProtoCluster object)
Append object to the collection.
Definition: ProtoClusterCollection.cc:111
std::string getTypeName() const final
fully qualified type name
Definition: ProtoClusterCollection.h:114
bool isValid() const final
Definition: ProtoClusterCollection.h:160
void prepareForWrite() const final
Definition: ProtoClusterCollection.cc:71
ProtoClusterCollection & operator=(ProtoClusterCollection &&)=default
void clear() final
Definition: ProtoClusterCollection.cc:66
ProtoClusterCollection(const ProtoClusterCollection &)=delete
iterator end()
Definition: ProtoClusterCollection.h:171
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: ProtoClusterCollection.h:116
MutableProtoCluster create()
Append a new object to the collection, and return this object.
Definition: ProtoClusterCollection.cc:54
void prepareAfterRead() final
Definition: ProtoClusterCollection.cc:92
ProtoClusterCollection(ProtoClusterCollection &&)=default
unsigned getID() const final
Definition: ProtoClusterCollection.h:156
iterator begin()
Definition: ProtoClusterCollection.h:165
size_t size() const final
number of elements in the collection
Definition: ProtoClusterCollection.cc:39
const_iterator begin() const
Definition: ProtoClusterCollection.h:168
ProtoClusterCollection & operator=(const ProtoClusterCollection &)=delete
~ProtoClusterCollection()
Definition: ProtoClusterCollection.cc:18
Definition: ProtoClusterCollection.h:35
ProtoCluster * operator->()
Definition: ProtoClusterCollection.cc:156
ProtoClusterCollectionIterator & operator=(const ProtoClusterCollectionIterator &)=delete
ProtoCluster operator*()
Definition: ProtoClusterCollection.cc:151
ProtoClusterCollectionIterator(size_t index, const ProtoClusterObjPointerContainer *collection)
Definition: ProtoClusterCollection.h:37
ProtoClusterCollectionIterator(const ProtoClusterCollectionIterator &)=delete
ProtoClusterCollectionIterator & operator++()
Definition: ProtoClusterCollection.cc:161
bool operator!=(const ProtoClusterCollectionIterator &x) const
Definition: ProtoClusterCollection.h:42
Definition: ProtoCluster.h:28
Definition: ProtoClusterCollection.h:57
MutableProtoCluster operator*()
Definition: ProtoClusterCollection.cc:168
ProtoClusterMutableCollectionIterator & operator++()
Definition: ProtoClusterCollection.cc:178
ProtoClusterMutableCollectionIterator(size_t index, const ProtoClusterObjPointerContainer *collection)
Definition: ProtoClusterCollection.h:59
MutableProtoCluster * operator->()
Definition: ProtoClusterCollection.cc:173
bool operator!=(const ProtoClusterMutableCollectionIterator &x) const
Definition: ProtoClusterCollection.h:64
ProtoClusterMutableCollectionIterator(const ProtoClusterMutableCollectionIterator &)=delete
ProtoClusterMutableCollectionIterator & operator=(const ProtoClusterMutableCollectionIterator &)=delete
Definition: ProtoClusterObj.h:19
std::vector< eicd::CalorimeterHit > * m_hits
Definition: ProtoClusterObj.h:34
Definition: CalorimeterHit.cc:13
std::deque< ProtoClusterObj * > ProtoClusterObjPointerContainer
Definition: ProtoClusterCollectionData.h:21
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93