File: read_jagged1_root.C

package info (click to toggle)
python-awkward 2.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 23,088 kB
  • sloc: python: 148,689; cpp: 33,562; sh: 432; makefile: 21; javascript: 8
file content (60 lines) | stat: -rw-r--r-- 1,636 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <iostream>
#include <vector>
#include <chrono>

#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TInterpreter.h"

void read_jagged1_root() {
  gInterpreter->GenerateDictionary("vector<float>", "vector");

  std::vector<float>* data;
  data = nullptr;

  TFile* f = new TFile("/home/jpivarski/storage/data/chep-2021-jagged-jagged-jagged/zlib9-jagged1.root");
  TTree* t;
  f->GetObject("tree", t);

  TBranch* b;
  b = nullptr;
  t->SetBranchAddress("branch", &data, &b);

  auto begin_time = std::chrono::high_resolution_clock::now();

  int64_t num_entries = b->GetEntries();
  int64_t num_baskets = b->GetWriteBasket();
  Long64_t* basket_starts = b->GetBasketEntry();
  for (int64_t basketid = 0;  basketid < num_baskets;  basketid++) {
    int64_t start = basket_starts[basketid];
    int64_t stop = num_entries;
    if (basketid + 1 < num_baskets) {
      stop = basket_starts[basketid + 1];
    }

    std::vector<int32_t> offsets0;
    std::vector<float> content;

    offsets0.reserve(1024);
    content.reserve(1024);

    offsets0.push_back(0);

    for (int64_t i = start;  i < stop;  i++) {
      b->GetEntry(i);

      offsets0.push_back(offsets0.back() + data->size());
      std::copy(data->begin(), data->end(), std::back_inserter(content));
    }
  }

  auto end_time = std::chrono::high_resolution_clock::now();

  int64_t count_nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(
      end_time - begin_time
  ).count();

  std::cout << "ROOT zlib9-jagged1.root " << num_entries << " entries " << (count_nanoseconds / 1e9) << " seconds" << std::endl;
}