12from basf2
import conditions
as b2conditions
13from basf2
import create_path, process
14from basf2
import B2FATAL, B2INFO, B2WARNING
18from caf.backends
import get_input_data
23 Runs the CAF collector in a general way by passing serialised basf2 paths, input file
24 locations,
and local databases
from previous calibrations.
32 with open(
"collector_config.json")
as config_file:
33 config = json.load(config_file)
39 b2conditions.override_globaltags()
41 for db_type, database
in config[
"database_chain"]:
42 if db_type ==
"local":
43 B2INFO(f
"Adding Local Database {database[0]} to head of chain of local databases.")
44 b2conditions.prepend_testing_payloads(database[0])
46 B2INFO(f
"Using Global Tag {database}.")
47 b2conditions.prepend_globaltag(database)
50 collector_path = create_path()
54 pre_collector_path_name =
"pre_collector.path"
55 pickle_paths = glob.glob(
"./*.path")
58 pickle_paths = filter(
lambda x: pre_collector_path_name
not in x, pickle_paths)
61 if os.path.exists(pre_collector_path_name):
62 collector_path.add_path(get_path_from_file(pre_collector_path_name))
64 B2INFO(
"Couldn't find any pickle files for pre-collector setup")
68 for pickle_path
in pickle_paths:
69 collector_path.add_path(get_path_from_file(pickle_path))
71 B2FATAL(
"Couldn't find any pickle files for collector path!")
74 input_data = get_input_data()
79 from caf.utils
import PathExtras
80 pe = PathExtras(collector_path)
82 root_input_mod = collector_path.modules()[pe.index(
"RootInput")]
83 root_input_mod.param(
"inputFileNames", input_data)
84 input_entry_sequences = get_entry_sequences(root_input_mod)
87 if len(input_entry_sequences) == 1
and len(input_data) > 1:
88 root_input_mod.param(
"entrySequences", len(input_data)*input_entry_sequences)
89 elif "SeqRootInput" in pe:
90 root_input_mod = collector_path.modules()[pe.index(
"SeqRootInput")]
91 root_input_mod.param(
"inputFileNames", input_data)
93 main.add_module(
"RootInput", inputFileNames=input_data)
95 if "HistoManager" not in pe:
96 main.add_module(
"HistoManager", histoFileName=
"CollectorOutput.root")
98 main.add_path(collector_path)
99 basf2.print_path(main)
101 print(basf2.statistics)
104def get_entry_sequences(root_input_module):
106 Finds the value of entrySequences (list) from the RootInput module.
108 for module_param_info
in root_input_module.available_params():
109 if module_param_info.name ==
"entrySequences":
110 entry_sequences = module_param_info.values
113 B2WARNING(
"entrySequences ModuleParamInfo couldn't be found! "
114 "Setting to empty list but this indicates that this script is out of date!")
116 return entry_sequences
119if __name__ ==
"__main__":