79 lines
1.6 KiB
C++
79 lines
1.6 KiB
C++
#include <ROOT/RNTupleReader.hxx>
|
|
#include <ROOT/RNTuple.hxx>
|
|
#include <TFile.h>
|
|
|
|
#include <cstdio>
|
|
#include <cstdint>
|
|
|
|
#include <sys/mman.h>
|
|
#include <unistd.h>
|
|
|
|
#ifdef DEBUG
|
|
#include <sanitizer/asan_interface.h>
|
|
#endif
|
|
|
|
#include "types.h"
|
|
#include "defer.hpp"
|
|
#include "mem.h"
|
|
|
|
#include "mem.cpp"
|
|
|
|
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 < 3) {
|
|
fprintf(stderr, "Usage: %s <ntuple_name> <ntuple_file.root>\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
// Collect arguments
|
|
const char *ntpl_name = argv[1];
|
|
const char *fname = argv[2];
|
|
|
|
// Allocate memory
|
|
Arena *arena = arena_alloc();
|
|
if (!arena) {
|
|
fprintf(stderr, "Failed to allocate memory\n");
|
|
return 1;
|
|
}
|
|
defer { arena_release(arena); };
|
|
|
|
// Open and map the file
|
|
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); };
|
|
|
|
// Open the TFile
|
|
TFile *tfile = TFile::Open(fname, "READ");
|
|
if (!tfile) {
|
|
fprintf(stderr, "Failed to open TFile.\n");
|
|
return 1;
|
|
}
|
|
defer { delete tfile; };
|
|
|
|
// Get the RNTuple information
|
|
const RNTuple *anchor = tfile->Get<RNTuple>(ntpl_name);
|
|
if (!anchor) {
|
|
fprintf(stderr, "RNTuple '%s' not found in %s.\n", ntpl_name, fname);
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|