improve title

This commit is contained in:
silverweed 2025-01-24 12:05:32 +01:00
parent 50efecc72a
commit 9bf2b1e0c5
4 changed files with 65 additions and 34 deletions

View file

@ -143,11 +143,14 @@ void init_viewer(Arena *arena, App_State &app, u16 n_cols)
viewer.mem_edit = make_memory_editor(app, (i32)n_cols);
// Init title
if (app.tfile_data.sections[Sec_RNTuple_Anchor].head) {
u32 n_ntuples = app.tfile_data.sections[Sec_RNTuple_Anchor].count;
if (n_ntuples) {
Temp scratch = scratch_begin(&arena, 1);
defer { scratch_end(scratch); };
const RNTuple_Anchor_Info *anchor = (const RNTuple_Anchor_Info *)app.tfile_data.sections[Sec_RNTuple_Anchor].head->info;
if (n_ntuples == 1) {
Section *sec = app.tfile_data.sections[Sec_RNTuple_Anchor].head;
const RNTuple_Anchor_Info *anchor = (const RNTuple_Anchor_Info *)sec->info;
String8 ntpl_desc = rntuple_description(scratch.arena, anchor->anchor);
if (rntuple_is_old_version(anchor->anchor)) {
viewer.col_title[0] = 1.f;
@ -157,6 +160,17 @@ void init_viewer(Arena *arena, App_State &app, u16 n_cols)
viewer.col_title[0] = viewer.col_title[1] = viewer.col_title[2] = 1.f;
viewer.title = push_str8f(arena, "\"%s\" (%s) from file \"%s\"", anchor->name.c(), ntpl_desc.c(), app.inspected_file.name.c());
}
} else {
String8 title = str8("RNTuples");
for (Section *sec = app.tfile_data.sections[Sec_RNTuple_Anchor].head; sec; sec = sec->next) {
const RNTuple_Anchor_Info *anchor = (const RNTuple_Anchor_Info *)sec->info;
title = str8_concat(scratch.arena, title, push_str8f(scratch.arena, " \"%s\",", anchor->name));
}
title.size -= 1; // strip trailing comma
title = str8_concat(scratch.arena, title, push_str8f(scratch.arena, " from file \"%s\"", app.inspected_file.name.c()));
viewer.col_title[0] = viewer.col_title[1] = viewer.col_title[2] = 1.f;
viewer.title = str8_from_buf(arena, title.str, title.size);
}
} else {
viewer.col_title[0] = viewer.col_title[1] = viewer.col_title[2] = 1.f;
viewer.title = push_str8f(arena, "(no RNTuple) from file \"%s\"", app.inspected_file.name.c());

View file

@ -40,6 +40,17 @@ String8 str8_from_buf(Arena *arena, const u8 *buf, u64 size)
return s;
}
String8 str8_concat(Arena *arena, String8 a, String8 b)
{
String8 res;
res.size = a.size + b.size;
res.str = arena_push_array_nozero<u8>(arena, res.size + 1);
memcpy(res.str, a.str, a.size);
memcpy(res.str + a.size, b.str, b.size);
res.str[res.size] = 0;
return res;
}
internal
String8 to_pretty_size(Arena *arena, u64 bytes)
{

View file

@ -79,8 +79,9 @@ enum {
// Examines the innards of a TFile to get byte range info about the TKeys.
// Additionally, it returns the names of all the RNTuples stored in it.
// `data` should point to the beginning of a ROOT file.
// If `ntpl_name` is non-empty, skip all RNTuples that are not the one specified.
internal
b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data &tfile_data)
b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data &tfile_data, String8 ntpl_name)
{
u64 cur = 4; // offset of header version
if (data_len < cur) {
@ -270,6 +271,8 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
if (key_has_class_name("ROOT::RNTuple") || key_has_class_name("ROOT::Experimental::RNTuple")) {
u64 name_off = cname_off + cname_len + 1;
u8 name_len = data[name_off];
const char *rntuple_name = (const char *)data + name_off + 1;
if (!ntpl_name.size || strncmp((const char *)ntpl_name.str, rntuple_name, name_len) == 0) {
RNTuple_Anchor_Info *rntuple_info = arena_push<RNTuple_Anchor_Info>(arena);
rntuple_info->offset_in_file = cur;
if (name_len) {
@ -293,7 +296,9 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
sec_anchor->range.len = n_bytes - keylen;
sec_anchor->pre_size = keylen;
sec_anchor->post_size = 8;
} else {
fprintf(stderr, "Note: skipped RNTuple '%s' because it doesn't match the name '%s' we're looking for.\n", rntuple_name, ntpl_name.c());
}
} else if (key_has_class_name("RBlob")) {
if (!sections[Sec_Page].head) {
push_section(arena, tfile_data, Sec_Page)->pre_size = keylen;
@ -365,6 +370,7 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
return true;
}
// Creates the RNTuple_Header and Footer sections by associating them to their proper RBlobs and Anchor.
internal
void map_rntuple_rblobs(Arena *arena, TFile_Data &tfile_data)
{
@ -425,9 +431,9 @@ void map_rntuple_rblobs(Arena *arena, TFile_Data &tfile_data)
}
internal
b8 get_tfile_data(Arena *arena, const Inspected_File &file, u32 walk_tkeys_flags, String8 &ntpl_name, TFile_Data &tfile_data)
b8 get_tfile_data(Arena *arena, const Inspected_File &file, u32 walk_tkeys_flags, String8 ntpl_name, TFile_Data &tfile_data)
{
b8 success = walk_tkeys(arena, file.mem, file.size, walk_tkeys_flags, tfile_data);
b8 success = walk_tkeys(arena, file.mem, file.size, walk_tkeys_flags, tfile_data, ntpl_name);
if (success) {
// TODO: if ntpl_name is non-empty, only pick the given RNTuple
map_rntuple_rblobs(arena, tfile_data);

BIN
testdata/multi.root vendored Normal file

Binary file not shown.