Belle II Software  release-05-01-25
RunTPC_daily_report.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 import os
4 import sys
5 import datetime
6 from basf2 import *
7 from subprocess import call
8 
9 d = datetime.datetime.today()
10 print((d.strftime('job start: %Y-%m-%d %H:%M:%S\n')))
11 
12 # 1/ mkdir output_directory
13 # 2/ basf2 ./RunTPC_daily_report.py yyyy mm dd TPCposition output_directory
14 
15 location = ""
16 if len(sys.argv) == 6:
17  # parse input
18  inputs = '/home/belle/igal/beast/data/NTP/TPC/' + \
19  str(sys.argv[1]) + "-" + str(sys.argv[2]) + "-" + str(sys.argv[3]) + "/tpc" + str(sys.argv[4]) + "*.root"
20  # parse output
21  outfile = str(sys.argv[5]) + "/DailyReportOfTPC" + str(sys.argv[4]) + "_" + \
22  str(sys.argv[1]) + str(sys.argv[2]) + str(sys.argv[3]) + ".root"
23  # date yyyymmdd
24  date = str(sys.argv[1]) + str(sys.argv[2]) + str(sys.argv[3])
25  # TPC position
26  TPCnb = str(sys.argv[4])
27 else:
28  print
29  print("Usage:")
30  print(" 1/ Create an output directory ")
31  print(" mkdir output_directory")
32  print(" 2/ basf2 ./RunTPC_daily_report.py yyyy mm dd TPCposition output_directory")
33  print("For example: ")
34  print(" basf2 ./RunTPC_daily_report.py 2016 05 30 3 output_directory")
35  print
36  quit()
37 
38 print(inputs)
39 print(outfile)
40 print(date)
41 print(TPCnb)
42 
43 # Register necessary modules
44 main = create_path()
45 
46 # Register RootInput
47 simpleinput = register_module('RootInput')
48 simpleinput.param('inputFileNames', inputs)
49 main.add_module(simpleinput)
50 
51 # Register HistoManager
52 histo = register_module("HistoManager") # Histogram Manager
53 histo.param('histoFileName', outfile)
54 main.add_module(histo)
55 
56 # Register Gearbox
57 gearbox = register_module('Gearbox')
58 gearbox.param('fileName', '/geometry/Beast2_phase1.xml')
59 main.add_module(gearbox)
60 
61 # Register MicrotpcDailyReport
62 daily = register_module('MicrotpcDailyReport')
63 daily.param('inputTPCNumber', int(TPCnb))
64 daily.param('inputReportDate', int(date))
65 main.add_module(daily)
66 
67 
68 process(main)
69 
70 print('Event Statistics:')
71 print(statistics)
72 
73 d = datetime.datetime.today()
74 print(d.strftime('job finish: %Y-%m-%d %H:%M:%S\n'))