9import b2test_utils
as b2u
13def filter_input_output(input_file_name, output_file_name, include_branches=None, exclude_branches=None):
15 b2u.configure_logging_for_tests()
16 b2.set_random_seed(
'Forza Livorno!!!')
17 b2.B2INFO(
'We are testing the following configuration:',
18 include_branches=include_branches,
19 exclude_branches=exclude_branches)
20 child_path = b2.Path()
21 child_path.add_module(
'RootInput',
22 inputFileName=input_file_name,
23 collectStatistics=
True)
24 if include_branches
is not None:
25 b2.set_module_parameters(child_path,
27 branchNames=include_branches)
28 if exclude_branches
is not None:
29 b2.set_module_parameters(child_path,
31 excludeBranchNames=exclude_branches)
32 child_path.add_module(
'RootOutput',
33 outputFileName=output_file_name)
34 b2.process(child_path)
37def check_file_content(file_name, input_branches):
39 f = ROOT.TFile.Open(file_name,
'READ')
41 b2.B2FATAL(f
'Cannot open the input file {file_name}.')
43 file_branches = [branch.GetName()
for branch
in tree.GetListOfBranches()]
45 return set(input_branches) <= set(file_branches)
48if __name__ ==
'__main__':
50 with b2u.clean_working_directory():
52 input_file_name = b2.find_file(
'framework/tests/mdst_with_muid.root')
53 assert (0 == b2u.run_in_subprocess(input_file_name,
'mdst_all_branches.root',
None,
None,
54 target=filter_input_output))
55 all_branches = [
'Tracks',
'ECLClusters',
'TracksToECLClusters',
'Muids',
'TracksToMuids']
56 assert (1 == check_file_content(input_file_name, all_branches))
58 file_to_check =
'mdst_without_muid.root'
59 assert (0 == b2u.run_in_subprocess(input_file_name, file_to_check,
None, [
'Muids'],
60 target=filter_input_output))
61 assert (0 == check_file_content(file_to_check, [
'Muids']))
62 assert (0 == check_file_content(file_to_check, [
'TracksToMuids']))
63 assert (1 == check_file_content(file_to_check, [
'Tracks',
'ECLClusters']))
65 file_to_check =
'mdst_only_muid.root'
66 assert (0 == b2u.run_in_subprocess(input_file_name, file_to_check, [
'Muids'],
None,
67 target=filter_input_output))
69 assert (0 == check_file_content(file_to_check, [
'Muids']))
71 assert (0 == b2u.run_in_subprocess(input_file_name, file_to_check, [
'Tracks',
'ECLClusters'],
None,
72 target=filter_input_output))
73 assert (0 == check_file_content(file_to_check, [
'Muids',
'TracksToMuids']))
74 assert (1 == check_file_content(file_to_check, [
'Tracks',
'ECLClusters',
'TracksToECLClusters']))