Belle II Software  release-08-01-10
run_roitest.py
1 #! /usr/bin/env python
2 
3 
10 
11 import os
12 import sys
13 import signal
14 import subprocess
15 
16 global inputrb
17 global outputrb
18 
19 global procbasf2
20 global procrb2mrb
21 global procmrb2rb
22 
23 global ncol
24 
25 global inrblist
26 global outrblist
27 
28 # Signal Handler
29 
30 
31 def 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 
45 signal.signal(signal.SIGINT, cleanup)
46 signal.signal(signal.SIGTERM, cleanup)
47 
48 
49 # Obtain input/output RingBuffer names
50 argvs = sys.argv
51 argc = len(argvs)
52 
53 inputrb = argvs[1]
54 outputrb = argvs[2]
55 
56 # Number of collector basf2 processes
57 ncol = 3
58 
59 # Collector script
60 # col_script = "EvtGenSimRec.py"
61 # col_script = "collector.py"
62 # col_script = "fastcollector.py"
63 col_script = "roitest.py"
64 
65 inrblist = []
66 outrblist = []
67 roiqlist = []
68 
69 for 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 
74 print(inrblist)
75 print(outrblist)
76 
77 for x in inrblist:
78  subprocess.call("createrb " + x, shell='True')
79 for x in outrblist:
80  subprocess.call("createrb " + x, shell='True')
81 
82 # Run rb2mrb
83 cmdrb2mrb = "rb2mrb " + inputrb + " "
84 cmdmrb2rb = "mrb2rb "
85 for i in range(0, ncol):
86  cmdrb2mrb += (inrblist[i] + " ")
87  cmdmrb2rb += (outrblist[i] + " ")
88 cmdmrb2rb += outputrb
89 
90 # Run rb2mrb
91 print(cmdrb2mrb)
92 procrb2mrb = subprocess.Popen(cmdrb2mrb, shell='True')
93 # os.system ("rb2mrb " + inputrb + " " + inrblist[0] + " &" )
94 
95 # Run mrb2rb
96 print(cmdmrb2rb)
97 procmrb2rb = subprocess.Popen(cmdmrb2rb, shell='True')
98 # os.system ("mrb2rb " + outrblist[0] + " " + outputrb + " &" )
99 
100 procbasf2 = []
101 # run basf2
102 for 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
108 while True:
109  signal.pause()