File indexing completed on 2024-11-15 09:50:09
0001 #ifndef PODIO_COLLECTIONBUFFERS_H
0002 #define PODIO_COLLECTIONBUFFERS_H
0003
0004 #include "podio/ObjectID.h"
0005 #include "podio/SchemaEvolution.h"
0006
0007 #include <functional>
0008 #include <memory>
0009 #include <string>
0010 #include <string_view>
0011 #include <utility>
0012 #include <vector>
0013
0014 namespace podio {
0015
0016 class CollectionBase;
0017
0018 template <typename T>
0019 using UVecPtr = std::unique_ptr<std::vector<T>>;
0020
0021 using CollRefCollection = std::vector<UVecPtr<podio::ObjectID>>;
0022 using VectorMembersInfo = std::vector<std::pair<std::string, void*>>;
0023
0024
0025
0026
0027
0028 struct CollectionWriteBuffers {
0029 void* data{nullptr};
0030 void* vecPtr{nullptr};
0031 CollRefCollection* references{nullptr};
0032 VectorMembersInfo* vectorMembers{nullptr};
0033
0034 template <typename DataT>
0035 std::vector<DataT>* dataAsVector() {
0036 return asVector<DataT>(data);
0037 }
0038
0039 template <typename T>
0040 static std::vector<T>* asVector(void* raw) {
0041
0042 return *static_cast<std::vector<T>**>(raw);
0043 }
0044 };
0045
0046 struct CollectionReadBuffers {
0047 void* data{nullptr};
0048 CollRefCollection* references{nullptr};
0049 VectorMembersInfo* vectorMembers{nullptr};
0050 SchemaVersionT schemaVersion{0};
0051 std::string_view type{};
0052
0053 using CreateFuncT = std::function<std::unique_ptr<podio::CollectionBase>(podio::CollectionReadBuffers, bool)>;
0054 using RecastFuncT = std::function<void(CollectionReadBuffers&)>;
0055
0056 using DeleteFuncT = std::function<void(CollectionReadBuffers&)>;
0057
0058 CollectionReadBuffers(void* d, CollRefCollection* ref, VectorMembersInfo* vec, SchemaVersionT version,
0059 std::string_view typ, CreateFuncT&& createFunc, RecastFuncT&& recastFunc,
0060 DeleteFuncT&& deleteFunc) :
0061 data(d),
0062 references(ref),
0063 vectorMembers(vec),
0064 schemaVersion(version),
0065 type(typ),
0066 createCollection(std::move(createFunc)),
0067 recast(std::move(recastFunc)),
0068 deleteBuffers(std::move(deleteFunc)) {
0069 }
0070
0071 CollectionReadBuffers() = default;
0072 CollectionReadBuffers(const CollectionReadBuffers&) = default;
0073 CollectionReadBuffers& operator=(const CollectionReadBuffers&) = default;
0074
0075 CollectionReadBuffers(CollectionWriteBuffers buffers) :
0076 data(buffers.data), references(buffers.references), vectorMembers(buffers.vectorMembers) {
0077 }
0078
0079 template <typename DataT>
0080 std::vector<DataT>* dataAsVector() {
0081 return asVector<DataT>(data);
0082 }
0083
0084 template <typename T>
0085 static std::vector<T>* asVector(void* raw) {
0086
0087 return static_cast<std::vector<T>*>(raw);
0088 }
0089
0090 CreateFuncT createCollection{};
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 RecastFuncT recast{};
0112
0113
0114
0115
0116 DeleteFuncT deleteBuffers{};
0117 };
0118
0119 }
0120
0121 #endif