Project
Loading...
Searching...
No Matches
dump.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12// o2-aod-native-dump <file> <DF_x/O2tree> <output.arrow> [--threads N] [--pread]
13//
14// Decodes one tree with the ROOT-free reader into heap memory and writes it
15// as an Arrow IPC stream, with the dataset schema of the TTree plugin.
16
18#include "AODNative/Container.h"
19#include "AODNative/Errors.h"
20#include <arrow/io/file.h>
21#include <arrow/ipc/writer.h>
22#include <cstdio>
23#include <cstring>
24#include <string>
25
26using namespace o2::aod::native;
27
28int main(int argc, char** argv)
29{
30 std::vector<std::string> args;
31 Options options;
32 for (int i = 1; i < argc; ++i) {
33 if (std::strcmp(argv[i], "--threads") == 0 && i + 1 < argc) {
34 options.threads = std::stoi(argv[++i]);
35 } else if (std::strcmp(argv[i], "--pread") == 0) {
36 options.localIO = Options::LocalIO::PRead;
37 } else {
38 args.push_back(argv[i]);
39 }
40 }
41 if (args.size() != 3 || args[1].find('/') == std::string::npos) {
42 std::fprintf(stderr, "usage: %s <file> <DF_x/O2tree> <output.arrow> [--threads N] [--pread]\n", argv[0]);
43 return 2;
44 }
45 auto df = args[1].substr(0, args[1].find('/'));
46 auto treeName = args[1].substr(args[1].find('/') + 1);
47 try {
48 RootFile file{ByteSource::open(args[0], options)};
49 std::optional<TreeInfo> tree;
50 for (auto& key : file.keysOf(df)) {
51 if (key.name == treeName) {
52 tree = file.readTree(key);
53 }
54 }
55 if (!tree) {
56 throw FormatError("no tree " + treeName + " in " + df);
57 }
58 auto batch = readTree(file.source(), *tree, options).ValueOrDie();
59 auto out = arrow::io::FileOutputStream::Open(args[2]).ValueOrDie();
60 auto writer = arrow::ipc::MakeStreamWriter(out, batch->schema()).ValueOrDie();
61 auto status = writer->WriteRecordBatch(*batch);
62 if (status.ok()) {
63 status = writer->Close();
64 }
65 if (!status.ok()) {
66 std::fprintf(stderr, "%s: %s\n", argv[0], status.ToString().c_str());
67 return 1;
68 }
69 } catch (FormatError const& e) {
70 std::fprintf(stderr, "%s: %s\n", argv[0], e.what());
71 return 1;
72 }
73 return 0;
74}
int32_t i
StringRef key
static std::unique_ptr< ByteSource > open(std::string url, const Options &)
arrow::Result< std::shared_ptr< arrow::RecordBatch > > readTree(ByteSource &source, TreeInfo const &tree, Options const &options, arrow::MemoryPool *pool=arrow::default_memory_pool())
Reads a whole tree into heap memory: plan, execute, wrap.
#define main
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))