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

Typedefs

using StoreCollection = std::pair< const std::string &, const podio::CollectionBase * >
 

Functions

std::pair< sio::buffer, sio::record_info > readRecord (sio::ifstream &stream, bool decompress=true, std::size_t initBufferSize=sio::mbyte)
 Read the record into a buffer and potentially uncompress it.
 
std::shared_ptr< SIOCollectionIDTableBlockcreateCollIDBlock (const std::vector< StoreCollection > &collections, const podio::CollectionIDTable &collIdTable)
 Create the collection ID block from the passed collections.
 
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.
 
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.
 

Typedef Documentation

◆ StoreCollection

using podio::sio_utils::StoreCollection = typedef std::pair<const std::string&, const podio::CollectionBase*>

Definition at line 36 of file sioUtils.h.

Function Documentation

◆ createBlocks()

sio::block_list podio::sio_utils::createBlocks ( const std::vector< StoreCollection > &  collections,
const podio::GenericParameters parameters 
)
inline

Create all blocks to store the passed collections and parameters into a record.

Definition at line 64 of file sioUtils.h.

65 {
66 sio::block_list blocks;
67 blocks.reserve(collections.size() + 1); // parameters + collections
68
69 auto paramBlock = std::make_shared<SIOEventMetaDataBlock>();
70 // TODO: get rid of const_cast
71 paramBlock->metadata = const_cast<podio::GenericParameters*>(&parameters);
72 blocks.emplace_back(std::move(paramBlock));
73
74 for (const auto& [name, col] : collections) {
75 blocks.emplace_back(podio::SIOBlockFactory::instance().createBlock(col, name));
76 }
77
78 return blocks;
79 }
static SIOBlockFactory & instance()
Definition: SIOBlock.h:236
std::shared_ptr< SIOBlock > createBlock(const podio::CollectionBase *col, const std::string &name) const
Definition: SIOBlock.cc:110

Referenced by podio::SIOFrameWriter::writeFrame().

◆ createCollIDBlock()

std::shared_ptr< SIOCollectionIDTableBlock > podio::sio_utils::createCollIDBlock ( const std::vector< StoreCollection > &  collections,
const podio::CollectionIDTable collIdTable 
)
inline

Create the collection ID block from the passed collections.

Definition at line 39 of file sioUtils.h.

40 {
41 // Need to make sure that the type names and subset collection bits are in
42 // the same order here!
43 std::vector<std::string> types;
44 types.reserve(collections.size());
45 std::vector<short> subsetColl;
46 subsetColl.reserve(collections.size());
47 std::vector<std::string> names;
48 names.reserve(collections.size());
49 std::vector<int> ids;
50 ids.reserve(collections.size());
51
52 for (const auto& [name, coll] : collections) {
53 names.emplace_back(name);
54 ids.emplace_back(collIdTable.collectionID(name));
55 types.emplace_back(coll->getValueTypeName());
56 subsetColl.emplace_back(coll->isSubsetCollection());
57 }
58
59 return std::make_shared<SIOCollectionIDTableBlock>(std::move(names), std::move(ids), std::move(types),
60 std::move(subsetColl));
61 }
int collectionID(const std::string &name) const
return collection ID for given name

Referenced by podio::SIOFrameWriter::writeFrame().

◆ readRecord()

std::pair< sio::buffer, sio::record_info > podio::sio_utils::readRecord ( sio::ifstream &  stream,
bool  decompress = true,
std::size_t  initBufferSize = sio::mbyte 
)
inline

Read the record into a buffer and potentially uncompress it.

Definition at line 18 of file sioUtils.h.

19 {
20 sio::record_info recInfo;
21 sio::buffer infoBuffer{sio::max_record_info_len};
22 sio::buffer recBuffer{initBufferSize};
23 sio::api::read_record_info(stream, recInfo, infoBuffer);
24 sio::api::read_record_data(stream, recInfo, recBuffer);
25
26 if (decompress) {
27 sio::buffer uncBuffer{recInfo._uncompressed_length};
28 sio::zlib_compression compressor;
29 compressor.uncompress(recBuffer.span(), uncBuffer);
30 return std::make_pair(std::move(uncBuffer), recInfo);
31 }
32
33 return std::make_pair(std::move(recBuffer), recInfo);
34 }

Referenced by podio::SIOLegacyReader::readNextEntry(), and podio::SIOFrameReader::readNextEntry().

◆ writeRecord()

sio::ifstream::pos_type podio::sio_utils::writeRecord ( const sio::block_list &  blocks,
const std::string &  recordName,
sio::ofstream &  stream,
std::size_t  initBufferSize = sio::mbyte,
bool  compress = true 
)
inline

Write the passed record and return where it starts in the file.

Definition at line 82 of file sioUtils.h.

84 {
85 auto buffer = sio::buffer{initBufferSize};
86 auto recInfo = sio::api::write_record(recordName, buffer, blocks, 0);
87
88 if (compress) {
89 // use zlib to compress the record into another buffer
90 sio::zlib_compression compressor;
91 compressor.set_level(6); // Z_DEFAULT_COMPRESSION==6
92 auto comBuffer = sio::buffer{initBufferSize};
93 sio::api::compress_record(recInfo, buffer, comBuffer, compressor);
94
95 sio::api::write_record(stream, buffer.span(0, recInfo._header_length), comBuffer.span(), recInfo);
96 } else {
97 sio::api::write_record(stream, buffer.span(), recInfo);
98 }
99
100 return recInfo._file_start;
101 }

Referenced by podio::SIOFrameWriter::finish(), podio::SIOWriter::finish(), podio::SIOFrameWriter::SIOFrameWriter(), podio::SIOWriter::writeEvent(), and podio::SIOFrameWriter::writeFrame().