Belle II Software  release-08-01-10
trggdlDataTsim.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 # 0
36 # use_central_database("online")
37 # use_local_database("./localdb/database.txt")
38 # use_central_database("staging_online")
39 
40 # use_central_database("master_2019-09-26")
41 # use_central_database("data_reprocessing_prompt_bucket6")
42 # use_central_database("TRGGDL_201811")
43 # use_central_database("online")
44 # use_central_database("staging_online")
45 
46 # 1
47 b2.conditions.disable_globaltag_replay()
48 b2.conditions.prepend_testing_payloads('./localdb/database.txt')
49 
50 # 2
51 # b2.conditions.disable_globaltag_replay()
52 # b2.conditions.globaltags = ['data_reprocessing_prompt_rel4_patchb', 'online']
53 # b2.conditions.prepend_testing_payloads('./localdb/database.txt')
54 
55 main = b2.create_path()
56 
57 # input
58 if f_in_root[-6:] == ".sroot":
59  rootfiletype = "sroot"
60  input = b2.register_module('SeqRootInput')
61  matchobj = re.search("([^\\/]+)\\.sroot", f_in_root)
62  basename = re.sub('\\.sroot$', '', matchobj.group())
63 if f_in_root[-5:] == ".root":
64  rootfiletype = "root"
65  input = b2.register_module('RootInput')
66  matchobj = re.search("([^\\/]+)\\.root", f_in_root)
67  basename = re.sub('\\.root$', '', matchobj.group())
68 
69 input.param('inputFileName', f_in_root)
70 main.add_module(input)
71 
72 
73 # Unpacker
74 trggdlUnpacker = b2.register_module("TRGGDLUnpacker")
75 # trggdlUnpacker.param('print_dbmap', True)
76 main.add_module(trggdlUnpacker)
77 
78 #
79 trggdlsummary = b2.register_module('TRGGDLSummary')
80 main.add_module(trggdlsummary)
81 
82 datatsim = b2.register_module('TRGGDL')
83 datatsim.param('SimulationMode', 3)
84 datatsim.param('Belle2Phase', "Belle2Phase")
85 # datatsim.param('algFromDB', False)
86 # datatsim.param('algFilePath', "ftd_0023.alg")
87 main.add_module(datatsim)
88 
89 histo = b2.register_module('HistoManager')
90 histo.param("histoFileName", "trgsum/dsim.%s.root" % basename)
91 main.add_module(histo)
92 if not os.path.isdir('trgsum'):
93  os.mkdir('trgsum')
94 
95 progress = b2.register_module('Progress')
96 main.add_module(progress)
97 
98 # main.add_module(output, branchNames=["TRGSummary"])
99 
100 b2.process(main)
101 # process(main, max_event=200)
102 
103 print(b2.statistics)