first commit

This commit is contained in:
silverweed 2024-07-10 17:04:11 +02:00
commit 136d7df643
4 changed files with 75 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
*~
*.swo
*.swp
rntviewer

7
Makefile Normal file
View file

@ -0,0 +1,7 @@
CXX = clang++
d:
$(CXX) -g -O0 -o rntviewer rntviewer.cpp $(shell root-config --cflags --libs) -lROOTNTuple
r:
$(CXX) -O2 -o rntviewer rntviewer.cpp $(shell root-config --cflags --libs) -lROOTNTuple

20
defer.hpp Normal file
View file

@ -0,0 +1,20 @@
#pragma once
#include <functional>
#include <utility>
struct Defer_Guard {
template <typename F>
Defer_Guard(F && f) : _f(f) {}
~Defer_Guard() { _f(); }
std::function<void()> _f;
};
struct Defer_Guard_Helper {
template <typename F>
Defer_Guard operator+(F&& f) { return Defer_Guard(std::forward<F>(f)); }
};
#define CONCAT_STR_INTERNAL(A, B) A##B
#define CONCAT_STR(A, B) CONCAT_STR_INTERNAL(A, B)
#define defer const auto CONCAT_STR(defer_, __LINE__) = Defer_Guard_Helper{} + [&]

44
rntviewer.cpp Normal file
View file

@ -0,0 +1,44 @@
#include "defer.hpp"
#include <ROOT/RNTupleReader.hxx>
#include <cstdio>
#include <sys/mman.h>
using namespace ROOT::Experimental;
static size_t file_size(FILE *f)
{
fseek(f, 0, SEEK_END);
size_t res = ftell(f);
fseek(f, 0, SEEK_SET);
return res;
}
int main(int argc, char **argv)
{
if (argc < 2) {
fprintf(stderr, "Usage: %s <ntuple_file.root>\n", argv[0]);
return 1;
}
// Open and map the file
const char *fname = argv[0];
FILE *file = fopen(fname, "rb");
defer { fclose(file); };
const int fd = fileno(file);
const size_t fsize = file_size(file);
void *fmem = mmap(0, fsize, PROT_READ, MAP_SHARED_VALIDATE, fd, 0);
if (!fmem) {
fprintf(stderr, "Failed to open file %s\n", fname);
return 1;
}
defer { munmap(fmem, fsize); };
// Get the RNTuple information
return 0;
}