Belle II Software development
prompt_utils.py
1
8
9
10def fix_mille_paths_for_algo(algo):
11 """
12 Add pre.algorithm to fix mille file paths
13
14 Attach a pre-algorithm which loops over collector files
15 and fixes the paths to mille binary files (in case they have
16 been moved since creation - otherwise the effect is null)
17
18 If previous pre_algorithm exists, it is run after the fix
19 is applied.
20
21 Parameters
22 ----------
23 algo : caf.framework.Algorithm
24 The algorithm to which to attach pre_algorithm
25 """
26
27 prev_prealgo = algo.pre_algorithm
28
29 def fixMillePaths(algorithm, iteration):
30 import ROOT
31 import os
32
33 print("Now fixing .mille binary paths in CollectorOutput.root files")
34
35 for path in algorithm.getInputFileNames():
36 file = ROOT.TFile(path, "UPDATE")
37 dirname = os.path.dirname(path)
38
39 runRange = file.Get("MillepedeCollector/RunRange")
40 runSet = [(-1, -1)] if runRange.getGranularity() == "all" else [(e, r) for e, r in runRange.getExpRunSet()]
41
42 for exp, run in runSet:
43 milleData = file.Get(f"MillepedeCollector/mille/mille_{exp}.{run}/mille_1")
44
45 fixed_milleFiles = [os.path.join(dirname, os.path.basename(str(milleFile))) for milleFile in milleData.getFiles()]
46
47 milleData.clear()
48 for f in fixed_milleFiles:
49 if os.path.isfile(f):
50 milleData.addFile(f)
51 print(f)
52 else:
53 print(dirname, ":")
54 print("Missing file: ", f)
55
56 file.cd(f"MillepedeCollector/mille/mille_{exp}.{run}/")
57 milleData.Write("", ROOT.TObject.kOverwrite)
58 file.Write()
59 file.Close()
60
61 # Run the previously set pre-algorithm if any
62 if prev_prealgo is not None:
63 prev_prealgo(algorithm, iteration)
64
65 algo.pre_algorithm = fixMillePaths