48 double v =
static_cast<double>(
nbytes);
49 if (
v >= 1024.0 * 1024.0 * 1024.0) {
50 v /= 1024.0 * 1024.0 * 1024.0;
52 }
else if (
v >= 1024.0 * 1024.0) {
55 }
else if (
v >= 1024.0) {
59 std::ostringstream os;
60 os.setf(std::ios::fixed);
61 os.precision(
v >= 100.0 ? 0 : (
v >= 10.0 ? 1 : 2));
68 static constexpr std::uint64_t gUpdateFrequencyBytes = 100 * 1000 * 1000;
69 std::uint64_t fNbytesNext = gUpdateFrequencyBytes;
79 fNbytesNext += gUpdateFrequencyBytes;
88 std::cout <<
"Done: " <<
report.fEntries <<
" entries\n";
91 if (
report.fFileBytesOnDisk >
report.fCompressedPayloadBytes) {
94 <<
" (page lists, footer, streamer info, ROOT keys)\n";
96 if (
report.fUncompressedPageBytes > 0 &&
report.fCompressedPayloadBytes > 0) {
98 static_cast<double>(
report.fCompressedPayloadBytes) /
static_cast<double>(
report.fUncompressedPageBytes);
99 std::cout <<
" page compression ratio: " << std::fixed << std::setprecision(3) <<
ratio
100 <<
" (payload / uncompressed pages)\n";
110 *
reinterpret_cast<std::string *
>(
field.fFieldBuffer) =
reinterpret_cast<const char *
>(
branch.fBranchBuffer.get());
114std::unique_ptr<ROOT::Experimental::RNTupleImporter>
131 importer->fSourceTree->SetImplicitMT(
false);
140std::unique_ptr<ROOT::Experimental::RNTupleImporter>
156 importer->fSourceTree->SetImplicitMT(
false);
179 std::cout <<
"Importing '" <<
f.fField->GetFieldName() <<
"' [" <<
f.fField->GetTypeName() <<
"]\n";
182 std::cout <<
"Importing (projected) '" <<
f->GetFieldName() <<
"' [" <<
f->GetTypeName() <<
"]\n";
205 const auto firstLeaf =
static_cast<TLeaf *
>(
b->GetListOfLeaves()->First());
212 return R__FAIL(
"unsupported: classes in leaf list, branch " + std::string(
b->GetName()));
214 return R__FAIL(
"unsupported: count leaf arrays in leaf list, branch " + std::string(
b->GetName()));
230 c.fCountVal = std::make_unique<Int_t>();
239 std::vector<std::unique_ptr<ROOT::RFieldBase>>
recordItems;
245 return R__FAIL(
"unsupported: TObject branches, branch: " + std::string(
b->GetName()));
285 f.fValue = std::make_unique<ROOT::RFieldBase::RValue>(
field->CreateValue());
286 f.fFieldBuffer =
f.fValue->GetPtr<
void>().get();
308 R__ASSERT(
b->GetListOfLeaves()->GetEntries() == 1);
324 ib.fBranchName =
b->GetName();
329 return R__FAIL(
"unable to load class " + std::string(
b->GetClassName()) +
" for branch " +
330 std::string(
b->GetName()));
332 auto ptrBuf =
reinterpret_cast<void **
>(
ib.fBranchBuffer.get());
341 isClass ? *
reinterpret_cast<void **
>(
ib.fBranchBuffer.get()) :
ib.fBranchBuffer.get();
355 auto recordField = std::make_unique<ROOT::RRecordField>(
"_0", std::move(
c.fLeafFields));
361 for (
const auto leaf :
c.fRecordField->GetConstSubfields()) {
362 const auto name =
leaf->GetFieldName();
369 return c.fFieldName +
"._0." +
name;
386 for (
auto &
field :
fModel->GetMutableFieldZero()) {
395 fEntry->BindRawPtr(
f.fField->GetFieldName(),
f.fFieldBuffer);
398 fEntry->BindRawPtr<
void>(
c.fFieldName, &
c.fFieldBuffer);
399 c.fSizeOfRecord =
c.fRecordField->GetValueSize();
400 const auto subfields =
c.fRecordField->GetConstSubfields();
401 const auto &offsets =
c.fRecordField->GetOffsets();
403 assert(
c.fPackedLeaves.empty());
409 packed.fImportBranchIdx =
c.fLeafBranchIndexes[
l];
410 c.fPackedLeaves.push_back(
packed);
412 c.fFieldBuffer.reserve(
static_cast<std::size_t
>(
c.fMaxLength) *
c.fSizeOfRecord);
443 std::unique_ptr<ROOT::Internal::RPageSink>
sink =
445 sink->GetMetrics().Enable();
450 sink = std::make_unique<ROOT::Internal::RPageSinkBuf>(std::move(
sink));
472 const auto nItems =
static_cast<std::size_t
>(*
c.fCountVal);
476 for (
const auto &
leaf :
c.fPackedLeaves) {
478 auto *
dst =
c.fFieldBuffer.data() +
leaf.fOffset;
479 for (std::size_t
j = 0;
j <
nItems; ++
j) {
507 report.fFileBytesOnDisk =
static_cast<std::uint64_t
>(
fDestFile->GetSize());
#define R__FORWARD_ERROR(res)
Short-hand to return an RResult<T> in an error state (i.e. after checking)
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Used to report every ~100 MB of compressed page payload, and at the end about the status of the impor...
bool fConvertDotsInBranchNames
Whether or not dot characters in branch names should be converted to underscores.
std::unique_ptr< ROOT::REntry > fEntry
std::unique_ptr< TFile > fDestFile
std::int64_t fMaxEntries
The maximum number of entries to import. When this value is -1 (default), import all entries.
std::map< std::string, RImportLeafCountCollection > fLeafCountCollections
Maps the count leaf to the information about the corresponding untyped collection.
RNTupleImporter()=default
std::unique_ptr< ROOT::RNTupleModel > fModel
std::vector< RImportBranch > fImportBranches
ROOT::RResult< void > InitDestination(std::string_view destFileName)
RImportReport fLastImportReport
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).
std::unique_ptr< RProgressCallback > fProgressCallback
void Import()
Import works in two steps:
ROOT::RNTupleWriteOptions fWriteOptions
std::string fDestFileName
bool fIsQuiet
No standard output, conversely if set to false, schema information and progress is printed.
std::vector< RImportField > fImportFields
FieldModifier_t fFieldModifier
std::vector< std::unique_ptr< RImportTransformation > > fImportTransformations
The list of transformations to be performed for every entry.
ROOT::RResult< void > PrepareSchema()
Sets up the connection from TTree branches to RNTuple fields, including initialization of the memory ...
ROOT::RFieldZero & GetFieldZero()
Base class for all ROOT issued exceptions.
std::vector< const RFieldBase * > GetConstSubfields() const
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId)
Factory method to resurrect a field from the stored on-disk type information.
static std::unique_ptr< RNTupleModel > CreateBare()
Creates a "bare model", i.e. an RNTupleModel with no default entry.
bool GetUseBufferedWrite() const
const_iterator begin() const
const_iterator end() const
The field for an untyped record.
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
static std::unique_ptr< RVectorField > CreateUntyped(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField)
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Describe directory structure in memory.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
TClass * IsA() const override
virtual const char * GetName() const
Returns name of object.
A TTree represents a columnar dataset.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
virtual Long64_t GetEntries() const
virtual TObjArray * GetListOfBranches()
std::unique_ptr< RNTupleWriter > CreateRNTupleWriter(std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< Internal::RPageSink > sink)
RProjectedFields & GetProjectedFieldsOfModel(RNTupleModel &model)
double ratio(double numerator, double denominator)
ROOT::RFieldBase * fField
The field is kept during schema preparation and transferred to the fModel before the writing starts.
When the schema is set up and the import started, it needs to be reset before the next Import() call ...
Leaf count arrays require special treatment.
Int_t fMaxLength
Stores count leaf GetMaximum() to create large enough buffers for the array leafs.
Summary printed after the RNTuple writer commits (footer, streamer info, last cluster).