File RNTupleReader.h

namespace podio
class RNTupleReader
#include <podio/RNTupleReader.h>

The RNTupleReader can be used to read files that have been written with the RNTuple backend.

The RNTupleReader provides the data as ROOTFrameData from which a podio::Frame can be constructed. It can be used to read files written by the RNTupleWriter.

Public Functions

RNTupleReader() = default

Create a RNTupleReader.

~RNTupleReader() = default

Destructor.

RNTupleReader(const RNTupleReader&) = delete

The RNTupleReader is not copy-able.

RNTupleReader &operator=(const RNTupleReader&) = delete

The RNTupleReader is not copy-able.

void openFile(const std::string &filename)

Open a single file for reading.

Parameters:

filename – The name of the input file

void openFiles(const std::vector<std::string> &filenames)

Open multiple files for reading and then treat them as if they are one file.

Note

All of the files are assumed to have the same structure. Specifically this means:

  • The same categories are available from all files

  • The collections that are contained in the individual categories are the same across all files

  • This usually boils down to “the files have been written with the same

    ”settings”, e.g. they are outputs of a batched process.

Parameters:

filenames – The filenames of all input files that should be read

std::unique_ptr<podio::ROOTFrameData> readNextEntry(const std::string &name, const std::vector<std::string> &collsToRead = {})

Read the next data entry for a given category.

Parameters:
  • name – The category name for which to read the next entry

  • collsToRead – (optional) the collection names that should be read. If not provided (or empty) all collections will be read

Throws:

std::invalid_argument – in case collsToRead contains collection names that are not available

Returns:

FrameData from which a podio::Frame can be constructed if the category exists and if there are still entries left to read. Otherwise a nullptr

std::unique_ptr<podio::ROOTFrameData> readEntry(const std::string &name, const unsigned entry, const std::vector<std::string> &collsToRead = {})

Read the desired data entry for a given category.

Parameters:
  • name – The category name for which to read the next entry

  • entry – The entry number to read

  • collsToRead – (optional) the collection names that should be read. If not provided (or empty) all collections will be read

Throws:

std::invalid_argument – in case collsToRead contains collection names that are not available

Returns:

FrameData from which a podio::Frame can be constructed if the category and the desired entry exist. Otherwise a nullptr

std::vector<std::string_view> getAvailableCategories() const

Get the names of all the available Frame categories in the current file(s).

Returns:

The names of the available categores from the file

unsigned getEntries(const std::string &name)

Get the number of entries for the given name.

Parameters:

name – The name of the category

Returns:

The number of entries that are available for the category

inline podio::version::Version currentFileVersion() const

Get the build version of podio that has been used to write the current file.

Returns:

The podio build version

inline std::optional<podio::version::Version> currentFileVersion(const std::string &name) const

Get the (build) version of a datamodel that has been used to write the current file.

Parameters:

name – The name of the datamodel

Returns:

The (build) version of the datamodel if available or an empty optional

inline const std::string_view getDatamodelDefinition(const std::string &name) const

Get the datamodel definition for the given name.

Parameters:

name – The name of the datamodel

Returns:

The high level definition of the datamodel in JSON format

inline std::vector<std::string> getAvailableDatamodels() const

Get all names of the datamodels that are available from this reader.

Returns:

The names of the datamodels

Private Functions

bool initCategory(const std::string &category)

Initialize the given category by filling the maps with metadata information that will be used later.

GenericParameters readEventMetaData(const std::string &name, const unsigned localEntry, const unsigned readerIndex)

Read and reconstruct the generic parameters of the Frame.

template<typename T>
void readParams(const std::string &name, const unsigned entNum, const unsigned readerIndex, GenericParameters &params)

Private Members

std::unique_ptr<root_compat::RNTupleReader> m_metadata = {}
podio::version::Version m_fileVersion = {}
DatamodelDefinitionHolder m_datamodelHolder = {}
std::unordered_map<std::string, std::vector<std::unique_ptr<root_compat::RNTupleReader>>> m_readers = {}
std::unordered_map<std::string, std::unique_ptr<root_compat::RNTupleReader>> m_metadata_readers = {}
std::vector<std::string> m_filenames = {}
std::unordered_map<std::string, unsigned> m_entries = {}
std::unordered_map<std::string, std::vector<unsigned>> m_readerEntries = {}
std::unordered_map<std::string, unsigned> m_totalEntries = {}
std::unordered_map<std::string, std::vector<podio::root_utils::CollectionWriteInfo>> m_collectionInfo = {}

Map each category to the collections that have been written and are available.

std::vector<std::string> m_availableCategories = {}
std::unordered_map<std::string, std::shared_ptr<podio::CollectionIDTable>> m_idTables = {}
namespace root_compat

Introduce a new namespace instead of potentially opening and polluting the ROOT namespace.

Typedefs

using RNTupleReader = ROOT::RNTupleReader