2024-07-12 07:53:01 +00:00
|
|
|
// ************************************
|
|
|
|
// *
|
|
|
|
// * rntviewer
|
|
|
|
// *
|
|
|
|
// * A graphical RNTuple visualizer
|
|
|
|
// *
|
|
|
|
// * @author silverweed, 2024
|
|
|
|
// *
|
|
|
|
// ***********************************
|
|
|
|
// #include <ROOT/RNTupleReader.hxx>
|
|
|
|
// #include <ROOT/RNTuple.hxx>
|
|
|
|
// #include <TFile.h>
|
2024-07-10 17:38:16 +00:00
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdint>
|
2024-07-12 07:53:01 +00:00
|
|
|
#include <utility> // for std::forward
|
2024-07-10 17:38:16 +00:00
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include <sanitizer/asan_interface.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <imgui/imgui.h>
|
|
|
|
#include <imgui/backends/imgui_impl_glfw.h>
|
|
|
|
#include <imgui/backends/imgui_impl_opengl3.h>
|
2024-07-10 19:41:48 +00:00
|
|
|
#include <imgui_club/imgui_memory_editor.h>
|
2024-07-10 17:38:16 +00:00
|
|
|
|
|
|
|
#define GLFW_INCLUDE_NONE
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
2024-07-12 09:58:55 +00:00
|
|
|
#include "root/root_inc.h"
|
2024-07-12 07:53:01 +00:00
|
|
|
#include "root/RMicroFileReader.hxx"
|
2024-07-11 14:29:44 +00:00
|
|
|
|
2024-07-10 17:38:16 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "defer.hpp"
|
|
|
|
#include "mem.h"
|
2024-07-11 12:00:43 +00:00
|
|
|
#include "str.h"
|
|
|
|
#include "rntuple.h"
|
|
|
|
#include "window.h"
|
2024-07-11 12:27:19 +00:00
|
|
|
#include "render.h"
|
2024-07-10 18:11:42 +00:00
|
|
|
#include "app_state.h"
|
2024-07-10 17:38:16 +00:00
|
|
|
|
2024-07-11 12:00:43 +00:00
|
|
|
// @Platform
|
|
|
|
#include "platform_linux.h"
|
|
|
|
|
2024-07-10 17:38:16 +00:00
|
|
|
namespace chr = std::chrono;
|
|
|
|
|
|
|
|
#include "mem.cpp"
|
2024-07-11 12:00:43 +00:00
|
|
|
#include "str.cpp"
|
|
|
|
#include "rntuple.cpp"
|
2024-07-10 17:38:16 +00:00
|
|
|
#include "render.cpp"
|
|
|
|
#include "mainloop.cpp"
|
|
|
|
|
2024-07-10 19:47:37 +00:00
|
|
|
internal
|
|
|
|
b8 init_imgui(GLFWwindow* window) {
|
2024-07-10 17:38:16 +00:00
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
|
|
|
ImGuiIO& io = ImGui::GetIO(); (void) io;
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
|
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
|
|
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
2024-07-11 06:49:20 +00:00
|
|
|
ImGui_ImplOpenGL3_Init("#version 400");
|
2024-07-10 17:38:16 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-11 12:00:43 +00:00
|
|
|
internal
|
|
|
|
void app_cleanup(App_State &app)
|
|
|
|
{
|
|
|
|
os_stop_file_watch(app);
|
|
|
|
os_unmap_file(app.inspected_fmem, app.inspected_file_size);
|
|
|
|
if (app.inspected_file) fclose(app.inspected_file);
|
|
|
|
}
|
|
|
|
|
2024-07-10 17:38:16 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2024-07-11 12:00:43 +00:00
|
|
|
if (argc > 1 && argv[1][0] == '-') {
|
2024-07-10 17:38:16 +00:00
|
|
|
fprintf(stderr, "Usage: %s <ntuple_name> <ntuple_file.root>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect arguments
|
2024-07-11 12:00:43 +00:00
|
|
|
const char *ntpl_name = argc > 1 ? argv[1] : nullptr;
|
|
|
|
const char *fname = argc > 2 ? argv[2] : nullptr;
|
2024-07-10 17:38:16 +00:00
|
|
|
|
|
|
|
// Allocate program memory
|
|
|
|
Arena *arena = arena_alloc();
|
|
|
|
if (!arena) {
|
|
|
|
fprintf(stderr, "Failed to allocate memory\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
defer { arena_release(arena); };
|
|
|
|
|
|
|
|
// Init imgui and GLFW
|
|
|
|
GLFWwindow *window = init_glfw(800, 600);
|
|
|
|
if (!window) {
|
|
|
|
fprintf(stderr, "Failed to init GLFW\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
defer { glfwTerminate(); };
|
|
|
|
|
|
|
|
if (!init_imgui(window)) {
|
|
|
|
fprintf(stderr, "Failed to init Imgui\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-07-11 12:00:43 +00:00
|
|
|
App_State app {};
|
|
|
|
defer { app_cleanup(app); };
|
|
|
|
|
|
|
|
// Open and map the file
|
|
|
|
if (fname) {
|
2024-07-16 09:12:50 +00:00
|
|
|
if (!os_open_and_map_file(fname, app))
|
|
|
|
return 1;
|
2024-07-11 12:00:43 +00:00
|
|
|
|
|
|
|
// Watch file for changes (to adapt the displayed file size - otherwise
|
|
|
|
// we may try to access invalid memory when the file gets shrunk)
|
|
|
|
os_start_file_watch(fname, app);
|
2024-07-10 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
2024-07-11 12:00:43 +00:00
|
|
|
app.ntpl_name = ntpl_name;
|
2024-07-12 09:58:55 +00:00
|
|
|
app.rndata = get_rntuple_data(arena, fname, ntpl_name);
|
2024-07-11 12:27:19 +00:00
|
|
|
app.vsettings = make_viewer_settings();
|
2024-07-10 18:11:42 +00:00
|
|
|
|
2024-07-11 12:00:43 +00:00
|
|
|
// Start main loop
|
2024-07-10 18:11:42 +00:00
|
|
|
run_main_loop(window, arena, app);
|
2024-07-10 17:38:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|