-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuproot-bestcase.py
67 lines (46 loc) · 1.55 KB
/
uproot-bestcase.py
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
61
62
63
64
65
66
import sys
sys.path.insert(0, "/home/jpivarski/storage/data/python-3.13-uproot")
import time
import threading
import queue
import uproot
import numpy as np
def in_thread(which, task_descriptions):
while True:
task_description = task_descriptions.get()
if task_description is None:
break
branch, entry_start, entry_stop = task_description
array = branch.array(entry_start=entry_start, entry_stop=entry_stop)
del array
NUM_THREADS = int(sys.argv[1])
SOURCE = uproot.MemmapSource if sys.argv[2] == "mm" else None
# https://opendata.cern.ch/record/12365
tree1 = uproot.open(
"/home/jpivarski/Downloads/Run2012B_DoubleMuParked.root:Events",
array_cache=None,
handler=SOURCE,
)
# https://opendata.cern.ch/record/12366
tree2 = uproot.open(
"/home/jpivarski/Downloads/Run2012C_DoubleMuParked.root:Events",
array_cache=None,
handler=SOURCE,
)
task_descriptions = queue.Queue()
for tree in [tree1, tree2]:
for branch in tree.branches:
for basketid in range(branch.num_baskets):
task_descriptions.put((branch,) + branch.basket_entry_start_stop(basketid))
for _ in range(100):
task_descriptions.put(None)
threads = []
for which in range(NUM_THREADS):
threads.append(threading.Thread(target=in_thread, args=(which, task_descriptions)))
start_timer = time.perf_counter()
for thread in threads:
thread.start()
for thread in threads:
thread.join()
stop_timer = time.perf_counter()
print(NUM_THREADS, type(tree1.file.source).__name__, stop_timer - start_timer)