Skip to content

Commit 053f615

Browse files
committed
[io] Add ROOT::Internal::DumpBin(TMemFile &) for debugging purposes
1 parent f4a7d74 commit 053f615

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

io/io/inc/TMemFile.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@
1616
#include <vector>
1717
#include <memory>
1818

19+
class TMemFile;
20+
21+
namespace ROOT::Internal {
22+
23+
void DumpBin(const TMemFile &file, FILE *out);
24+
25+
}
26+
1927
class TMemFile : public TFile {
28+
friend void ROOT::Internal::DumpBin(const TMemFile &file, FILE *out);
29+
2030
public:
2131
using ExternalDataPtr_t = std::shared_ptr<const std::vector<char>>;
2232
/// A read-only memory range which we do not control.

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_dump.root", "wb");
322+
/// ROOT::Internal::DumpBin(memFile, out);
323+
/// fclose(out);
324+
/// ~~~
325+
void ROOT::Internal::DumpBin(const TMemFile &file, FILE *out)
326+
{
327+
const auto *cur = &file.fBlockList;
328+
while (cur && cur->fSize) {
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)