Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions tree/ntuple/inc/ROOT/RMiniFile.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,19 @@ private:
/// The RNTuple class description is always present.
ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t fStreamerInfoMap;

/// Private constructor used by all factory methods.
/// Note that, in case of "owned" files (those created via Recreate) there must be exactly one non-hidden
/// RNTupleFileWriter which is responsible for serializing the ROOT file metadata.
/// This is enforced by the public API, as the only way to create a hidden FileWriter is via CloneAsHidden (which
/// creates a secondary hidden writer over the same file) and Append (which never writes the file metadata because
/// they are already handled by the "real" TFile).
explicit RNTupleFileWriter(std::string_view name, std::uint64_t maxKeySize, bool isHidden);

/// For a TFile container written by a C file stream, write the header and TFile object
void WriteTFileSkeleton(int defaultCompression);
/// The only key that will be visible in file->ls()
/// Returns the size on disk of the anchor object
std::uint64_t WriteTFileNTupleKey(int compression);
/// Returns the link to the RNTuple anchor.
ROOT::Internal::RNTupleLink WriteTFileNTupleKey(int compression);
/// Write the TList with the RNTuple key
void WriteTFileKeysList(std::uint64_t anchorSize);
/// Write the compressed streamer info record with the description of the RNTuple class
Expand Down
47 changes: 27 additions & 20 deletions tree/ntuple/src/RMiniFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1412,34 +1412,34 @@ ROOT::Internal::RNTupleLink ROOT::Internal::RNTupleFileWriter::Commit(int compre
auto &fileSimple = std::get<RImplSimple>(fFile);
auto &shared = *fileSimple.fShared;

RTFNTuple ntupleOnDisk(fNTupleAnchor);
anchorInfo.fLocator.SetPosition(shared.fControlBlock->fSeekNTuple);

if (fIsBare) {
RTFNTuple ntupleOnDisk(fNTupleAnchor);

// Compute the checksum
std::uint64_t checksum = XXH3_64bits(ntupleOnDisk.GetPtrCkData(), ntupleOnDisk.GetSizeCkData());
memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekNTuple, &ntupleOnDisk, ntupleOnDisk.GetSize());
memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekNTuple + ntupleOnDisk.GetSize(), &checksum,
sizeof(checksum));
fileSimple.Flush();

anchorInfo.fLocator.SetPosition(shared.fControlBlock->fSeekNTuple);
anchorInfo.fLocator.SetNBytesOnStorage(ntupleOnDisk.GetSize());
} else {
auto anchorSize = WriteTFileNTupleKey(compression);
WriteTFileKeysList(anchorSize); // NOTE: this is written uncompressed
WriteTFileStreamerInfo(compression);
WriteTFileFreeList(); // NOTE: this is written uncompressed

// Update header and TFile record
memcpy(shared.fHeaderBlock, &shared.fControlBlock->fHeader, shared.fControlBlock->fHeader.GetSize());
R__ASSERT(shared.fControlBlock->fSeekFileRecord + shared.fControlBlock->fFileRecord.GetSize() <
RImplSimple::kHeaderBlockSize);
memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekFileRecord, &shared.fControlBlock->fFileRecord,
shared.fControlBlock->fFileRecord.GetSize());
anchorInfo = WriteTFileNTupleKey(compression);
if (!fIsHidden) {
WriteTFileKeysList(anchorInfo.fLocator.GetNBytesOnStorage()); // NOTE: this is written uncompressed
WriteTFileStreamerInfo(compression);
WriteTFileFreeList(); // NOTE: this is written uncompressed

// Update header and TFile record
memcpy(shared.fHeaderBlock, &shared.fControlBlock->fHeader, shared.fControlBlock->fHeader.GetSize());
R__ASSERT(shared.fControlBlock->fSeekFileRecord + shared.fControlBlock->fFileRecord.GetSize() <
RImplSimple::kHeaderBlockSize);
memcpy(shared.fHeaderBlock + shared.fControlBlock->fSeekFileRecord, &shared.fControlBlock->fFileRecord,
shared.fControlBlock->fFileRecord.GetSize());
}

fileSimple.Flush();

anchorInfo.fLocator.SetNBytesOnStorage(anchorSize);
}
}

Expand Down Expand Up @@ -1677,7 +1677,7 @@ void ROOT::Internal::RNTupleFileWriter::WriteTFileFreeList()
fileSimple.fShared->fControlBlock->fHeader.SetEnd(fileShared.fFilePos);
}

std::uint64_t ROOT::Internal::RNTupleFileWriter::WriteTFileNTupleKey(int compression)
ROOT::Internal::RNTupleLink ROOT::Internal::RNTupleFileWriter::WriteTFileNTupleKey(int compression)
{
RTFString strRNTupleClass{"ROOT::RNTuple"};
RTFString strRNTupleName{fNTupleName};
Expand All @@ -1698,9 +1698,16 @@ std::uint64_t ROOT::Internal::RNTupleFileWriter::WriteTFileNTupleKey(int compres
char zipAnchor[RTFNTuple::GetSizePlusChecksum()];
auto szZipAnchor = RNTupleCompressor::Zip(keyBuf, sizeAnchor, compression, zipAnchor);

fileSimple.WriteKey(zipAnchor, szZipAnchor, sizeof(keyBuf), fileSimple.fShared->fControlBlock->fSeekNTuple,
RTFHeader::kBEGIN, "ROOT::RNTuple", fNTupleName, "");
return szZipAnchor;
ROOT::Internal::RNTupleLink anchorLink;
auto anchorOffset =
fileSimple.WriteKey(zipAnchor, szZipAnchor, sizeof(keyBuf), fileSimple.fShared->fControlBlock->fSeekNTuple,
RTFHeader::kBEGIN, "ROOT::RNTuple", fNTupleName, "");

assert(szZipAnchor < std::numeric_limits<decltype(anchorLink.fLength)>::max());
anchorLink.fLength = sizeof(keyBuf);
anchorLink.fLocator.SetPosition(anchorOffset);
anchorLink.fLocator.SetNBytesOnStorage(szZipAnchor);
return anchorLink;
}

void ROOT::Internal::RNTupleFileWriter::WriteTFileSkeleton(int defaultCompression)
Expand Down
Loading
Loading