-
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
Add support for the new RNTuple format #395
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
7f2826f
Add a RNTuple writer
jmcarcell 78d1162
Cleanup and add a reader
jmcarcell 69d50c8
Add compilation instructions for RNTuple
jmcarcell f4cc923
Add tests
jmcarcell 4dbbf7f
Fix the reader and writer so that they pass most of the tests
jmcarcell 49167c9
Commit missing changes in the header
jmcarcell 4bc7ed7
Add support for Generic Parameters
jmcarcell 9fc8da3
Add an ugly workaround to the unique_ptr issue
jmcarcell 529dffc
Read also vector members and remove some comments
jmcarcell 8dcdf5a
Do a bit of cleanup
jmcarcell 27e7b87
Do more cleanup, also compiler warnings
jmcarcell 5ea4a97
Add names in rootUtils.h, fix a few compiler warnings
jmcarcell bdf4335
Add a few minor changes
jmcarcell f119026
Add missing changes in the headers
jmcarcell 2aa55ef
Change map -> unordered_map and use append in CMakeLists.txt
jmcarcell 5edd00e
Simplify writing and reading of generic parameters
jmcarcell 4d995e3
Only create the ID table once
jmcarcell 647dd87
Add CollectionInfo structs
jmcarcell 8fee8b3
Add a ROOT version check
jmcarcell a1d97ba
Add missing endif()
jmcarcell d8ab05a
Add Name at the end of some names
jmcarcell be74a35
Add missing Name at the end
jmcarcell 53e1dd0
Cast to rvalue
jmcarcell 7216c2d
Cache entries and reserve
jmcarcell 01ccc64
Add comment and remove old comments
jmcarcell 09cbd61
Remove a few couts
jmcarcell 52b419d
Remove intermediate variables and use std::move
jmcarcell 7379ade
Run clang-format
jmcarcell 027925b
Use clang-format on tests too
jmcarcell 2629d66
Enable RNTuple I/O in Key4hep CI
tmadlener f8c58d1
Check if dev3 workflows come with recent enough ROOT
tmadlener a4ecb55
Change MakeField to the new signature
jmcarcell beaf236
Update the RNTuple reader and writer to use the buffer factory
jmcarcell ab5cfb2
Run clang-format
jmcarcell 1cd727e
Update the RNTuple writer to use a bare model
jmcarcell f34ebc7
Add friends for Generic Parameters
jmcarcell 659e051
Update changes after the changes in the collectionID and string_view
jmcarcell a471949
Run clang-format
jmcarcell 178e6a1
Update the reader and writer to conform to #405
jmcarcell 5be7223
Reorganize and clean up code in the reader
jmcarcell ec5bcf3
Run clang-format
jmcarcell b0f654c
Simplify how the references are filled
jmcarcell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,104 @@ | ||
#ifndef PODIO_ROOTNTUPLEREADER_H | ||
#define PODIO_ROOTNTUPLEREADER_H | ||
|
||
#include "podio/CollectionBranches.h" | ||
#include "podio/ICollectionProvider.h" | ||
#include "podio/ROOTFrameData.h" | ||
#include "podio/SchemaEvolution.h" | ||
#include "podio/podioVersion.h" | ||
#include "podio/utilities/DatamodelRegistryIOHelpers.h" | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include <ROOT/RNTuple.hxx> | ||
#include <ROOT/RNTupleModel.hxx> | ||
|
||
namespace podio { | ||
|
||
/** | ||
This class has the function to read available data from disk | ||
and to prepare collections and buffers. | ||
**/ | ||
class ROOTNTupleReader { | ||
|
||
public: | ||
ROOTNTupleReader() = default; | ||
~ROOTNTupleReader() = default; | ||
|
||
ROOTNTupleReader(const ROOTNTupleReader&) = delete; | ||
ROOTNTupleReader& operator=(const ROOTNTupleReader&) = delete; | ||
|
||
void openFile(const std::string& filename); | ||
void openFiles(const std::vector<std::string>& filename); | ||
|
||
/** | ||
* 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. | ||
*/ | ||
std::unique_ptr<podio::ROOTFrameData> readNextEntry(const std::string& name); | ||
|
||
/** | ||
* 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. | ||
*/ | ||
std::unique_ptr<podio::ROOTFrameData> readEntry(const std::string& name, const unsigned entry); | ||
|
||
/// Returns number of entries for the given name | ||
unsigned getEntries(const std::string& name); | ||
|
||
/// Get the build version of podio that has been used to write the current file | ||
podio::version::Version currentFileVersion() const { | ||
return m_fileVersion; | ||
} | ||
|
||
void closeFile(); | ||
|
||
private: | ||
/** | ||
* Initialize the given category by filling the maps with metadata information | ||
* that will be used later | ||
*/ | ||
bool initCategory(const std::string& category); | ||
|
||
/** | ||
* Read and reconstruct the generic parameters of the Frame | ||
*/ | ||
GenericParameters readEventMetaData(const std::string& name, unsigned entNum); | ||
|
||
template <typename T> | ||
void readParams(const std::string& name, unsigned entNum, GenericParameters& params); | ||
|
||
std::unique_ptr<ROOT::Experimental::RNTupleReader> m_metadata{}; | ||
|
||
podio::version::Version m_fileVersion{}; | ||
DatamodelDefinitionHolder m_datamodelHolder{}; | ||
|
||
std::unordered_map<std::string, std::vector<std::unique_ptr<ROOT::Experimental::RNTupleReader>>> m_readers{}; | ||
std::unordered_map<std::string, std::unique_ptr<ROOT::Experimental::RNTupleReader>> m_metadata_readers{}; | ||
std::vector<std::string> m_filenames{}; | ||
|
||
std::unordered_map<std::string, int> m_entries{}; | ||
std::unordered_map<std::string, unsigned> m_totalEntries{}; | ||
|
||
struct CollectionInfo { | ||
std::vector<unsigned int> id{}; | ||
std::vector<std::string> name{}; | ||
std::vector<std::string> type{}; | ||
std::vector<short> isSubsetCollection{}; | ||
std::vector<SchemaVersionT> schemaVersion{}; | ||
}; | ||
|
||
std::unordered_map<std::string, CollectionInfo> m_collectionInfo{}; | ||
|
||
std::vector<std::string> m_availableCategories{}; | ||
|
||
std::shared_ptr<podio::CollectionIDTable> m_table{}; | ||
}; | ||
|
||
} // namespace podio | ||
|
||
#endif |
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,74 @@ | ||
#ifndef PODIO_ROOTNTUPLEWRITER_H | ||
#define PODIO_ROOTNTUPLEWRITER_H | ||
|
||
#include "podio/CollectionBase.h" | ||
#include "podio/Frame.h" | ||
#include "podio/GenericParameters.h" | ||
#include "podio/SchemaEvolution.h" | ||
#include "podio/utilities/DatamodelRegistryIOHelpers.h" | ||
|
||
#include "TFile.h" | ||
#include <ROOT/RNTuple.hxx> | ||
#include <ROOT/RNTupleModel.hxx> | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
namespace podio { | ||
|
||
class ROOTNTupleWriter { | ||
public: | ||
ROOTNTupleWriter(const std::string& filename); | ||
~ROOTNTupleWriter(); | ||
|
||
ROOTNTupleWriter(const ROOTNTupleWriter&) = delete; | ||
ROOTNTupleWriter& operator=(const ROOTNTupleWriter&) = delete; | ||
|
||
template <typename T> | ||
void fillParams(GenericParameters& params, ROOT::Experimental::REntry* entry); | ||
|
||
void writeFrame(const podio::Frame& frame, const std::string& category); | ||
void writeFrame(const podio::Frame& frame, const std::string& category, const std::vector<std::string>& collsToWrite); | ||
void finish(); | ||
|
||
private: | ||
using StoreCollection = std::pair<const std::string&, podio::CollectionBase*>; | ||
std::unique_ptr<ROOT::Experimental::RNTupleModel> createModels(const std::vector<StoreCollection>& collections); | ||
|
||
std::unique_ptr<ROOT::Experimental::RNTupleModel> m_metadata{}; | ||
std::unordered_map<std::string, std::unique_ptr<ROOT::Experimental::RNTupleWriter>> m_writers{}; | ||
std::unique_ptr<ROOT::Experimental::RNTupleWriter> m_metadataWriter{}; | ||
|
||
std::unique_ptr<TFile> m_file{}; | ||
|
||
DatamodelDefinitionCollector m_datamodelCollector{}; | ||
|
||
struct CollectionInfo { | ||
std::vector<unsigned int> id{}; | ||
std::vector<std::string> name{}; | ||
std::vector<std::string> type{}; | ||
std::vector<short> isSubsetCollection{}; | ||
std::vector<SchemaVersionT> schemaVersion{}; | ||
}; | ||
|
||
std::unordered_map<std::string, CollectionInfo> m_collectionInfo{}; | ||
|
||
std::set<std::string> m_categories{}; | ||
|
||
bool m_finished{false}; | ||
|
||
std::vector<std::string> m_intkeys{}, m_floatkeys{}, m_doublekeys{}, m_stringkeys{}; | ||
|
||
std::vector<std::vector<int>> m_intvalues{}; | ||
std::vector<std::vector<float>> m_floatvalues{}; | ||
std::vector<std::vector<double>> m_doublevalues{}; | ||
std::vector<std::vector<std::string>> m_stringvalues{}; | ||
|
||
template <typename T> | ||
std::pair<std::vector<std::string>&, std::vector<std::vector<T>>&> getKeyValueVectors(); | ||
}; | ||
|
||
} // namespace podio | ||
|
||
#endif // PODIO_ROOTNTUPLEWRITER_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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not entirely happy with this one. But at the moment we seem to not have any other option(?).
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.
Not yet, it's in my todo list