Belle II Software development
run_roitest.py
1#! /usr/bin/env python
2
3
10
11import os
12import sys
13import signal
14import subprocess
15
16global inputrb
17global outputrb
18
19global procbasf2
20global procrb2mrb
21global procmrb2rb
22
23global ncol
24
25global inrblist
26global outrblist
27
28# Signal Handler
29
30
31def cleanup(num, frame):
32 os.kill(procrb2mrb.pid, signal.SIGINT)
33 os.kill(procmrb2rb.pid, signal.SIGINT)
34 for i in range(0, ncol):
35 os.kill(procbasf2[i].pid, signal.SIGKILL)
36 subprocess.call(["removerb", inrblist[i]])
37 subprocess.call(["removerb", outrblist[i]])
38 exit()
39
40# main
41
42
43# Signal Handler
44
45signal.signal(signal.SIGINT, cleanup)
46signal.signal(signal.SIGTERM, cleanup)
47
48
49# Obtain input/output RingBuffer names
50argvs = sys.argv
51argc = len(argvs)
52
53inputrb = argvs[1]
54outputrb = argvs[2]
55
56# Number of collector basf2 processes
57ncol = 3
58
59# Collector script
60# col_script = "EvtGenSimRec.py"
61# col_script = "collector.py"
62# col_script = "fastcollector.py"
63col_script = "roitest.py"
64
65inrblist = []
66outrblist = []
67roiqlist = []
68
69for i in range(0, ncol):
70 inrblist.append(inputrb + str(i + 1))
71 outrblist.append(outputrb + str(i + 1))
72 roiqlist.append('/roi' + str(i))
73
74print(inrblist)
75print(outrblist)
76
77for x in inrblist:
78 subprocess.call("createrb " + x, shell='True')
79for x in outrblist:
80 subprocess.call("createrb " + x, shell='True')
81
82# Run rb2mrb
83cmdrb2mrb = "rb2mrb " + inputrb + " "
84cmdmrb2rb = "mrb2rb "
85for i in range(0, ncol):
86 cmdrb2mrb += (inrblist[i] + " ")
87 cmdmrb2rb += (outrblist[i] + " ")
88cmdmrb2rb += outputrb
89
90# Run rb2mrb
91print(cmdrb2mrb)
92procrb2mrb = subprocess.Popen(cmdrb2mrb, shell='True')
93# os.system ("rb2mrb " + inputrb + " " + inrblist[0] + " &" )
94
95# Run mrb2rb
96print(cmdmrb2rb)
97procmrb2rb = subprocess.Popen(cmdmrb2rb, shell='True')
98# os.system ("mrb2rb " + outrblist[0] + " " + outputrb + " &" )
99
100procbasf2 = []
101# run basf2
102for i in range(0, ncol):
103 basf2cmd = "basf2 --no-stats " + col_script + " " + inrblist[i] + " " + outrblist[i] + " " + roiqlist[i]
104 print(basf2cmd)
105 procbasf2.append(subprocess.Popen(basf2cmd, shell='True'))
106
107# Sleep
108while True:
109 signal.pause()