Class podio::WriterFor

class WriterFor

Builder for a Writer that allows to configure the backend and its options.

The backend is determined when create() is called, in the following order

  • An explicitly selected backend (via either withBackend() or withType()) is used.

  • The extension of the filename selects the backend. For “.root” files the PODIO_DEFAULT_WRITE_RNTUPLE environment variable switches from TTree to RNTuple, if it is set to a non-empty value.

Options passed via withOptions() have to be usable with the backend that has been determined as described above.

All configuration errors are detected before any file is created.

#include <podio/Writer.h>
#include <podio/ROOTWriteOptions.h>

auto writer = podio::WriterFor{"output.root"}.withBackend(podio::WriterFor::Backend::RNTuple).create();
auto writer = podio::WriterFor{"output.root"}.withType("rntuple").create();
// TTree or RNTuple depending on PODIO_DEFAULT_WRITE_RNTUPLE
auto writer = podio::WriterFor{"output.root"}
                  .withOptions(podio::ROOTWriteOptions{.compressionSettings = 505})
                  .create();
// Always RNTuple
auto writer = podio::WriterFor{"output.root"}
                  .withBackend(podio::WriterFor::Backend::RNTuple)
                  .withOptions(podio::ROOTWriteOptions{.compressionSettings = 505})
                  .create();

Public Types

enum class Backend

The I/O backends that can be explicitly selected.

Values:

enumerator TTree

TTree based ROOT files (ROOTWriter).

enumerator RNTuple

RNTuple based ROOT files (RNTupleWriter).

enumerator SIO

SIO files (SIOWriter).

enumerator Arrow

Arrow / Parquet directories (ArrowWriter).

Public Functions

inline explicit WriterFor(std::string filename)

Start configuring a Writer for the given file.

Parameters:

filename – The filename of the output file that will be created

WriterFor &withBackend(Backend backend)

Explicitly select the backend.

Parameters:

backend – The backend to use

Throws:
  • std::invalid_argument – If a backend has already been selected

  • std::runtime_error – If support for the backend has not been built

WriterFor &withType(const std::string &type)

Explicitly select the backend via its name.

Parameters:

type – One of “default”, “root”, “rntuple”, “sio” or “parquet” (case insensitive). “default” does not select a backend, it is determined from the filename instead

Throws:
  • std::runtime_error – If the type is not known or if support for the backend has not been built

  • std::invalid_argument – If a backend has already been selected

template<std::copy_constructible OptionsT>
inline WriterFor &withOptions(const OptionsT &options)

Set the options of a specific low level writer.

The options are only checked against the backend that has been determined when create() is called.

Template Parameters:

OptionsT – The options of a low level writer, e.g. ROOTWriteOptions or ArrowWriter::Options

Parameters:

options – The backend specific options

Writer create() const

Create the Writer.

Throws:
  • std::invalid_argument – If the options can not be used with the selected backend

  • std::runtime_error – If the filename can not be associated to an I/O backend or if support for the desired I/O backend has not been built

Returns:

A fully initialized Writer for the I/O backend that has been determined