Belle II Software  release-06-00-14
test_skims.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """Test skims by running them all as a single combined steering file."""
13 
14 from glob import glob
15 
16 from b2test_utils import clean_working_directory, require_file
17 import basf2 as b2
18 import modularAnalysis as ma
19 from skim import CombinedSkim
20 from skim.WGs.fei import BaseFEISkim
21 from skim.registry import Registry
22 
23 # NOTE: Another way this test could have been written is to run the standalone steering
24 # file for every skim:
25 #
26 # for SkimName in Registry.names:
27 # b2.b2test_utils.check_error_free(
28 # "b2skim-run", f"Skim {SkimName}", "skim", toolopts=[SkimName, "-n", "10"]
29 # )
30 #
31 # I think what is written below is preferable, as it makes the overall running time of
32 # this test smaller.
33 
34 
35 def is_fei_skim(skim):
36  return isinstance(skim, BaseFEISkim)
37 
38 
39 def is_combined_or_fei_skim(skim):
40  return isinstance(skim, CombinedSkim) or is_fei_skim(skim)
41 
42 
43 def main():
44  path = b2.Path()
45  mdst_files = glob(f'{b2.find_file("mdst/tests")}/mdst-v*.root')
46  mdst_files.sort(reverse=True)
47  ma.inputMdstList("default", require_file(mdst_files[0]), path=path)
48 
49  analysisGlobaltag = ma.getAnalysisGlobaltag()
50  SkimObjects = [Registry.get_skim_function(skim)(analysisGlobaltag=analysisGlobaltag) for skim in Registry.names]
51  skims = CombinedSkim(*[skim for skim in SkimObjects if not is_combined_or_fei_skim(skim)])
52  skims(path)
53  feiSkims = CombinedSkim(*[skim for skim in SkimObjects if is_fei_skim(skim)])
54  feiSkims(path)
55 
56  b2.process(path, max_event=10)
57 
58 
59 if __name__ == "__main__":
60  with clean_working_directory():
61  main()
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:75