Converts a TTree into an RNTuple.
Example usage (see the ntpl008_import.C tutorial for a full example):
The output file is created if it does not exist, otherwise the ntuple is added to the existing file. Directories in the output file are created as necessary, allowing ntuples to be stored in a nested structure (e.g. DirName/TreeName). Note that input file and output file can be identical if the ntuple is stored under a different name than the tree (use SetNTupleName()).
By default, the RNTuple is compressed with zstd, independent of the input compression. The compression settings (and other output parameters) can be changed by SetWriteOptions(). For example, to compress the imported RNTuple using lz4 (with compression level 4) instead:
Most RNTuple fields have a type identical to the corresponding TTree input branch. Exceptions are
std::string fieldsstd::array<...> fields_collection0, _collection1, etc.). In order to keep field names and branch names aligned, RNTuple projects the members of these collections and its collection counter to the input branch names. For instance, the following input leafs: will be converted to the following RNTuple schema: Current limitations of the importer:
Definition at line 103 of file RNTupleImporter.hxx.
Classes | |
| struct | RCStringTransformation |
Transform a NULL terminated C string branch into an std::string field. More... | |
| struct | RImportBranch |
| struct | RImportField |
| struct | RImportGuard |
| When the schema is set up and the import started, it needs to be reset before the next Import() call can start. More... | |
| struct | RImportLeafCountCollection |
| Leaf count arrays require special treatment. More... | |
| struct | RImportReport |
| Summary printed after the RNTuple writer commits (footer, streamer info, last cluster). More... | |
| struct | RImportTransformation |
| Base class to perform data transformations from TTree branches to RNTuple fields if necessary. More... | |
| class | RProgressCallback |
| Used to report every ~100 MB of compressed page payload, and at the end about the status of the import. More... | |
Public Types | |
| using | FieldModifier_t = std::function<void(ROOT::RFieldBase &)> |
| Used to make adjustments to the fields of the output model. | |
Public Member Functions | |
| RNTupleImporter (const RNTupleImporter &other)=delete | |
| RNTupleImporter (RNTupleImporter &&other)=delete | |
| ~RNTupleImporter ()=default | |
| RImportReport | GetLastImportReport () const |
| Metrics from the most recent Import() call (always filled, even when quiet). | |
| ROOT::RNTupleWriteOptions | GetWriteOptions () const |
| void | Import () |
| Import works in two steps: | |
| RNTupleImporter & | operator= (const RNTupleImporter &other)=delete |
| RNTupleImporter & | operator= (RNTupleImporter &&other)=delete |
| void | SetConvertDotsInBranchNames (bool value) |
| Whereas branch names may contain dots, RNTuple field names may not. | |
| void | SetFieldModifier (const FieldModifier_t &modifier) |
| Add custom method to adjust column representations. | |
| void | SetIsQuiet (bool value) |
| Whether or not information and progress is printed to stdout. | |
| void | SetMaxEntries (std::uint64_t maxEntries) |
| void | SetNTupleName (const std::string &name) |
| void | SetWriteOptions (const ROOT::RNTupleWriteOptions &options) |
Static Public Member Functions | |
| static std::unique_ptr< RNTupleImporter > | Create (std::string_view sourceFileName, std::string_view treeName, std::string_view destFileName) |
| Opens the input file for reading and the output file for writing (update). | |
| static std::unique_ptr< RNTupleImporter > | Create (TTree *sourceTree, std::string_view destFileName) |
| Directly uses the provided tree and opens the output file for writing (update). | |
Private Member Functions | |
| RNTupleImporter ()=default | |
| ROOT::RResult< void > | InitDestination (std::string_view destFileName) |
| ROOT::RResult< void > | PrepareSchema () |
| Sets up the connection from TTree branches to RNTuple fields, including initialization of the memory buffers used for reading and writing. | |
| void | ReportSchema () |
| void | ResetSchema () |
Private Attributes | |
| bool | fConvertDotsInBranchNames = false |
| Whether or not dot characters in branch names should be converted to underscores. | |
| std::unique_ptr< TFile > | fDestFile |
| std::string | fDestFileName |
| std::unique_ptr< ROOT::REntry > | fEntry |
| FieldModifier_t | fFieldModifier |
| std::vector< RImportBranch > | fImportBranches |
| std::vector< RImportField > | fImportFields |
| std::vector< std::unique_ptr< RImportTransformation > > | fImportTransformations |
| The list of transformations to be performed for every entry. | |
| bool | fIsQuiet = false |
| No standard output, conversely if set to false, schema information and progress is printed. | |
| RImportReport | fLastImportReport {} |
| std::map< std::string, RImportLeafCountCollection > | fLeafCountCollections |
| Maps the count leaf to the information about the corresponding untyped collection. | |
| std::int64_t | fMaxEntries = -1 |
| The maximum number of entries to import. When this value is -1 (default), import all entries. | |
| std::unique_ptr< ROOT::RNTupleModel > | fModel |
| std::string | fNTupleName |
| std::unique_ptr< RProgressCallback > | fProgressCallback |
| std::unique_ptr< TFile > | fSourceFile |
| TTree * | fSourceTree |
| ROOT::RNTupleWriteOptions | fWriteOptions |
#include <ROOT/RNTupleImporter.hxx>
| using ROOT::Experimental::RNTupleImporter::FieldModifier_t = std::function<void(ROOT::RFieldBase &)> |
Used to make adjustments to the fields of the output model.
Definition at line 106 of file RNTupleImporter.hxx.
|
privatedefault |
|
delete |
|
delete |
|
default |
|
static |
Opens the input file for reading and the output file for writing (update).
Definition at line 115 of file RNTupleImporter.cxx.
|
static |
Directly uses the provided tree and opens the output file for writing (update).
Definition at line 141 of file RNTupleImporter.cxx.
|
inline |
Metrics from the most recent Import() call (always filled, even when quiet).
Definition at line 286 of file RNTupleImporter.hxx.
|
inline |
Definition at line 273 of file RNTupleImporter.hxx.
| void ROOT::Experimental::RNTupleImporter::Import | ( | ) |
Import works in two steps:
Definition at line 421 of file RNTupleImporter.cxx.
|
private |
Definition at line 165 of file RNTupleImporter.cxx.
|
delete |
|
delete |
|
private |
Sets up the connection from TTree branches to RNTuple fields, including initialization of the memory buffers used for reading and writing.
Definition at line 196 of file RNTupleImporter.cxx.
|
private |
Definition at line 176 of file RNTupleImporter.cxx.
|
private |
Definition at line 186 of file RNTupleImporter.cxx.
|
inline |
Whereas branch names may contain dots, RNTuple field names may not.
By setting this option, dot characters are automatically converted into underscores to prevent the importer from throwing an exception.
Definition at line 280 of file RNTupleImporter.hxx.
|
inline |
Add custom method to adjust column representations.
Will be called for every field of the frozen model before it is attached to the page sink
Definition at line 290 of file RNTupleImporter.hxx.
|
inline |
Whether or not information and progress is printed to stdout.
Definition at line 283 of file RNTupleImporter.hxx.
|
inline |
Definition at line 276 of file RNTupleImporter.hxx.
|
inline |
Definition at line 275 of file RNTupleImporter.hxx.
|
inline |
Definition at line 274 of file RNTupleImporter.hxx.
Whether or not dot characters in branch names should be converted to underscores.
If this option is not set and a branch with a '.' is encountered, the importer will throw an exception.
Definition at line 231 of file RNTupleImporter.hxx.
|
private |
Definition at line 226 of file RNTupleImporter.hxx.
|
private |
Definition at line 224 of file RNTupleImporter.hxx.
|
private |
Definition at line 243 of file RNTupleImporter.hxx.
|
private |
Definition at line 240 of file RNTupleImporter.hxx.
|
private |
Definition at line 244 of file RNTupleImporter.hxx.
|
private |
Definition at line 245 of file RNTupleImporter.hxx.
|
private |
The list of transformations to be performed for every entry.
Definition at line 249 of file RNTupleImporter.hxx.
No standard output, conversely if set to false, schema information and progress is printed.
Definition at line 237 of file RNTupleImporter.hxx.
|
private |
Definition at line 238 of file RNTupleImporter.hxx.
|
private |
Maps the count leaf to the information about the corresponding untyped collection.
Definition at line 247 of file RNTupleImporter.hxx.
|
private |
The maximum number of entries to import. When this value is -1 (default), import all entries.
Definition at line 234 of file RNTupleImporter.hxx.
|
private |
Definition at line 242 of file RNTupleImporter.hxx.
|
private |
Definition at line 225 of file RNTupleImporter.hxx.
|
private |
Definition at line 239 of file RNTupleImporter.hxx.
|
private |
Definition at line 221 of file RNTupleImporter.hxx.
|
private |
Definition at line 222 of file RNTupleImporter.hxx.
|
private |
Definition at line 227 of file RNTupleImporter.hxx.