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

Functions

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

Function Documentation

◆ collate_info_files()

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

Definition at line 8 of file info_file_collator.py.

10) -> None:
11 """Collate the json information into an output file."""
12 console.log(
13 "Reading specified JSON files and outputting collated value traces to %s",
14 output_file.name,
15 )
16
17 jsons = []
18 jd = json.JSONDecoder()
19 for jf in json_files:
20 console.log(f"Reading info JSON file {jf.name}")
21 text = jf.read()
22 idx = 0
23 while idx < len(text):
24 res = jd.raw_decode(text, idx)
25 jsons.append(res[0])
26 idx = res[1] + 2
27
28 data = {}
29
30 for jsonobj in jsons:
31 session = jsonobj["origin"]["session"]
32 application = jsonobj["origin"]["application"]
33
34 if session not in data:
35 data[session] = {}
36
37 if application not in data[session]:
38 data[session][application] = {}
39
40 objref = data[session][application]
41 if "substructure" in jsonobj["origin"]:
42 for sub in jsonobj["origin"]["substructure"]:
43 if sub not in objref:
44 objref[sub] = {}
45 objref = objref[sub]
46
47 measurement = (
48 jsonobj["measurement"].replace("dunedaq.", "").replace("opmon.", "")
49 )
50 if measurement not in objref:
51 objref[measurement] = {}
52 objref = objref[measurement]
53
54 custom_origin = ""
55 if "custom_origin" in jsonobj:
56 first = True
57 for k, v in jsonobj["custom_origin"].items():
58 if not first:
59 custom_origin += "."
60 custom_origin += f"{k}:{v}"
61 first = False
62
63 if custom_origin != "":
64 if custom_origin not in objref:
65 objref[custom_origin] = {}
66 objref = objref[custom_origin]
67
68 for datapoint in jsonobj["data"]:
69 if datapoint not in objref:
70 objref[datapoint] = {}
71
72 for value in jsonobj["data"][datapoint]:
73 objref[datapoint][jsonobj["time"]] = jsonobj["data"][datapoint][value]
74
75 json.dump(data, output_file, indent=4, sort_keys=True)
76 console.log("Operation complete")
77 return