-
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 support for the new RNTuple format (#395)
* Add a RNTuple writer * Cleanup and add a reader * Add compilation instructions for RNTuple * Add tests * Fix the reader and writer so that they pass most of the tests * Commit missing changes in the header * Add support for Generic Parameters * Add an ugly workaround to the unique_ptr issue * Read also vector members and remove some comments * Do a bit of cleanup * Do more cleanup, also compiler warnings * Add names in rootUtils.h, fix a few compiler warnings * Add a few minor changes * Add missing changes in the headers * Change map -> unordered_map and use append in CMakeLists.txt * Simplify writing and reading of generic parameters * Only create the ID table once * Add CollectionInfo structs * Add a ROOT version check * Add missing endif() * Add Name at the end of some names * Add missing Name at the end * Cast to rvalue * Cache entries and reserve * Add comment and remove old comments * Remove a few couts * Remove intermediate variables and use std::move * Run clang-format * Use clang-format on tests too * Enable RNTuple I/O in Key4hep CI * Check if dev3 workflows come with recent enough ROOT * Change MakeField to the new signature * Update the RNTuple reader and writer to use the buffer factory * Run clang-format * Update the RNTuple writer to use a bare model * Add friends for Generic Parameters * Update changes after the changes in the collectionID and string_view * Run clang-format * Update the reader and writer to conform to #405 * Reorganize and clean up code in the reader * Run clang-format * Simplify how the references are filled --------- Co-authored-by: jmcarcell <jmcarcell@users.noreply.github.com> Co-authored-by: tmadlener <thomas.madlener@desy.de>
- Loading branch information
1 parent
d8294d2
commit 1e8a8f9
Showing
16 changed files
with
762 additions
and
6 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
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.