File indexing completed on 2025-01-18 09:28:06
0001
0002
0003 #ifndef ACTSPODIOEDM_TrackStateCollection_H
0004 #define ACTSPODIOEDM_TrackStateCollection_H
0005
0006
0007 #include "ActsPodioEdm/MutableTrackState.h"
0008 #include "ActsPodioEdm/TrackState.h"
0009 #include "ActsPodioEdm/TrackStateCollectionData.h"
0010 #include "ActsPodioEdm/TrackStateObj.h"
0011
0012
0013 #include "podio/CollectionBase.h"
0014 #include "podio/ICollectionProvider.h"
0015
0016 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0017 #include "nlohmann/json_fwd.hpp"
0018 #endif
0019
0020 #include <algorithm>
0021 #include <array>
0022 #include <cstddef>
0023 #include <memory>
0024 #include <mutex>
0025 #include <ostream>
0026 #include <string_view>
0027 #include <vector>
0028
0029 namespace podio {
0030 struct RelationNames;
0031 }
0032
0033 namespace ActsPodioEdm {
0034
0035 class TrackStateCollectionIterator {
0036 public:
0037 TrackStateCollectionIterator(size_t index,
0038 const TrackStateObjPointerContainer* collection)
0039 : m_index(index),
0040 m_object(podio::utils::MaybeSharedPtr<TrackStateObj>{nullptr}),
0041 m_collection(collection) {}
0042
0043 TrackStateCollectionIterator(const TrackStateCollectionIterator&) = delete;
0044 TrackStateCollectionIterator& operator=(const TrackStateCollectionIterator&) =
0045 delete;
0046
0047 bool operator!=(const TrackStateCollectionIterator& x) const {
0048 return m_index != x.m_index;
0049 }
0050
0051 bool operator==(const TrackStateCollectionIterator& x) const {
0052 return m_index == x.m_index;
0053 }
0054
0055 TrackState operator*();
0056 TrackState* operator->();
0057 TrackStateCollectionIterator& operator++();
0058
0059 private:
0060 size_t m_index;
0061 TrackState m_object;
0062 const TrackStateObjPointerContainer* m_collection;
0063 };
0064
0065 class TrackStateMutableCollectionIterator {
0066 public:
0067 TrackStateMutableCollectionIterator(
0068 size_t index, const TrackStateObjPointerContainer* collection)
0069 : m_index(index),
0070 m_object(podio::utils::MaybeSharedPtr<TrackStateObj>{nullptr}),
0071 m_collection(collection) {}
0072
0073 TrackStateMutableCollectionIterator(
0074 const TrackStateMutableCollectionIterator&) = delete;
0075 TrackStateMutableCollectionIterator& operator=(
0076 const TrackStateMutableCollectionIterator&) = delete;
0077
0078 bool operator!=(const TrackStateMutableCollectionIterator& x) const {
0079 return m_index != x.m_index;
0080 }
0081
0082 bool operator==(const TrackStateMutableCollectionIterator& x) const {
0083 return m_index == x.m_index;
0084 }
0085
0086 MutableTrackState operator*();
0087 MutableTrackState* operator->();
0088 TrackStateMutableCollectionIterator& operator++();
0089
0090 private:
0091 size_t m_index;
0092 MutableTrackState m_object;
0093 const TrackStateObjPointerContainer* m_collection;
0094 };
0095
0096
0097
0098
0099 class TrackStateCollection : public podio::CollectionBase {
0100 public:
0101 using value_type = TrackState;
0102 using const_iterator = TrackStateCollectionIterator;
0103 using iterator = TrackStateMutableCollectionIterator;
0104 using difference_type = ptrdiff_t;
0105 using size_type = size_t;
0106
0107 TrackStateCollection();
0108 TrackStateCollection(TrackStateCollectionData&& data, bool isSubsetColl);
0109
0110 TrackStateCollection(const TrackStateCollection&) = delete;
0111 TrackStateCollection& operator=(const TrackStateCollection&) = delete;
0112 TrackStateCollection(TrackStateCollection&&) = default;
0113 TrackStateCollection& operator=(TrackStateCollection&&) = default;
0114
0115
0116 ~TrackStateCollection();
0117
0118 constexpr static auto typeName = "ActsPodioEdm::TrackStateCollection";
0119 constexpr static auto valueTypeName = "ActsPodioEdm::TrackState";
0120 constexpr static auto dataTypeName = "ActsPodioEdm::TrackStateData";
0121
0122 void clear() final;
0123
0124
0125 void print(std::ostream& os = std::cout, bool flush = true) const final;
0126
0127
0128 TrackStateCollection* operator->() {
0129 return static_cast<TrackStateCollection*>(this);
0130 }
0131
0132
0133 MutableTrackState create();
0134
0135
0136
0137 template <typename... Args>
0138 MutableTrackState create(Args&&... args);
0139
0140
0141 std::size_t size() const final;
0142
0143
0144 std::size_t max_size() const final;
0145
0146
0147 bool empty() const final;
0148
0149
0150 const std::string_view getTypeName() const final { return typeName; }
0151
0152 const std::string_view getValueTypeName() const final {
0153 return valueTypeName;
0154 }
0155
0156 const std::string_view getDataTypeName() const final { return dataTypeName; }
0157
0158 podio::SchemaVersionT getSchemaVersion() const final;
0159
0160 bool isSubsetCollection() const final { return m_isSubsetColl; }
0161
0162 void setSubsetCollection(bool setSubset = true) final;
0163
0164
0165 TrackState operator[](std::size_t index) const;
0166
0167 MutableTrackState operator[](std::size_t index);
0168
0169 TrackState at(std::size_t index) const;
0170
0171 MutableTrackState at(std::size_t index);
0172
0173
0174 void push_back(const MutableTrackState& object);
0175
0176 void push_back(const TrackState& object);
0177
0178 void prepareForWrite() const final;
0179 void prepareAfterRead() final;
0180 bool setReferences(
0181 const podio::ICollectionProvider* collectionProvider) final;
0182
0183
0184 podio::CollectionWriteBuffers getBuffers() final;
0185
0186 void setID(uint32_t ID) final {
0187 m_collectionID = ID;
0188 if (!m_isSubsetColl) {
0189 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0190 [ID](TrackStateObj* obj) {
0191 obj->id = {obj->id.index, static_cast<uint32_t>(ID)};
0192 });
0193 }
0194 m_isValid = true;
0195 }
0196
0197 uint32_t getID() const final { return m_collectionID; }
0198
0199 bool isValid() const final { return m_isValid; }
0200
0201 size_t getDatamodelRegistryIndex() const final;
0202
0203
0204 iterator begin() { return iterator(0, &m_storage.entries); }
0205 const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0206 const_iterator cbegin() const { return begin(); }
0207 iterator end() {
0208 return iterator(m_storage.entries.size(), &m_storage.entries);
0209 }
0210 const_iterator end() const {
0211 return const_iterator(m_storage.entries.size(), &m_storage.entries);
0212 }
0213 const_iterator cend() const { return end(); }
0214
0215 std::vector<ActsPodioEdm::TrackStateInfo> data(const size_t nElem = 0) const;
0216 std::vector<ActsPodioEdm::Surface> referenceSurface(
0217 const size_t nElem = 0) const;
0218
0219 private:
0220
0221
0222
0223 friend class TrackStateCollectionData;
0224
0225 bool m_isValid{false};
0226 mutable bool m_isPrepared{false};
0227 bool m_isSubsetColl{false};
0228 uint32_t m_collectionID{0};
0229 mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
0230 mutable TrackStateCollectionData m_storage{};
0231 };
0232
0233 std::ostream& operator<<(std::ostream& o, const TrackStateCollection& v);
0234
0235 template <typename... Args>
0236 MutableTrackState TrackStateCollection::create(Args&&... args) {
0237 if (m_isSubsetColl) {
0238 throw std::logic_error("Cannot create new elements on a subset collection");
0239 }
0240 const int size = m_storage.entries.size();
0241 auto obj =
0242 new TrackStateObj({size, m_collectionID}, {std::forward<Args>(args)...});
0243 m_storage.entries.push_back(obj);
0244
0245 return MutableTrackState(podio::utils::MaybeSharedPtr(obj));
0246 }
0247
0248 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0249 void to_json(nlohmann::json& j, const TrackStateCollection& collection);
0250 #endif
0251
0252 }
0253
0254 #endif