11#include "sio/compression/zlib.h"
22 m_stream.open(filename, std::ios::binary);
24 if (not m_stream.is_open()) {
25 SIO_THROW(sio::error_code::not_open,
"Couldn't open output stream '" + filename +
"'");
42 writeCollectionIDTable();
46 auto blocks = createBlocks();
50sio::block_list SIOWriter::createBlocks()
const {
51 sio::block_list blocks;
52 blocks.emplace_back(m_eventMetaData);
54 for (
const auto& name : m_collectionsToWrite) {
56 m_store->
get(name, col);
57 col->prepareForWrite();
66 sio::block_list blocks{};
67 blocks.push_back(m_runMetaData);
72 blocks.push_back(m_collectionMetaData);
73 m_tocRecord.
addRecord(m_collectionMetaData->name(),
77 auto tocRecordBlock = std::make_shared<SIOFileTOCRecordBlock>();
78 tocRecordBlock->record = &m_tocRecord;
79 blocks.push_back(tocRecordBlock);
85 uint64_t finalWords = (((uint64_t)sio_helpers::SIOTocMarker) << 32) | ((uint64_t)tocStartPos & 0xffffffff);
86 m_stream.write(
reinterpret_cast<char*
>(&finalWords),
sizeof(finalWords));
94 m_store->
get(name, colB);
97 throw std::runtime_error(std::string(
"no such collection to write: ") + name);
102 throw std::runtime_error(std::string(
"could not create SIOBlock for type: ") + typName);
105 m_collectionsToWrite.push_back(name);
108void SIOWriter::writeCollectionIDTable() {
109 sio::block_list blocks;
110 blocks.emplace_back(std::make_shared<SIOCollectionIDTableBlock>(m_store));
111 blocks.emplace_back(std::make_shared<SIOVersionBlock>(podio::version::build_version));
virtual std::string getValueTypeName() const =0
fully qualified type name of elements - with namespace
bool get(const std::string &name, const T *&collection)
access a collection by name. returns true if successful
ColMDMap * getColMetaDataMap()
GenericParameters * eventMetaDataPtr()
RunMDMap * getRunMetaDataMap()
static SIOBlockFactory & instance()
static SIOBlockLibraryLoader & instance()
void addRecord(const std::string &name, PositionType startPos)
SIOWriter(const std::string &filename, EventStore *store)
void registerForWrite(const std::string &name)
sio::ifstream::pos_type writeRecord(const sio::block_list &blocks, const std::string &recordName, sio::ofstream &stream, std::size_t initBufferSize=sio::mbyte, bool compress=true)
Write the passed record and return where it starts in the file.