Skip to content

Commit 1d8c337

Browse files
committed
[io] Add TMemFile::DumpBin for debugging purposes
1 parent acc3a76 commit 1d8c337

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

io/io/inc/TMemFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class TMemFile : public TFile {
105105
void ResetErrno() const override;
106106

107107
void Print(Option_t *option="") const override;
108+
void DumpBin(FILE *out) const;
108109

109110
ClassDefOverride(TMemFile, 0) // A ROOT file that reads/writes on a chunk of memory
110111
};

io/io/src/TMemFile.cxx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,26 @@ void TMemFile::Print(Option_t *option /* = "" */) const
312312
}
313313
}
314314

315+
////////////////////////////////////////////////////////////////////////////////
316+
/// Writes the contents of the TMemFile to the given file. This is meant to be
317+
/// used mostly for debugging, as it dumps the current file's content as-is with
318+
/// no massaging (meaning the content might not be a valid ROOT file): for regular use cases, use Cp().
319+
/// Example usage:
320+
/// ~~~ {.cpp}
321+
/// FILE *out = fopen("memfile.root", "wb");
322+
/// memFile->DumpBin(out);
323+
/// fclose(out);
324+
/// ~~~
325+
void TMemFile::DumpBin(FILE *out) const
326+
{
327+
const auto *cur = &fBlockList;
328+
while (cur) {
329+
fwrite(cur->fBuffer, cur->fSize, 1, out);
330+
cur = cur->fNext;
331+
}
332+
fflush(out);
333+
}
334+
315335
////////////////////////////////////////////////////////////////////////////////
316336
/// Wipe all the data from the permanent buffer but keep, the in-memory object
317337
/// alive.

0 commit comments

Comments
 (0)