Belle II Software  release-08-01-10
run_collector.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 
68 for i in range(0, ncol):
69  inrblist.append(inputrb + str(i + 1))
70  outrblist.append(outputrb + str(i + 1))
71 
72 print(inrblist)
73 print(outrblist)
74 
75 for x in inrblist:
76  subprocess.call("createrb " + x, shell='True')
77 for x in outrblist:
78  subprocess.call("createrb " + x, shell='True')
79 
80 # Run rb2mrb
81 cmdrb2mrb = "rb2mrb " + inputrb + " "
82 cmdmrb2rb = "mrb2rb "
83 for i in range(0, ncol):
84  cmdrb2mrb += (inrblist[i] + " ")
85  cmdmrb2rb += (outrblist[i] + " ")
86 cmdmrb2rb += outputrb
87 
88 # Run rb2mrb
89 print(cmdrb2mrb)
90 procrb2mrb = subprocess.Popen(cmdrb2mrb, shell='True')
91 # os.system ("rb2mrb " + inputrb + " " + inrblist[0] + " &" )
92 
93 # Run mrb2rb
94 print(cmdmrb2rb)
95 procmrb2rb = subprocess.Popen(cmdmrb2rb, shell='True')
96 # os.system ("mrb2rb " + outrblist[0] + " " + outputrb + " &" )
97 
98 procbasf2 = []
99 # run basf2
100 for 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
106 while True:
107  signal.pause()