Skip to content

Commit ea94ecf

Browse files
silverweedguitargeek
authored andcommitted
[ntuple] add cloning for RImplSimple-based writer
(cherry picked from commit 6598334)
1 parent b53b083 commit ea94ecf

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

tree/ntuple/src/RMiniFile.cxx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,11 +1336,21 @@ ROOT::Internal::RNTupleFileWriter::Append(std::string_view ntupleName, ROOT::Exp
13361336
std::unique_ptr<ROOT::Internal::RNTupleFileWriter>
13371337
ROOT::Internal::RNTupleFileWriter::CloneAsHidden(std::string_view ntupleName) const
13381338
{
1339-
if (auto *file = std::get_if<RImplTFile>(&fFile)) {
1340-
return Append(ntupleName, *file->fDirectory, fNTupleAnchor.fMaxKeySize, /* hidden= */ true);
1341-
}
1342-
// TODO: support also non-TFile-based writers
1343-
throw ROOT::RException(R__FAIL("cannot clone a non-TFile-based RNTupleFileWriter."));
1339+
if (auto *tfile = std::get_if<RImplTFile>(&fFile)) {
1340+
return Append(ntupleName, *tfile->fDirectory, fNTupleAnchor.fMaxKeySize, /* hidden= */ true);
1341+
} else if (auto *file = std::get_if<RImplSimple>(&fFile)) {
1342+
if (fIsBare)
1343+
throw ROOT::RException(R__FAIL("cloning a bare file is currently unsupported"));
1344+
1345+
auto writer = std::unique_ptr<RNTupleFileWriter>(
1346+
new RNTupleFileWriter(ntupleName, fNTupleAnchor.GetMaxKeySize(), /*hidden=*/true));
1347+
auto &clonedFile = std::get<RImplSimple>(writer->fFile);
1348+
clonedFile.fShared = file->fShared;
1349+
clonedFile.fDirectIO = file->fDirectIO;
1350+
return writer;
1351+
}
1352+
// TODO: support also RFile-based writers
1353+
throw ROOT::RException(R__FAIL("cannot clone an RFile-based RNTupleFileWriter."));
13441354
}
13451355

13461356
void ROOT::Internal::RNTupleFileWriter::Seek(std::uint64_t offset)
@@ -1404,7 +1414,7 @@ ROOT::Internal::RNTupleLink ROOT::Internal::RNTupleFileWriter::Commit(int compre
14041414
// Writing by C file stream: prepare the container format header and stream the RNTuple anchor object
14051415
auto &fileSimple = std::get<RImplSimple>(fFile);
14061416
auto &shared = *fileSimple.fShared;
1407-
1417+
14081418
RTFNTuple ntupleOnDisk(fNTupleAnchor);
14091419
anchorInfo.fLocator.SetPosition(shared.fControlBlock->fSeekNTuple);
14101420

@@ -1424,12 +1434,11 @@ ROOT::Internal::RNTupleLink ROOT::Internal::RNTupleFileWriter::Commit(int compre
14241434
WriteTFileFreeList(); // NOTE: this is written uncompressed
14251435

14261436
// Update header and TFile record
1427-
memcpy(shared.fHeaderBlock, &shared.fControlBlock->fHeader,
1428-
shared.fControlBlock->fHeader.GetSize());
1437+
memcpy(shared.fHeaderBlock, &shared.fControlBlock->fHeader, shared.fControlBlock->fHeader.GetSize());
14291438
R__ASSERT(shared.fControlBlock->fSeekFileRecord + shared.fControlBlock->fFileRecord.GetSize() <
14301439
RImplSimple::kHeaderBlockSize);
1431-
memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekFileRecord,
1432-
&shared.fControlBlock->fFileRecord, shared.fControlBlock->fFileRecord.GetSize());
1440+
memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekFileRecord, &shared.fControlBlock->fFileRecord,
1441+
shared.fControlBlock->fFileRecord.GetSize());
14331442

14341443
fileSimple.Flush();
14351444

0 commit comments

Comments
 (0)