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]
27 while idx < len(text) and text[idx] != '{':
28 idx += 1
29 data = {}
30
31 for jsonobj in jsons:
32 session = jsonobj["origin"]["session"]
33 application = jsonobj["origin"]["application"]
34
35 if session not in data:
36 data[session] = {}
37
38 if application not in data[session]:
39 data[session][application] = {}
40
41 objref = data[session][application]
42 if "substructure" in jsonobj["origin"]:
43 for sub in jsonobj["origin"]["substructure"]:
44 if sub not in objref:
45 objref[sub] = {}
46 objref = objref[sub]
47
48 measurement = (
49 jsonobj["measurement"].replace("dunedaq.", "").replace("opmon.", "")
50 )
51 if measurement not in objref:
52 objref[measurement] = {}
53 objref = objref[measurement]
54
55 custom_origin = ""
56 if "custom_origin" in jsonobj:
57 first = True
58 for k, v in jsonobj["custom_origin"].items():
59 if not first:
60 custom_origin += "."
61 custom_origin += f"{k}:{v}"
62 first = False
63
64 if custom_origin != "":
65 if custom_origin not in objref:
66 objref[custom_origin] = {}
67 objref = objref[custom_origin]
68
69 for datapoint in jsonobj["data"]:
70 if datapoint not in objref:
71 objref[datapoint] = {}
72
73 for value in jsonobj["data"][datapoint]:
74 objref[datapoint][jsonobj["time"]] = jsonobj["data"][datapoint][value]
75
76 json.dump(data, output_file, indent=4, sort_keys=True)
77 console.log("Operation complete")
78 return