Belle II Software development
copy_for_rebasing.py
1import os
2import glob
3import shutil
4import argparse
5
6import fei
7
8
9def copy_files(input_path, output_path, training_data=False):
10 """
11 Copy specific files from the input training collection to a new collection used for FEI rebasing
12
13 Args:
14 input_path (str): Path to the source directory containing the files to copy.
15 output_path (str): Path to the destination directory where selected files will be copied.
16 training_data (bool): If True, copy training data files.
17 """
18 if os.path.exists(output_path):
19 shutil.rmtree(output_path)
20 os.makedirs(output_path)
21 os.makedirs(os.path.join(output_path, 'collection'))
22
23 # copy localdb
24 shutil.copytree(
25 os.path.join(input_path, 'collection', 'localdb'),
26 os.path.join(output_path, 'collection', 'localdb'))
27
28 # copy Summary.pickle.backup_previous
29 shutil.copy(
30 os.path.join(input_path, 'collection', 'Summary.pickle'),
31 os.path.join(output_path, 'collection', 'Summary.pickle.backup_previous'))
32
33 # copy non fake .xml and logs
34 xml_files = glob.glob(os.path.join(input_path, 'collection', '*.xml'))
35 for xml_file in xml_files:
36 if not fei.core.Teacher.check_if_weightfile_is_fake(xml_file):
37 shutil.copy(xml_file, os.path.join(output_path, 'collection'))
38 shutil.copy(xml_file.replace('.xml', '.log'), os.path.join(output_path, 'collection'))
39
40 # copy Monitor_TrainingData.root and Monitor_ModuleStatistics.root
41 shutil.copy(
42 os.path.join(input_path, 'collection', 'Monitor_TrainingData.root'),
43 os.path.join(output_path, 'collection', 'Monitor_TrainingData.root'))
44 shutil.copy(
45 os.path.join(input_path, 'collection', 'Monitor_ModuleStatistics.root'),
46 os.path.join(output_path, 'collection', 'Monitor_ModuleStatistics.root'))
47
48 if training_data:
49 shutil.copy(
50 os.path.join(input_path, 'collection', 'training_input.root'),
51 os.path.join(output_path, 'collection', 'training_input.root'))
52 shutil.copy(
53 os.path.join(input_path, 'collection', 'validation_input.root'),
54 os.path.join(output_path, 'collection', 'validation_input.root'))
55
56
57# ================================================================
58if __name__ == "__main__":
59 # python3 copy_for_rebasing.py -i B_reduced_train -o B_reduced_rebased -t
60 parser = argparse.ArgumentParser(description='Copy files for re-basing FEI examples.')
61 parser.add_argument('-i', '--input_path', type=str, required=True,
62 help='Path to the source directory containing the files to copy.')
63 parser.add_argument('-o', '--output_path', type=str, required=True,
64 help='Path to the destination directory where selected files will be copied.')
65 parser.add_argument('-t', '--training_data', action='store_true', help='Copy training data files.')
66
67 args = parser.parse_args()
68 copy_files(args.input_path, args.output_path, args.training_data)