PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
SIOBlockUserData.h
Go to the documentation of this file.
1#ifndef PODIO_SIOBLOCKUSERDATA_H
2#define PODIO_SIOBLOCKUSERDATA_H
3
5#include "podio/SIOBlock.h"
7
8#include <sio/api.h>
9#include <sio/io_device.h>
10#include <sio/version.h>
11
12#include <algorithm>
13#include <string>
14#include <typeindex>
15
16namespace {
17
18/// helper function to get valid sio block names
19template <typename BasicType, typename = podio::EnableIfSupportedUserType<BasicType>>
20inline std::string sio_name() {
21 std::string s = podio::userDataTypeName<BasicType>();
22 std::replace(s.begin(), s.end(), ' ', '_');
23 return s;
24}
25} // namespace
26
27namespace podio {
28
29template <typename BasicType, typename = EnableIfSupportedUserType<BasicType>>
31public:
32 SIOBlockUserData() : SIOBlock(::sio_name<BasicType>(), sio::version::encode_version(0, 1)) {
33
34 podio::SIOBlockFactory::instance().registerBlockForCollection(podio::userDataTypeName<BasicType>(), this);
35 }
36
37 SIOBlockUserData(const std::string& name) : SIOBlock(name, sio::version::encode_version(0, 1)) {
38 }
39
40 void read(sio::read_device& device, sio::version_type /*version*/) override {
41 auto* dataVec = new std::vector<BasicType>();
42 unsigned size(0);
43 device.data(size);
44 dataVec->resize(size);
45 podio::handlePODDataSIO(device, &(*dataVec)[0], size);
46 m_buffers.data = dataVec;
47 }
48
49 void write(sio::write_device& device) override {
50 auto* dataVec = podio::CollectionWriteBuffers::asVector<BasicType>(m_buffers.data);
51 unsigned size = dataVec->size();
52 device.data(size);
53 podio::handlePODDataSIO(device, &(*dataVec)[0], size);
54 }
55
56 void createBuffers(bool) override {
57
60
61 // Nothing to do here since UserDataCollections cannot be subset collections
63 return std::make_unique<UserDataCollection<BasicType>>(std::move(*buffers.dataAsVector<BasicType>()));
64 };
65 }
66
67 SIOBlock* create(const std::string& name) const override {
68 return new SIOBlockUserData(name);
69 }
70
71private:
72};
73
74} // namespace podio
75#endif
void registerBlockForCollection(const std::string &type, SIOBlock *b)
Definition: SIOBlock.h:226
static SIOBlockFactory & instance()
Definition: SIOBlock.h:236
SIOBlockUserData(const std::string &name)
SIOBlock * create(const std::string &name) const override
void read(sio::read_device &device, sio::version_type) override
void createBuffers(bool) override
void write(sio::write_device &device) override
Base class for sio::block handlers used with PODIO.
Definition: SIOBlock.h:60
std::string name()
Definition: SIOBlock.h:77
podio::CollectionReadBuffers m_buffers
Definition: SIOBlock.h:93
std::vector< std::pair< std::string, void * > > VectorMembersInfo
std::vector< UVecPtr< podio::ObjectID > > CollRefCollection
void handlePODDataSIO(devT &device, PODData *data, size_t size)
Definition: SIOBlock.h:25
CollRefCollection * references
std::vector< DataT > * dataAsVector()
VectorMembersInfo * vectorMembers