PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
podio::SIOFrameWriter Class Reference

#include <SIOFrameWriter.h>

Public Member Functions

 SIOFrameWriter (const std::string &filename)
 
 ~SIOFrameWriter ()=default
 
 SIOFrameWriter (const SIOFrameWriter &)=delete
 
SIOFrameWriteroperator= (const SIOFrameWriter &)=delete
 
void writeFrame (const podio::Frame &frame, const std::string &category)
 
void writeFrame (const podio::Frame &frame, const std::string &category, const std::vector< std::string > &collsToWrite)
 
void finish ()
 

Detailed Description

Definition at line 17 of file SIOFrameWriter.h.

Constructor & Destructor Documentation

◆ SIOFrameWriter() [1/2]

podio::SIOFrameWriter::SIOFrameWriter ( const std::string &  filename)

Definition at line 15 of file SIOFrameWriter.cc.

15 {
16 m_stream.open(filename, std::ios::binary);
17 if (!m_stream.is_open()) {
18 SIO_THROW(sio::error_code::not_open, "Couldn't open output stream '" + filename + "'");
19 }
20
21 auto& libLoader [[maybe_unused]] = SIOBlockLibraryLoader::instance();
22
23 sio::block_list blocks;
24 blocks.emplace_back(std::make_shared<SIOVersionBlock>(podio::version::build_version));
25 // write the version uncompressed
26 sio_utils::writeRecord(blocks, "podio_header_info", m_stream, sizeof(podio::version::Version), false);
27}
static SIOBlockLibraryLoader & instance()
Definition: SIOBlock.h:263
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.
Definition: sioUtils.h:82

◆ ~SIOFrameWriter()

podio::SIOFrameWriter::~SIOFrameWriter ( )
default

◆ SIOFrameWriter() [2/2]

podio::SIOFrameWriter::SIOFrameWriter ( const SIOFrameWriter )
delete

Member Function Documentation

◆ finish()

void podio::SIOFrameWriter::finish ( )

Definition at line 53 of file SIOFrameWriter.cc.

53 {
54 auto edmDefMap = std::make_shared<podio::SIOMapBlock<std::string, std::string>>(
55 m_datamodelCollector.getDatamodelDefinitionsToWrite());
56
57 sio::block_list blocks;
58 blocks.push_back(edmDefMap);
59 m_tocRecord.addRecord(sio_helpers::SIOEDMDefinitionName, sio_utils::writeRecord(blocks, "EDMDefinitions", m_stream));
60
61 blocks.clear();
62 blocks.emplace_back(std::make_shared<SIOFileTOCRecordBlock>(&m_tocRecord));
63
64 auto tocStartPos = sio_utils::writeRecord(blocks, sio_helpers::SIOTocRecordName, m_stream);
65
66 // Now that we know the position of the TOC Record, put this information
67 // into a final marker that can be identified and interpreted when reading
68 // again
69 uint64_t finalWords = (((uint64_t)sio_helpers::SIOTocMarker) << 32) | ((uint64_t)tocStartPos & 0xffffffff);
70 m_stream.write(reinterpret_cast<char*>(&finalWords), sizeof(finalWords));
71
72 m_stream.close();
73}
std::vector< std::tuple< std::string, std::string > > getDatamodelDefinitionsToWrite() const
Get all the names and JSON definitions that need to be written.
void addRecord(const std::string &name, PositionType startPos)
Definition: SIOBlock.cc:184

◆ operator=()

SIOFrameWriter & podio::SIOFrameWriter::operator= ( const SIOFrameWriter )
delete

◆ writeFrame() [1/2]

void podio::SIOFrameWriter::writeFrame ( const podio::Frame frame,
const std::string &  category 
)

Write the given Frame with the given category

Definition at line 29 of file SIOFrameWriter.cc.

29 {
30 writeFrame(frame, category, frame.getAvailableCollections());
31}
std::vector< std::string > getAvailableCollections() const
Definition: Frame.h:252
void writeFrame(const podio::Frame &frame, const std::string &category)

Referenced by writeFrame().

◆ writeFrame() [2/2]

void podio::SIOFrameWriter::writeFrame ( const podio::Frame frame,
const std::string &  category,
const std::vector< std::string > &  collsToWrite 
)

Write the given Frame with the given category only storing the collections that are desired via collsToWrite

Definition at line 33 of file SIOFrameWriter.cc.

34 {
35 std::vector<sio_utils::StoreCollection> collections;
36 collections.reserve(collsToWrite.size());
37 for (const auto& name : collsToWrite) {
38 collections.emplace_back(name, frame.getCollectionForWrite(name));
39 m_datamodelCollector.registerDatamodelDefinition(collections.back().second, name);
40 }
41
42 // Write necessary metadata and the actual data into two different records.
43 // Otherwise we cannot easily unpack the data record, because necessary
44 // information is contained within the record.
45 sio::block_list tableBlocks;
46 tableBlocks.emplace_back(sio_utils::createCollIDBlock(collections, frame.getCollectionIDTableForWrite()));
47 m_tocRecord.addRecord(category, sio_utils::writeRecord(tableBlocks, category + "_HEADER", m_stream));
48
49 const auto blocks = sio_utils::createBlocks(collections, frame.getParameters());
50 sio_utils::writeRecord(blocks, category, m_stream);
51}
void registerDatamodelDefinition(const podio::CollectionBase *coll, const std::string &name)
podio::CollectionIDTable getCollectionIDTableForWrite() const
Definition: Frame.h:278
const podio::GenericParameters & getParameters() const
Definition: Frame.h:238
const podio::CollectionBase * getCollectionForWrite(const std::string &name) const
Definition: Frame.h:269
sio::block_list createBlocks(const std::vector< StoreCollection > &collections, const podio::GenericParameters &parameters)
Create all blocks to store the passed collections and parameters into a record.
Definition: sioUtils.h:64
std::shared_ptr< SIOCollectionIDTableBlock > createCollIDBlock(const std::vector< StoreCollection > &collections, const podio::CollectionIDTable &collIdTable)
Create the collection ID block from the passed collections.
Definition: sioUtils.h:39

The documentation for this class was generated from the following files: