Belle II Software development
run_collector.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"
61col_script = "collector.py"
62# col_script = "fastcollector.py"
63# col_script = "roitest.py"
64
65inrblist = []
66outrblist = []
67
68for i in range(0, ncol):
69 inrblist.append(inputrb + str(i + 1))
70 outrblist.append(outputrb + str(i + 1))
71
72print(inrblist)
73print(outrblist)
74
75for x in inrblist:
76 subprocess.call("createrb " + x, shell='True')
77for x in outrblist:
78 subprocess.call("createrb " + x, shell='True')
79
80# Run rb2mrb
81cmdrb2mrb = "rb2mrb " + inputrb + " "
82cmdmrb2rb = "mrb2rb "
83for i in range(0, ncol):
84 cmdrb2mrb += (inrblist[i] + " ")
85 cmdmrb2rb += (outrblist[i] + " ")
86cmdmrb2rb += outputrb
87
88# Run rb2mrb
89print(cmdrb2mrb)
90procrb2mrb = subprocess.Popen(cmdrb2mrb, shell='True')
91# os.system ("rb2mrb " + inputrb + " " + inrblist[0] + " &" )
92
93# Run mrb2rb
94print(cmdmrb2rb)
95procmrb2rb = subprocess.Popen(cmdmrb2rb, shell='True')
96# os.system ("mrb2rb " + outrblist[0] + " " + outputrb + " &" )
97
98procbasf2 = []
99# run basf2
100for i in range(0, ncol):
101 basf2cmd = "basf2 --no-stats " + col_script + " " + inrblist[i] + " " + outrblist[i]
102 print(basf2cmd)
103 procbasf2.append(subprocess.Popen(basf2cmd, shell='True'))
104
105# Sleep
106while True:
107 signal.pause()