Belle II Software  release-08-01-10
trggdlSummary.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # -----------------------------------------------------------------------------------
13 #
14 # Example of GDL trigger Summary Module
15 #
16 # usage : %> basf2 trggdlSummary.py [input sroot file name]
17 #
18 # -----------------------------------------------------------------------------------
19 
20 import basf2 as b2
21 
22 import sys # get argv
23 import re
24 import os.path
25 argvs = sys.argv # get arg
26 argc = len(argvs) # of arg
27 if argc != 2:
28  sys.exit("trggdlSummary.py> # of arg is strange. Exit.")
29 if argc == 2:
30  f_in_root = argvs[1]
31 
32 
33 b2.set_log_level(b2.LogLevel.INFO)
34 
35 main = b2.create_path()
36 
37 # input
38 if f_in_root[-6:] == ".sroot":
39  rootfiletype = "sroot"
40  input = b2.register_module('SeqRootInput')
41  matchobj = re.search("([^\\/]+)\\.sroot", f_in_root)
42  basename = re.sub('\\.sroot$', '', matchobj.group())
43 if f_in_root[-5:] == ".root":
44  rootfiletype = "root"
45  input = b2.register_module('RootInput')
46  matchobj = re.search("([^\\/]+)\\.root", f_in_root)
47  basename = re.sub('\\.root$', '', matchobj.group())
48 
49 input.param('inputFileName', f_in_root)
50 main.add_module(input)
51 
52 
53 # output
54 output = b2.register_module('RootOutput')
55 output.param("outputFileName", "trgsum/trgsum.%s.root" % basename)
56 if not os.path.isdir('trgsum'):
57  os.mkdir('trgsum')
58 
59 # Unpacker
60 trggdlUnpacker = b2.register_module("TRGGDLUnpacker")
61 main.add_module(trggdlUnpacker)
62 
63 #
64 trggdlsummary = b2.register_module('TRGGDLSummary')
65 main.add_module(trggdlsummary)
66 
67 progress = b2.register_module('Progress')
68 main.add_module(progress)
69 
70 main.add_module(output, branchNames=["TRGSummary"])
71 
72 b2.process(main)
73 
74 print(b2.statistics)