Belle II Software  release-05-01-25
test_unpacker_storearrays.py
1 # coding: utf-8
2 
3 import basf2
4 import b2test_utils
5 from svd import add_svd_unpacker, add_svd_reconstruction
6 
7 # ====================================================================
8 # Here we test the following behaviour of SVDUnpacker:
9 # 1. In case there is a pre-existing non-empty StoreArray of
10 # SVDShaperDigits, the unpacker throws B2FATAL unless the
11 # silentAppend parameter of the module is set.
12 # RATIONALE: This situation leads to unsorted digit arrays, and
13 # it can occur by error easily (by forgetting to exclude digits from
14 # HLT processing, for example). Unless a digit sorter is used, it
15 # will break clustering. Therefore, turning of a module parameter is
16 # required to make sure the user knows what he/she is doing.
17 # 2. In case there are no RawSVDs on input, the unpacker silently does
18 # nothing, only registers the output arrays.
19 # RATIONALE: This is meant to simplify processing, so that it be
20 # not necessary to customize processing scripts for each detector
21 # configuration. SVD reconstruction chain should silently (or with
22 # a single warning) withstand an absence of SVD data.
23 # ====================================================================
24 test_successful = True
25 test_message = ['successful', 'FAILED']
26 # ---------------------------------------------------------------------
27 
28 if __name__ == "__main__":
29 
31 
32  basf2.B2INFO('Test 1. \nBehaviour with residual digits\n')
33 
34  basf2.B2INFO('1/5 \nSet up: Using ParticleGun and SVDPacker, we generate\n' +
35  'a file with RawSVDs and residual digits.')
36 
37  create_input = basf2.create_path()
38  create_input.add_module('EventInfoSetter', expList=[0], runList=[0], evtNumList=[1])
39  create_input.add_module('Gearbox')
40  create_input.add_module('Geometry', components=['MagneticField', 'SVD'])
41  create_input.add_module('ParticleGun')
42  create_input.add_module('FullSim')
43 
44  create_input.add_module('SVDDigitizer')
45  create_input.add_module('SVDPacker')
46  create_input.add_module('RootOutput', outputFileName='rawPlusDigits.root')
48  result = b2test_utils.safe_process(create_input)
49 
50  test_successful = test_successful and (result == 0)
51  basf2.B2INFO('Generation {0}.\n'.format(test_message[result]))
52 
53  basf2.B2INFO('2/5\nRead shaper digits using default settings of SVDUnpacker.' +
54  '\nWe should see FATAL with message for SVDShaperDigits.')
55 
56  read_shapers_default = basf2.create_path()
57  read_shapers_default.add_module('RootInput', inputFileName='rawPlusDigits.root')
58  read_shapers_default.add_module('Gearbox')
59  read_shapers_default.add_module('Geometry', components=['MagneticField', 'SVD'])
60  read_shapers_default.add_module('SVDUnpacker')
61  add_svd_reconstruction(read_shapers_default)
62 
64  result = b2test_utils.safe_process(read_shapers_default)
65 
66  test_successful = test_successful and (result == 1)
67  basf2.B2INFO('Test {0}.\n'.format(test_message[1 - result]))
68 
69  basf2.B2INFO('3/5\nRead the safe way, excluding branches.\nWe should see no errors.')
70 
71  read_safe_way = basf2.create_path()
72  read_safe_way.add_module('RootInput',
73  inputFileName='rawPlusDigits.root',
74  branchNames=['EventMetaData', 'RawSVDs'])
75  read_safe_way.add_module('Gearbox')
76  read_safe_way.add_module('Geometry', components=['MagneticField', 'SVD'])
77  read_safe_way.add_module('SVDUnpacker')
78  add_svd_reconstruction(read_safe_way)
79 
81  result = b2test_utils.safe_process(read_safe_way)
82 
83  test_successful = test_successful and (result == 0)
84  basf2.B2INFO('Test {0}.\n'.format(test_message[result]))
85 
86  basf2.B2INFO('4/5\nRead with the Unpacker silentlyAppend switch on.\n' +
87  'We also include the SVDShaperDigitSorter.\n' +
88  'We should see no errors.')
89 
90  read_append_sort = basf2.create_path()
91  read_append_sort.add_module('RootInput',
92  inputFileName='rawPlusDigits.root',
93  branchNames=['EventMetaData', 'RawSVDs', 'SVDShaperDigits'])
94  read_append_sort.add_module('Gearbox')
95  read_append_sort.add_module('Geometry', components=['MagneticField', 'SVD'])
96  read_append_sort.add_module('SVDUnpacker', silentlyAppend=True)
97  read_append_sort.add_module('SVDShaperDigitSorter')
98  add_svd_reconstruction(read_append_sort)
99 
101  result = b2test_utils.safe_process(read_append_sort)
102 
103  test_successful = test_successful and (result == 0)
104  basf2.B2INFO('Test {0}.\n'.format(test_message[result]))
105 
106  basf2.B2INFO('5/5\nRead with the Unpacker silentAppend switch on.\n' +
107  'We don\'t include the SVDShaperDigitSorter.\n' +
108  'THERE WILL BE NO ERRORS, but digits and clusters may be duplicated!')
109 
110  read_append_nosort = basf2.create_path()
111  read_append_nosort.add_module('RootInput',
112  inputFileName='rawPlusDigits.root',
113  branchNames=['EventMetaData', 'RawSVDs', 'SVDShaperDigits'])
114  read_append_nosort.add_module('Gearbox')
115  read_append_nosort.add_module('Geometry', components=['MagneticField', 'SVD'])
116  read_append_nosort.add_module('SVDUnpacker', silentlyAppend=True)
117  add_svd_reconstruction(read_append_nosort)
118 
120  result = b2test_utils.safe_process(read_append_nosort)
121 
122  test_successful = test_successful and (result == 0)
123  basf2.B2INFO('Test {0}.\n'.format(test_message[result]))
124 
125  basf2.B2INFO('6 tasks of Test 1 completed\n\n')
126 
127  basf2.B2INFO('Test 2\nBehaviour when data absent\n')
128 
129  basf2.B2INFO('1/2\nRun unpacking and reconstruction with data.' +
130  '\nAll settings are standard.' +
131  '\nWe should see no errors. ')
132 
133  unpack_with_data = basf2.create_path()
134  unpack_with_data.add_module(
135  'RootInput',
136  inputFileName='rawPlusDigits.root',
137  excludeBranchNames=['SVDShaperDigits'])
138  unpack_with_data.add_module('Gearbox')
139  unpack_with_data.add_module('Geometry', components=['MagneticField', 'SVD'])
140  add_svd_unpacker(unpack_with_data)
141  add_svd_reconstruction(unpack_with_data)
142 
144  result = b2test_utils.safe_process(unpack_with_data)
145 
146  test_successful = test_successful and (result == 0)
147  basf2.B2INFO('Test {0}.\n'.format(test_message[result]))
148 
149  basf2.B2INFO('2/2\nRun unpacking and reconstruction without data.' +
150  '\nAll settings are standard.' +
151  '\nWe should see no errors. ')
152 
153  unpack_without_data = basf2.create_path()
154  unpack_without_data.add_module('EventInfoSetter', expList=[0], runList=[0], evtNumList=[1])
155  unpack_without_data.add_module('Gearbox')
156  unpack_without_data.add_module('Geometry', components=['MagneticField', 'SVD'])
157  add_svd_unpacker(unpack_without_data)
158  add_svd_reconstruction(unpack_without_data)
159 
161  result = b2test_utils.safe_process(unpack_without_data)
162 
163  test_successful = test_successful and (result == 0)
164  basf2.B2INFO('Test {0}.\n'.format(test_message[result]))
165 
166  basf2.B2INFO('2 tasks of Test 2 completed\n')
167 
168  basf2.B2INFO('Summary result:\nTests {0}.\n'.format(
169  test_message[0 if test_successful else 1]))
b2test_utils.show_only_errors
def show_only_errors()
Definition: __init__.py:87
b2test_utils.clean_working_directory
def clean_working_directory()
Definition: __init__.py:176
b2test_utils.safe_process
def safe_process(*args, **kwargs)
Definition: __init__.py:224