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