File: uproot-root-parallel.py

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 (44 lines) | stat: -rw-r--r-- 1,074 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
import threading
import time
import sys

import uproot

num_workers = int(sys.argv[1])

print(f"prepare {num_workers}")

class Worker(threading.Thread):
    def __init__(self):
        super(Worker, self).__init__()
        self.objectarrays = []

    def add(self, branch, basket):
        self.objectarrays.append(uproot.interpretation.objects.ObjectArray(branch.interpretation.model, branch, {}, basket.byte_offsets, basket.data, 0))

    def run(self):
        for objectarray in self.objectarrays:
            for x in objectarray:
                pass

workers = [Worker() for i in range(num_workers)]

branch = uproot.open("/home/jpivarski/storage/data/chep-2021-jagged-jagged-jagged/zlib0-jagged3.root:tree/branch")
baskets = [branch.basket(i) for i in range(72)]

for i, basket in enumerate(baskets):
    workers[i % num_workers].add(branch, basket)

print("begin")
begin = time.time()

for worker in workers:
    worker.start()

for worker in workers:
    worker.join()

end = time.time()
print("end")

print(f"Uproot {num_workers} workers {end - begin} seconds")