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