move sections to tfile_data

This commit is contained in:
silverweed 2025-01-22 16:28:59 +01:00
parent 2d4862c234
commit 5481ed0f0e
5 changed files with 32 additions and 35 deletions

View file

@ -323,7 +323,7 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
if (ImGui::Begin("main", nullptr, main_win_flags)) {
// FIXME :multiple_anchors:
const ROOT::RNTuple &anchor = *(const ROOT::RNTuple *)app.tfile_data.tkeys_data.sections[Sec_RNTuple_Anchor].head->info;
const ROOT::RNTuple &anchor = *(const ROOT::RNTuple *)app.tfile_data.sections[Sec_RNTuple_Anchor].head->info;
String8 ntpl_desc = rntuple_description(scratch.arena, anchor);
if (rntuple_is_old_version(anchor)) {
ImGui::TextColored(ImColor(1.f, 0.f, 0.f), "\"%s\" (%s) from file \"%s\" ** old version, some data missing! **",
@ -388,7 +388,7 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
// Unique sections: just display a button that jumps to the start of it and show their size
for (u32 i = 0; i < Sec_COUNT; ++i) {
for (Section *sec = app.tfile_data.tkeys_data.sections[i].head; sec; sec = sec->next) {
for (Section *sec = app.tfile_data.sections[i].head; sec; sec = sec->next) {
if (!sec->range.len) continue;
String8 sec_name = section_names[i];

View file

@ -217,7 +217,7 @@ String8_Node *render_range_to_string(Arena *arena, App_State &app, u64 len, u64
defer { scratch_end(scratch); };
// Header
String8 ntpl_desc = rntuple_description(scratch.arena, *(const ROOT::RNTuple *)app.tfile_data.tkeys_data.sections[Sec_RNTuple_Anchor].head->info); // FIXME :multiple_anchors:
String8 ntpl_desc = rntuple_description(scratch.arena, *(const ROOT::RNTuple *)app.tfile_data.sections[Sec_RNTuple_Anchor].head->info); // FIXME :multiple_anchors:
String8_Node *result = push_str8_node(arena, nullptr, "RNTuple '%s' (%s) from file \"%s\"\n",
app.ntpl_name.c(), ntpl_desc.c(), app.inspected_file.name.c());
String8_Node *result_tail = result;

View file

@ -3,7 +3,7 @@ Section *push_section(Arena *arena, TFile_Data &tdata, Section_Id id)
{
Section *sec = arena_push<Section>(arena);
sec->id = id;
push_to_sll(tdata.tkeys_data.sections[id].head, tdata.tkeys_data.sections[id].tail, sec);
push_to_sll(tdata.sections[id].head, tdata.sections[id].tail, sec);
return sec;
}
@ -198,7 +198,7 @@ RNTuple_Data get_rntuple_data(Arena *arena, const Inspected_File &file, const TF
u32 anchor_idx = 0;
u64 n_tot_cluster_groups = 0;
u64 n_tot_clusters = 0;
for (Section *sec_anchor = tfile_data.tkeys_data.sections[Sec_RNTuple_Anchor].head; sec_anchor; sec_anchor = sec_anchor->next, ++anchor_idx) {
for (Section *sec_anchor = tfile_data.sections[Sec_RNTuple_Anchor].head; sec_anchor; sec_anchor = sec_anchor->next, ++anchor_idx) {
RNTupleDescriptor &desc = descriptors[anchor_idx];
new (&desc) RNTupleDescriptor();
desc = create_descriptor(arena, *(const ROOT::RNTuple *)sec_anchor->info, reader);
@ -217,7 +217,7 @@ RNTuple_Data get_rntuple_data(Arena *arena, const Inspected_File &file, const TF
/// Load all RNTuple data ///
anchor_idx = 0;
for (Section *sec_anchor = tfile_data.tkeys_data.sections[Sec_RNTuple_Anchor].head; sec_anchor; sec_anchor = sec_anchor->next, ++anchor_idx) {
for (Section *sec_anchor = tfile_data.sections[Sec_RNTuple_Anchor].head; sec_anchor; sec_anchor = sec_anchor->next, ++anchor_idx) {
const ROOT::RNTuple &anchor = *(const ROOT::RNTuple *)sec_anchor->info;
if (!anchor.GetNBytesHeader())
continue;
@ -476,7 +476,6 @@ Section find_section(App_State &app, u64 off, i64 hilite_cluster = -1)
assert(app.last_other_root_obj);
const RNTuple_Data &rdata = app.rndata;
const TKeys_Data &tdata = app.tfile_data.tkeys_data;
Section sec {};
// Check free slots
@ -490,14 +489,16 @@ Section find_section(App_State &app, u64 off, i64 hilite_cluster = -1)
}
for (u32 i = 1; i < Sec_COUNT; ++i) {
for (Section *sec = tdata.sections[i].head; sec; sec = sec->next) {
for (Section *sec = app.tfile_data.sections[i].head; sec; sec = sec->next) {
if (sec->range.start - sec->pre_size <= off && off < sec->range.end()) {
return *sec;
}
}
}
u64 rblob_sz = tdata.sections[Sec_Page].head->pre_size;
u64 rblob_sz = app.tfile_data.sections[Sec_Page].head->pre_size;
const TKeys_Data &tdata = app.tfile_data.tkeys_data;
/// Page fast lookup (relative to app.last_pinfo)
{

View file

@ -136,8 +136,6 @@ struct Sections {
};
struct TKeys_Data {
Sections sections[Sec_COUNT];
RNTuple_Anchor_Info *rntuples;
Byte_Range_Node *rblob_keys;
@ -145,18 +143,14 @@ struct TKeys_Data {
u64 n_other_root_obj;
};
struct RNTuple_Anchor_Node {
RNTuple_Anchor_Node *next;
Section section;
ROOT::RNTuple anchor;
};
struct TFile_Data {
u16 root_version_major;
u16 root_version_minor;
u16 root_version_patch;
u32 compression;
Sections sections[Sec_COUNT];
TKeys_Data tkeys_data;
// Sorted list of free slots in the TFile
Byte_Range *free_slots;

View file

@ -203,6 +203,8 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
RNTuple_Anchor_Info *rntuple_info_tail = nullptr;
Other_Root_Obj_Info *other_root_obj_tail = nullptr;
Sections *sections = tfile_data.sections;
u32 n_keys = 0;
// Walk through all the TKeys in the file and do two things:
// 1. assign proper start, len and pre_size to all sections as we go
@ -246,23 +248,23 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
continue;
}
if (cur == tkeys_data.sections[Sec_TKey_List].head->range.start - tkeys_data.sections[Sec_TKey_List].head->pre_size) {
if (keylen != tkeys_data.sections[Sec_TKey_List].head->pre_size ||
(u64)(n_bytes - keylen) != tkeys_data.sections[Sec_TKey_List].head->range.len)
if (cur == sections[Sec_TKey_List].head->range.start - sections[Sec_TKey_List].head->pre_size) {
if (keylen != sections[Sec_TKey_List].head->pre_size ||
(u64)(n_bytes - keylen) != sections[Sec_TKey_List].head->range.len)
{
fprintf(stderr, "Warning: inconsistent key list data, the file may have not parsed properly.\n");
fprintf(stderr, " (keylen: %u vs %lu, nbytes: %u vs %lu)\n",
keylen, tkeys_data.sections[Sec_TKey_List].head->pre_size,
n_bytes, tkeys_data.sections[Sec_TKey_List].head->range.len);
keylen, sections[Sec_TKey_List].head->pre_size,
n_bytes, sections[Sec_TKey_List].head->range.len);
}
} else if (cur == tkeys_data.sections[Sec_TFile_Info].head->range.start) {
tkeys_data.sections[Sec_TFile_Info].head->pre_size = keylen;
tkeys_data.sections[Sec_TFile_Info].head->range.start += keylen;
tkeys_data.sections[Sec_TFile_Info].head->range.len = n_bytes - keylen;
} else if (cur == tkeys_data.sections[Sec_TFile_FreeList].head->range.start) {
tkeys_data.sections[Sec_TFile_FreeList].head->pre_size = keylen;
tkeys_data.sections[Sec_TFile_FreeList].head->range.start += keylen;
tkeys_data.sections[Sec_TFile_FreeList].head->range.len = n_bytes - keylen;
} else if (cur == sections[Sec_TFile_Info].head->range.start) {
sections[Sec_TFile_Info].head->pre_size = keylen;
sections[Sec_TFile_Info].head->range.start += keylen;
sections[Sec_TFile_Info].head->range.len = n_bytes - keylen;
} else if (cur == sections[Sec_TFile_FreeList].head->range.start) {
sections[Sec_TFile_FreeList].head->pre_size = keylen;
sections[Sec_TFile_FreeList].head->range.start += keylen;
sections[Sec_TFile_FreeList].head->range.len = n_bytes - keylen;
} else {
// Check if this is a RNTuple anchor
u64 key_header_size = (key_version >= 1000) ? 18 + 16 : 18 + 8;
@ -310,7 +312,7 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
++tfile_data.n_anchors;
} else if (key_has_class_name("RBlob")) {
if (!tkeys_data.sections[Sec_Page].head) {
if (!sections[Sec_Page].head) {
push_section(arena, tfile_data, Sec_Page)->pre_size = keylen;
Section *sec_page_list = push_section(arena, tfile_data, Sec_Page_List);
sec_page_list->pre_size = keylen;
@ -346,8 +348,8 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
// adjust header section padding
{
u64 padding_end = tkeys_data.sections[Sec_TFile_Object].head->range.start - tkeys_data.sections[Sec_TFile_Object].head->pre_size;
Section &sec_header = *tkeys_data.sections[Sec_TFile_Header].head;
u64 padding_end = sections[Sec_TFile_Object].head->range.start - sections[Sec_TFile_Object].head->pre_size;
Section &sec_header = *sections[Sec_TFile_Header].head;
sec_header.post_size = padding_end - sec_header.range.len;
sec_header.range.len += sec_header.post_size;
}
@ -355,7 +357,7 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
// collect free slots
TFile_Free_Slot fs;
u64 free_slot_size = sizeof(u16) + (is_big_file ? sizeof(fs.rng.rng_long) : sizeof(fs.rng.rng_short));
Section *sec_tfile_freelist = tkeys_data.sections[Sec_TFile_FreeList].head;
Section *sec_tfile_freelist = sections[Sec_TFile_FreeList].head;
u64 free_slots_start = sec_tfile_freelist->range.start;
u64 free_slots_end = sec_tfile_freelist->range.end();
u64 n_free_slots = (free_slots_end - free_slots_start) / free_slot_size;
@ -419,7 +421,7 @@ void map_rntuple_rblobs(Arena *arena, TFile_Data &tfile_data)
u64 i = 0;
u64 best_anchor_diff = (u64)-1;
b8 *found_sec = found[sec_id == Sec_RNTuple_Footer];
for (Section *sec_anchor = tfile_data.tkeys_data.sections[Sec_RNTuple_Anchor].head; sec_anchor; sec_anchor = sec_anchor->next, ++i) {
for (Section *sec_anchor = tfile_data.sections[Sec_RNTuple_Anchor].head; sec_anchor; sec_anchor = sec_anchor->next, ++i) {
const ROOT::RNTuple &anchor = *(const ROOT::RNTuple *)sec_anchor->info;
if (!found_sec[i]) {
u64 seek = sec_id == Sec_RNTuple_Header ? anchor.GetSeekHeader() : anchor.GetSeekFooter();