-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a reader and writer interface, rename the RNTuple reader and writer
- Loading branch information
Showing
20 changed files
with
405 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef PODIO_FRAMEREADER_H | ||
#define PODIO_FRAMEREADER_H | ||
|
||
#include "podio/ROOTFrameData.h" | ||
#include "podio/podioVersion.h" | ||
#include "podio/utilities/DatamodelRegistryIOHelpers.h" | ||
|
||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
#include <string_view> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace podio { | ||
|
||
/** | ||
* This class has the function to read available data from disk | ||
* and to prepare collections and buffers. | ||
**/ | ||
class IROOTFrameReader { | ||
|
||
public: | ||
IROOTFrameReader() = default; | ||
virtual ~IROOTFrameReader() = default; | ||
|
||
IROOTFrameReader(const IROOTFrameReader&) = delete; | ||
IROOTFrameReader& operator=(const IROOTFrameReader&) = delete; | ||
|
||
/** | ||
* Open a single file for reading. | ||
* | ||
* @param filename The name of the input file | ||
*/ | ||
virtual void openFile(const std::string& filename) = 0; | ||
|
||
/** | ||
* 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. | ||
* | ||
* @param filenames The filenames of all input files that should be read | ||
*/ | ||
virtual void openFiles(const std::vector<std::string>& filenames) = 0; | ||
|
||
/** | ||
* Read the next data entry from which a Frame can be constructed for the | ||
* given name. In case there are no more entries left for this name or in | ||
* case there is no data for this name, this returns a nullptr. | ||
*/ | ||
virtual std::unique_ptr<podio::ROOTFrameData> readNextEntry(const std::string& name) = 0; | ||
|
||
/** | ||
* Read the specified data entry from which a Frame can be constructed for | ||
* the given name. In case the entry does not exist for this name or in case | ||
* there is no data for this name, this returns a nullptr. | ||
*/ | ||
virtual std::unique_ptr<podio::ROOTFrameData> readEntry(const std::string& name, const unsigned entry) = 0; | ||
|
||
/// Returns number of entries for the given name | ||
virtual unsigned getEntries(const std::string& name) = 0; | ||
|
||
/// Get the build version of podio that has been used to write the current file | ||
virtual podio::version::Version currentFileVersion() const = 0; | ||
|
||
/// Get the names of all the availalable Frame categories in the current file(s) | ||
virtual std::vector<std::string_view> getAvailableCategories() const = 0; | ||
|
||
/// Get the datamodel definition for the given name | ||
virtual const std::string_view getDatamodelDefinition(const std::string& name) const = 0; | ||
|
||
/// Get all names of the datamodels that ara available from this reader | ||
virtual std::vector<std::string> getAvailableDatamodels() const = 0; | ||
}; | ||
|
||
} // namespace podio | ||
|
||
#endif // PODIO_FRAMEREADER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#ifndef PODIO_IROOTFRAMEWRITER_H | ||
#define PODIO_IROOTFRAMEWRITER_H | ||
|
||
#include "podio/CollectionBranches.h" | ||
#include "podio/CollectionIDTable.h" | ||
#include "podio/utilities/DatamodelRegistryIOHelpers.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <tuple> | ||
#include <vector> | ||
|
||
namespace podio { | ||
class Frame; | ||
class CollectionBase; | ||
class GenericParameters; | ||
|
||
class IROOTFrameWriter { | ||
public: | ||
IROOTFrameWriter() = default; | ||
virtual ~IROOTFrameWriter() = default; | ||
|
||
IROOTFrameWriter(const IROOTFrameWriter&) = delete; | ||
IROOTFrameWriter& operator=(const IROOTFrameWriter&) = delete; | ||
|
||
/** Store the given frame with the given category. Store all available | ||
* collections from the Frame. | ||
* | ||
* NOTE: The contents of the first Frame that is written in this way | ||
* determines the contents that will be written for all subsequent Frames. | ||
*/ | ||
virtual void writeFrame(const podio::Frame& frame, const std::string& category) = 0; | ||
|
||
/** Store the given Frame with the given category. Store only the | ||
* collections that are passed. | ||
* | ||
* NOTE: The contents of the first Frame that is written in this way | ||
* determines the contents that will be written for all subsequent Frames. | ||
*/ | ||
virtual void writeFrame(const podio::Frame& frame, const std::string& category, | ||
const std::vector<std::string>& collsToWrite) = 0; | ||
|
||
/** Write the current file, including all the necessary metadata to read it again. | ||
*/ | ||
virtual void finish() = 0; | ||
|
||
/** Check whether the collsToWrite are consistent with the state of the passed | ||
* category. | ||
* | ||
* Return two vectors of collection names. The first one contains all the | ||
* names that were missing from the collsToWrite but were present in the | ||
* category. The second one contains the names that are present in the | ||
* collsToWrite only. If both vectors are empty the category and the passed | ||
* collsToWrite are consistent. | ||
* | ||
* NOTE: This will only be a meaningful check if the first Frame of the passed | ||
* category has already been written. Also, this check is rather expensive as | ||
* it has to effectively do two set differences. | ||
*/ | ||
std::tuple<std::vector<std::string>, std::vector<std::string>> | ||
checkConsistency(const std::vector<std::string>& collsToWrite, const std::string& category) const; | ||
}; | ||
|
||
} // namespace podio | ||
|
||
#endif // PODIO_IROOTFRAMEWRITER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.