File Reader.h
-
namespace podio
Functions
-
Reader makeReader(const std::string &filename)
Create a Reader that is able to read the file or files matching a glob pattern.
This will inspect the filename as well as peek at the file contents to instantiate the correct low level reader to open and read the file
- Parameters:
filename – The (path to the) file to read from. The file path can include glob patterns to match multiple files.
- Returns:
A Reader that has been initialized and that can be used for reading data from the passed file
-
Reader makeReader(const std::vector<std::string> &filenames)
Create a Reader that is able to read the files.
This will inspect the filenames as well as peek into the first file only to decide based on the contents which low level reader to instantiate for reading. All files are assumed to be of the same I/O format, no switching between formats is possible.
Note
For SIO files this will only work with exactly one file!
- Parameters:
filenames – The (paths to the) files to read from
- Throws:
std::runtime_error – in case the file extensions differ or in case support for the necessary I/O backend has not been built or in case multiple files for the SIO backend are passed
- Returns:
A Reader that has been initialized and that can be used for reading data from the passed files
-
class Reader
- #include <podio/Reader.h>
Generic (type erased) reader class that can handle different I/O backends transparently.
Offers some more high level functionality compared to the lower level backend specific readers that this class wraps. In contrast to the lower level readers that usually return arbitrary FrameData, this interface class will return fully constructed Frames. In addition, it provides convenience methods to deal specifically with the “events” frame category.
Note
The recommended way to construct is to use the makeReader() functions since they handle the instantiation of the correct low level readers
Public Functions
-
template<typename T>
Reader(std::unique_ptr<T> actualReader) Create a reader from a low level reader.
- Template Parameters:
T – The type of the low level reader (will be deduced)
- Parameters:
actualReader – a low level reader that provides access to FrameDataT
-
Reader(const Reader&) = delete
-
Reader(Reader&&) = default
-
~Reader() = default
-
inline podio::Frame readNextFrame(const std::string &name, const std::vector<std::string> &collsToRead = {})
Read the next frame of a given category.
- Parameters:
name – The category name for which to read the next frame
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 the category is not available or in case no more entries are available
- Returns:
A fully constructed Frame with the contents read from file
-
inline podio::Frame readNextEvent(const std::vector<std::string> &collsToRead = {})
Read the next frame of the “events” category.
- Parameters:
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 no (more) events are available
- Returns:
A fully constructed Frame with the contents read from file
-
inline podio::Frame readFrame(const std::string &name, size_t index, const std::vector<std::string> &collsToRead = {})
Read a specific frame for a given category.
- Parameters:
name – The category name for which to read the next entry
index – 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 the category is not available or in case the specified entry is not available
- Returns:
A fully constructed Frame with the contents read from file
-
inline podio::Frame readEvent(size_t index, const std::vector<std::string> &collsToRead = {})
Read a specific frame of the “events” category.
- Parameters:
index – The event 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 the desired event is not available
- Returns:
A fully constructed Frame with the contents read from file
-
inline size_t getEntries(const std::string &name) const
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 size_t getEvents() const
Get the number of events.
- 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 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 categories from the file
-
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 Members
-
std::unique_ptr<ReaderConcept> m_self = {nullptr}
-
struct ReaderConcept
Public Functions
-
virtual ~ReaderConcept() = default
-
virtual podio::Frame readFrame(const std::string &name, size_t index, const std::vector<std::string>&) = 0
-
virtual size_t getEntries(const std::string &name) const = 0
-
virtual std::optional<podio::version::Version> currentFileVersion(const std::string &name) const = 0
-
virtual std::vector<std::string_view> getAvailableCategories() const = 0
-
virtual const std::string_view getDatamodelDefinition(const std::string &name) const = 0
-
virtual std::vector<std::string> getAvailableDatamodels() const = 0
-
virtual ~ReaderConcept() = default
-
template<typename T>
struct ReaderModel : public podio::Reader::ReaderConcept Public Functions
-
ReaderModel(const ReaderModel&) = delete
-
ReaderModel &operator=(const ReaderModel&) = delete
-
ReaderModel(ReaderModel&&) = default
-
ReaderModel &operator=(ReaderModel&&) = default
-
~ReaderModel() override = default
-
inline podio::Frame readNextFrame(const std::string &name, const std::vector<std::string> &collsToRead) override
-
inline podio::Frame readFrame(const std::string &name, size_t index, const std::vector<std::string> &collsToRead) override
-
inline size_t getEntries(const std::string &name) const override
-
inline std::optional<podio::version::Version> currentFileVersion(const std::string &name) const override
-
inline std::vector<std::string_view> getAvailableCategories() const override
-
inline const std::string_view getDatamodelDefinition(const std::string &name) const override
-
inline std::vector<std::string> getAvailableDatamodels() const override
-
ReaderModel(const ReaderModel&) = delete
-
template<typename T>
-
Reader makeReader(const std::string &filename)