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