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. 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 | RImportTransformation |
Base class to perform data transformations from TTree branches to RNTuple fields if necessary. More... | |
class | RProgressCallback |
Used to report every ~100 MB (compressed), and at the end about the status of the import. More... | |
Public Types | |
using | FieldModifier_t = std::function< void(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 | |
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 (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 (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::Experimental::RResult< void > | InitDestination (std::string_view destFileName) |
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< 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. | |
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< RNTupleModel > | fModel |
std::string | fNTupleName |
std::unique_ptr< RProgressCallback > | fProgressCallback |
std::unique_ptr< TFile > | fSourceFile |
TTree * | fSourceTree |
RNTupleWriteOptions | fWriteOptions |
#include <ROOT/RNTupleImporter.hxx>
using ROOT::Experimental::RNTupleImporter::FieldModifier_t = std::function<void(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 80 of file RNTupleImporter.cxx.
|
static |
Directly uses the provided tree and opens the output file for writing (update).
Definition at line 106 of file RNTupleImporter.cxx.
|
inline |
Definition at line 255 of file RNTupleImporter.hxx.
void ROOT::Experimental::RNTupleImporter::Import | ( | ) |
Import works in two steps:
Definition at line 371 of file RNTupleImporter.cxx.
|
private |
Definition at line 130 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 161 of file RNTupleImporter.cxx.
|
private |
Definition at line 141 of file RNTupleImporter.cxx.
|
private |
Definition at line 151 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 262 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 269 of file RNTupleImporter.hxx.
|
inline |
Whether or not information and progress is printed to stdout.
Definition at line 265 of file RNTupleImporter.hxx.
|
inline |
Definition at line 258 of file RNTupleImporter.hxx.
|
inline |
Definition at line 257 of file RNTupleImporter.hxx.
|
inline |
Definition at line 256 of file RNTupleImporter.hxx.
|
private |
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 214 of file RNTupleImporter.hxx.
|
private |
Definition at line 209 of file RNTupleImporter.hxx.
|
private |
Definition at line 207 of file RNTupleImporter.hxx.
|
private |
Definition at line 225 of file RNTupleImporter.hxx.
|
private |
Definition at line 222 of file RNTupleImporter.hxx.
|
private |
Definition at line 226 of file RNTupleImporter.hxx.
|
private |
Definition at line 227 of file RNTupleImporter.hxx.
|
private |
The list of transformations to be performed for every entry.
Definition at line 231 of file RNTupleImporter.hxx.
|
private |
No standard output, conversely if set to false, schema information and progress is printed.
Definition at line 220 of file RNTupleImporter.hxx.
|
private |
Maps the count leaf to the information about the corresponding untyped collection.
Definition at line 229 of file RNTupleImporter.hxx.
|
private |
The maximum number of entries to import. When this value is -1 (default), import all entries.
Definition at line 217 of file RNTupleImporter.hxx.
|
private |
Definition at line 224 of file RNTupleImporter.hxx.
|
private |
Definition at line 208 of file RNTupleImporter.hxx.
|
private |
Definition at line 221 of file RNTupleImporter.hxx.
|
private |
Definition at line 204 of file RNTupleImporter.hxx.
|
private |
Definition at line 205 of file RNTupleImporter.hxx.
|
private |
Definition at line 210 of file RNTupleImporter.hxx.