1#ifndef PODIO_SIOBLOCK_H
2#define PODIO_SIOBLOCK_H
8#include <podio/podioVersion.h>
12#include <sio/io_device.h>
13#include <sio/version.h>
24template <
typename devT,
typename PODData>
26 unsigned count = size *
sizeof(PODData);
27 char* dataPtr =
reinterpret_cast<char*
>(data);
28 device.data(dataPtr, count);
32template <
typename MapLikeT>
34 device.data((
int)map.size());
35 for (
const auto& [key, value] : map) {
42template <
typename MapLikeT>
51 if constexpr (podio::detail::isVector<MapLikeT>) {
52 map.emplace_back(std::move(key), std::move(value));
54 map.emplace(std::move(key), std::move(value));
63 SIOBlock(
const std::string& nam, sio::version_type vers) : sio::block(nam, vers) {
78 return sio::block::name();
107 std::vector<short>&& isSubsetColl) :
108 sio::block(
"CollectionIDs", sio::version::encode_version(0, 3)),
109 _names(std::move(names)),
110 _ids(std::move(ids)),
111 _types(std::move(types)),
112 _isSubsetColl(std::move(isSubsetColl)) {
118 void read(sio::read_device& device, sio::version_type version)
override;
119 void write(sio::write_device& device)
override;
128 return _isSubsetColl;
132 std::vector<std::string> _names{};
133 std::vector<int> _ids{};
134 std::vector<std::string> _types{};
135 std::vector<short> _isSubsetColl{};
143 sio::block(
"podio_version", sio::
version::encode_version(1, 0)),
version(v) {
146 void write(sio::write_device& device)
override {
150 void read(sio::read_device& device, sio::version_type)
override {
168 void read(sio::read_device& device, sio::version_type version)
override;
169 void write(sio::write_device& device)
override;
179template <
typename KeyT,
typename ValueT>
181 SIOMapBlock() : sio::block(
"SIOMapBlock", sio::version::encode_version(0, 1)) {
184 sio::block(
"SIOMapBlock", sio::version::encode_version(0, 1)),
mapData(std::move(data)) {
190 void read(sio::read_device& device, sio::version_type)
override {
193 void write(sio::write_device& device)
override {
197 std::vector<std::tuple<KeyT, ValueT>>
mapData{};
211 void read(sio::read_device& device, sio::version_type version)
override;
212 void write(sio::write_device& device)
override;
214 std::map<int, GenericParameters>*
data{
nullptr};
222 typedef std::map<std::string, SIOBlock*> BlockMap;
233 std::shared_ptr<SIOBlock>
createBlock(
const std::string& typeStr,
const std::string& name,
234 const bool isRefColl =
false)
const;
247 enum class LoadStatus :
short { Success = 0, AlreadyLoaded = 1, Error = 2 };
252 LoadStatus loadLib(
const std::string& libname);
258 static std::vector<std::tuple<std::string, std::string>> getLibNames();
260 std::map<std::string, void*> _loadedLibs{};
269namespace sio_helpers {
271 static constexpr uint32_t SIOTocMarker = 0xc001fea7;
274 static constexpr int SIOTocInfoSize =
sizeof(uint64_t);
276 static constexpr const char* SIOTocRecordName =
"podio_SIO_TOC_Record";
279 static constexpr const char* SIOEDMDefinitionName =
"podio_SIO_EDMDefinitions";
306 using RecordListType = std::pair<std::string, std::vector<PositionType>>;
307 using MapType = std::vector<RecordListType>;
309 MapType m_recordMap{};
317 sio::block(sio_helpers::SIOTocRecordName, sio::version::encode_version(0, 1)),
record(r) {
323 void read(sio::read_device& device, sio::version_type version)
override;
324 void write(sio::write_device& device)
override;
virtual bool isSubsetCollection() const =0
check if this collection is a subset collection
virtual podio::CollectionWriteBuffers getBuffers()=0
Get the collection buffers for this collection.
factory for creating sio::blocks for a given type of EDM-collection
void registerBlockForCollection(const std::string &type, SIOBlock *b)
static SIOBlockFactory & instance()
std::shared_ptr< SIOBlock > createBlock(const podio::CollectionBase *col, const std::string &name) const
static SIOBlockLibraryLoader & instance()
Base class for sio::block handlers used with PODIO.
podio::CollectionBase * getCollection()
virtual SIOBlock * create(const std::string &name) const =0
virtual void createBuffers(const bool subsetCollection=false)=0
podio::CollectionReadBuffers getBuffers() const
SIOBlock(const std::string &nam, sio::version_type vers)
SIOBlock(const SIOBlock &)=delete
podio::CollectionReadBuffers m_buffers
SIOBlock & operator=(const SIOBlock &)=delete
void setCollection(podio::CollectionBase *col)
SIOCollectionIDTableBlock()
SIOCollectionIDTableBlock(const SIOCollectionIDTableBlock &)=delete
SIOCollectionIDTableBlock & operator=(const SIOCollectionIDTableBlock &)=delete
const std::vector< std::string > & getTypeNames() const
void write(sio::write_device &device) override
SIOCollectionIDTableBlock(std::vector< std::string > &&names, std::vector< int > &&ids, std::vector< std::string > &&types, std::vector< short > &&isSubsetColl)
const std::vector< short > & getSubsetCollectionBits() const
podio::CollectionIDTable * getTable()
void read(sio::read_device &device, sio::version_type version) override
PositionType getPosition(const std::string &name, unsigned iEntry=0) const
size_t getNRecords(const std::string &name) const
sio_helpers::position_type PositionType
std::vector< std::string_view > getRecordNames() const
void addRecord(const std::string &name, PositionType startPos)
typename MapLikeTypeHelper< T >::mapped_type GetMappedType
typename MapLikeTypeHelper< T >::key_type GetKeyType
void readMapLike(sio::read_device &device, MapLikeT &map)
Read anything that iterates like an std::map.
void handlePODDataSIO(devT &device, PODData *data, size_t size)
void writeMapLike(sio::write_device &device, const MapLikeT &map)
Write anything that iterates like an std::map.
CreateFuncT createCollection
SIOFileTOCRecordBlock(const SIOFileTOCRecordBlock &)=delete
void read(sio::read_device &device, sio::version_type version) override
void write(sio::write_device &device) override
SIOFileTOCRecordBlock(SIOFileTOCRecord *r)
SIOFileTOCRecord * record
SIOFileTOCRecordBlock & operator=(const SIOFileTOCRecordBlock &)=delete
void write(sio::write_device &device) override
SIOMapBlock & operator=(const SIOMapBlock &)=delete
SIOMapBlock(const SIOMapBlock &)=delete
void read(sio::read_device &device, sio::version_type) override
SIOMapBlock(std::vector< std::tuple< KeyT, ValueT > > &&data)
std::vector< std::tuple< KeyT, ValueT > > mapData
SIOVersionBlock(podio::version::Version v)
void read(sio::read_device &device, sio::version_type) override
void write(sio::write_device &device) override
podio::version::Version version