Skip to content
Open
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: 10 additions & 0 deletions io/io/inc/TMemFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
#include <vector>
#include <memory>

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<const std::vector<char>>;
/// A read-only memory range which we do not control.
Expand Down
20 changes: 20 additions & 0 deletions io/io/src/TMemFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +321 to +323
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the advantage of requiring the 3 steps instead of folding them into the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly the ability to pass stdout or similar, which would be more awkward to do with a string argument.
Also one may potentially want to dump multiple MemFiles to the same output, though that's probably rare.

/// ~~~
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.
Expand Down
Loading