-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document I/O interfaces #648
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,16 @@ | |
|
||
namespace podio { | ||
|
||
/// 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. | ||
/// | ||
/// @note The recommended way to construct is to use the makeReader() functions | ||
/// since they handle the instantiation of the correct low level readers | ||
class Reader { | ||
private: | ||
struct ReaderConcept { | ||
|
@@ -73,50 +83,139 @@ class Reader { | |
std::unique_ptr<ReaderConcept> m_self{nullptr}; | ||
|
||
public: | ||
/// Create a reader from a low level reader | ||
/// | ||
/// @tparam T The type of the low level reader (will bededuced) | ||
/// @param actualReader a low level reader that provides access to FrameDataT | ||
template <typename T> | ||
Reader(std::unique_ptr<T>); | ||
Reader(std::unique_ptr<T> actualReader); | ||
|
||
Reader(const Reader&) = delete; | ||
Reader& operator=(const Reader&) = delete; | ||
|
||
Reader(Reader&&) = default; | ||
Reader& operator=(Reader&&) = default; | ||
|
||
~Reader() = default; | ||
|
||
/// Read the next frame of a given category | ||
/// | ||
/// @param name The category name for which to read the next frame | ||
/// | ||
/// @returns A fully constructed Frame with the contents read from file | ||
/// | ||
/// @throws std::invalid_argument in case the category is not available or in | ||
/// case no more entries are available | ||
podio::Frame readNextFrame(const std::string& name) { | ||
return m_self->readNextFrame(name); | ||
} | ||
|
||
/// Read the next frame of the "events" category | ||
/// | ||
/// @returns A fully constructed Frame with the contents read from file | ||
/// | ||
/// @throws std::invalid_argument in case no (more) events are available | ||
podio::Frame readNextEvent() { | ||
return readNextFrame(podio::Category::Event); | ||
} | ||
|
||
/// Read a specific frame for a given category | ||
/// | ||
/// @param name The category name for which to read the next entry | ||
/// @param index The entry number to read | ||
/// | ||
/// @returns A fully constructed Frame with the contents read from file | ||
/// | ||
/// @throws std::invalid_argument in case the category is not available or in | ||
/// case the specified entry is not available | ||
podio::Frame readFrame(const std::string& name, size_t index) { | ||
return m_self->readFrame(name, index); | ||
} | ||
|
||
/// Read a specific frame of the "events" category | ||
/// | ||
/// @param index The event number to read | ||
/// | ||
/// @returns A fully constructed Frame with the contents read from file | ||
/// | ||
/// @throws std::invalid_argument in case the desired event is not available | ||
podio::Frame readEvent(size_t index) { | ||
return readFrame(podio::Category::Event, index); | ||
} | ||
|
||
/// Get the number of entries for the given name | ||
/// | ||
/// @param name The name of the category | ||
/// | ||
/// @returns The number of entries that are available for the category | ||
size_t getEntries(const std::string& name) const { | ||
return m_self->getEntries(name); | ||
} | ||
|
||
/// Get the number of events | ||
/// | ||
/// @returns The number of entries that are available for the category | ||
size_t getEvents() const { | ||
return getEntries(podio::Category::Event); | ||
} | ||
|
||
/// Get the build version of podio that has been used to write the current | ||
/// file | ||
/// | ||
/// @returns The podio build version | ||
podio::version::Version currentFileVersion() const { | ||
return m_self->currentFileVersion(); | ||
} | ||
|
||
/// Get the names of all the available Frame categories in the current file(s). | ||
/// | ||
/// @returns The names of the available categories from the file | ||
std::vector<std::string_view> getAvailableCategories() const { | ||
return m_self->getAvailableCategories(); | ||
} | ||
|
||
/// Get the datamodel definition for the given name | ||
/// | ||
/// @param name The name of the datamodel | ||
/// | ||
/// @returns The high level definition of the datamodel in JSON format | ||
const std::string_view getDatamodelDefinition(const std::string& name) const { | ||
return m_self->getDatamodelDefinition(name); | ||
} | ||
|
||
/// Get all names of the datamodels that are available from this reader | ||
/// | ||
/// @returns The names of the datamodels | ||
std::vector<std::string> getAvailableDatamodels() const { | ||
return m_self->getAvailableDatamodels(); | ||
} | ||
}; | ||
|
||
/// Create a Reader is able to read the file | ||
/// | ||
/// 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 | ||
/// | ||
/// @param filename The (path to the) file to read from | ||
/// | ||
/// @returns A Reader that has been initialized and that can be used for reading | ||
/// data from the passed file | ||
Reader makeReader(const std::string& filename); | ||
|
||
/// 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 read the first file! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should put in some exception handling or something of that kind. That is too burried in the docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean, throw an exception when more than one SIO file is passed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should not silently ignore faulty states. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so yes |
||
/// | ||
/// @param filenames The (paths to the) files to read from | ||
/// | ||
/// @returns A Reader that has been initialized and that can be used for reading | ||
/// data from the passed files | ||
/// | ||
/// @throws std::runtime_error in case the file extensions differ or in case | ||
/// support for the necessary I/O backend has not been built | ||
Reader makeReader(const std::vector<std::string>& filename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually it should be |
||
|
||
} // namespace podio | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition it provides convenience methods to deal specifically with the event frame category...