DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
opmonlib.info_file_collator Namespace Reference

Functions

dict collate_info_files (list json_files, Console console=None, click.File output_file=None)
 

Function Documentation

◆ collate_info_files()

dict opmonlib.info_file_collator.collate_info_files ( list json_files,
Console console = None,
click.File output_file = None )
Collate the json information into an output file.

Definition at line 12 of file info_file_collator.py.

14) -> dict:
15 """Collate the json information into an output file."""
16 if console is not None and output_file is not None:
17 console.log(
18 f"Reading specified JSON files and outputting collated value traces to {output_file.name}"
19 )
20
21 jsons = []
22 jd = json.JSONDecoder()
23 for jf in json_files:
24 if console is not None:
25 console.log(f"Reading info JSON file {jf.name}")
26 # 26-Nov-2025, KAB: it seems that the data type of the input "json_files" is different
27 # when this function is called from the info_file_collator script in this repo compared
28 # with when it is called with the list of opmon files generated in an integtest (from
29 # integrationtest/opmon_metric_checks.py). The following "if/else" block takes this
30 # difference into account.
31 if "pathlib.PosixPath" in str(type(jf)):
32 text = jf.read_text()
33 else:
34 text = jf.read()
35 idx = 0
36 while idx < len(text):
37 res = jd.raw_decode(text, idx)
38 jsons.append(res[0])
39 idx = res[1]
40 while idx < len(text) and text[idx] != '{':
41 idx += 1
42 data = {}
43
44 for jsonobj in jsons:
45 session = jsonobj["origin"]["session"]
46 application = jsonobj["origin"]["application"]
47
48 if session not in data:
49 data[session] = {}
50
51 if application not in data[session]:
52 data[session][application] = {}
53
54 objref = data[session][application]
55 if "substructure" in jsonobj["origin"]:
56 for sub in jsonobj["origin"]["substructure"]:
57 if sub not in objref:
58 objref[sub] = {}
59 objref = objref[sub]
60
61 measurement = (
62 jsonobj["measurement"].replace("dunedaq.", "").replace("opmon.", "")
63 )
64 if measurement not in objref:
65 objref[measurement] = {}
66 objref = objref[measurement]
67
68 custom_origin = ""
69 if "custom_origin" in jsonobj:
70 first = True
71 for k, v in jsonobj["custom_origin"].items():
72 if not first:
73 custom_origin += "."
74 custom_origin += f"{k}:{v}"
75 first = False
76
77 if custom_origin != "":
78 if custom_origin not in objref:
79 objref[custom_origin] = {}
80 objref = objref[custom_origin]
81
82 for datapoint in jsonobj["data"]:
83 if datapoint not in objref:
84 objref[datapoint] = {}
85
86 for value in jsonobj["data"][datapoint]:
87 objref[datapoint][jsonobj["time"]] = jsonobj["data"][datapoint][value]
88
89 if output_file is not None:
90 json.dump(data, output_file, indent=4, sort_keys=True)
91 if console is not None:
92 console.log("Operation complete")
93 return data