diff --git a/io/io/inc/TMemFile.h b/io/io/inc/TMemFile.h index 3b40651d6f167..fc6f111f89ed1 100644 --- a/io/io/inc/TMemFile.h +++ b/io/io/inc/TMemFile.h @@ -16,7 +16,17 @@ #include #include +class TMemFile; + +namespace ROOT::Internal { + +void DumpBin(const TMemFile &file, FILE *out); + +} + class TMemFile : public TFile { + friend void ROOT::Internal::DumpBin(const TMemFile &file, FILE *out); + public: using ExternalDataPtr_t = std::shared_ptr>; /// A read-only memory range which we do not control. diff --git a/io/io/src/TMemFile.cxx b/io/io/src/TMemFile.cxx index cf134cbb3458b..e4f91aca9a75f 100644 --- a/io/io/src/TMemFile.cxx +++ b/io/io/src/TMemFile.cxx @@ -312,6 +312,26 @@ void TMemFile::Print(Option_t *option /* = "" */) const } } +//////////////////////////////////////////////////////////////////////////////// +/// Writes the contents of the TMemFile to the given file. This is meant to be +/// used mostly for debugging, as it dumps the current file's content as-is with +/// no massaging (meaning the content might not be a valid ROOT file): for regular use cases, use Cp(). +/// Example usage: +/// ~~~ {.cpp} +/// FILE *out = fopen("memfile_dump.root", "wb"); +/// ROOT::Internal::DumpBin(memFile, out); +/// fclose(out); +/// ~~~ +void ROOT::Internal::DumpBin(const TMemFile &file, FILE *out) +{ + const auto *cur = &file.fBlockList; + while (cur && cur->fSize) { + fwrite(cur->fBuffer, cur->fSize, 1, out); + cur = cur->fNext; + } + fflush(out); +} + //////////////////////////////////////////////////////////////////////////////// /// Wipe all the data from the permanent buffer but keep, the in-memory object /// alive.