diff --git a/include/podio/SIOBlockUserData.h b/include/podio/SIOBlockUserData.h index 3deb5d193..2c2c5d275 100644 --- a/include/podio/SIOBlockUserData.h +++ b/include/podio/SIOBlockUserData.h @@ -1,6 +1,7 @@ #ifndef PODIO_SIOBLOCKUSERDATA_H #define PODIO_SIOBLOCKUSERDATA_H +#include "podio/CollectionBufferFactory.h" #include "podio/CollectionBuffers.h" #include "podio/SIOBlock.h" #include "podio/UserDataCollection.h" @@ -29,17 +30,22 @@ namespace podio { template > class SIOBlockUserData : public podio::SIOBlock { public: - SIOBlockUserData() : SIOBlock(::sio_name(), sio::version::encode_version(0, 1)) { + SIOBlockUserData() : + SIOBlock(::sio_name(), sio::version::encode_version(UserDataCollection::schemaVersion, 0)) { podio::SIOBlockFactory::instance().registerBlockForCollection(podio::userDataTypeName(), this); } - SIOBlockUserData(const std::string& name) : SIOBlock(name, sio::version::encode_version(0, 1)) { + SIOBlockUserData(const std::string& name) : + SIOBlock(name, sio::version::encode_version(UserDataCollection::schemaVersion, 0)) { } - void read(sio::read_device& device, sio::version_type /*version*/) override { + void read(sio::read_device& device, sio::version_type version) override { const auto& bufferFactory = podio::CollectionBufferFactory::instance(); - m_buffers = bufferFactory.createBuffers(podio::userDataCollTypeName(), 1, false).value(); + m_buffers = + bufferFactory + .createBuffers(podio::userDataCollTypeName(), sio::version::major_version(version), false) + .value(); auto* dataVec = new std::vector(); unsigned size(0); diff --git a/include/podio/UserDataCollection.h b/include/podio/UserDataCollection.h index b179e5953..78abda49a 100644 --- a/include/podio/UserDataCollection.h +++ b/include/podio/UserDataCollection.h @@ -2,9 +2,9 @@ #define PODIO_USERDATACOLLECTION_H #include "podio/CollectionBase.h" -#include "podio/CollectionBufferFactory.h" #include "podio/CollectionBuffers.h" #include "podio/DatamodelRegistry.h" +#include "podio/SchemaEvolution.h" #include "podio/utilities/TypeHelpers.h" #include @@ -90,6 +90,9 @@ class UserDataCollection : public CollectionBase { UserDataCollection& operator=(UserDataCollection&&) = default; ~UserDataCollection() = default; + /// The schema version of UserDataCollections + static constexpr SchemaVersionT schemaVersion = 1; + /// prepare buffers for serialization void prepareForWrite() const override { } @@ -160,7 +163,7 @@ class UserDataCollection : public CollectionBase { /// The schema version is fixed manually SchemaVersionT getSchemaVersion() const final { - return 1; + return schemaVersion; } /// Print this collection to the passed stream diff --git a/src/UserDataCollection.cc b/src/UserDataCollection.cc index c1035eaa8..71ea34d48 100644 --- a/src/UserDataCollection.cc +++ b/src/UserDataCollection.cc @@ -17,16 +17,17 @@ namespace { template int registerUserDataCollection(T) { // Register with schema version 1 to allow for potential changes - CollectionBufferFactory::mutInstance().registerCreationFunc(userDataCollTypeName(), 1, [](bool) { - return podio::CollectionReadBuffers{new std::vector(), nullptr, nullptr, - [](podio::CollectionReadBuffers buffers, bool) { - return std::make_unique>( - std::move(*buffers.dataAsVector())); - }, - [](podio::CollectionReadBuffers& buffers) { - buffers.data = podio::CollectionWriteBuffers::asVector(buffers.data); - }}; - }); + CollectionBufferFactory::mutInstance().registerCreationFunc( + userDataCollTypeName(), UserDataCollection::schemaVersion, [](bool) { + return podio::CollectionReadBuffers{new std::vector(), nullptr, nullptr, + [](podio::CollectionReadBuffers buffers, bool) { + return std::make_unique>( + std::move(*buffers.dataAsVector())); + }, + [](podio::CollectionReadBuffers& buffers) { + buffers.data = podio::CollectionWriteBuffers::asVector(buffers.data); + }}; + }); return 1; }