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

Functions

 hash_function (obj)
 
 convert_to_dict (db, obj)
 
 jsonify_xml_data (oksfile, output)
 

Variables

 log = getLogger('daqconf.jsonify')
 

Function Documentation

◆ convert_to_dict()

jsonify.convert_to_dict ( db,
obj )

Definition at line 14 of file jsonify.py.

14def convert_to_dict(db, obj):
15 dal_dict = {
16 "__type": obj.className(),
17 "_id": {
18 "$oid": hash_function(obj), # Borrowing from MongoDB
19 }
20 }
21
22 for attribute_name, attribute_value in db.attributes(obj.className(), all=True).items():
23 dal_dict[attribute_name] = getattr(obj, attribute_name)
24
25 for relation_name, relation_value in db.relations(obj.className(), all=True).items():
26 relation_object = getattr(obj, relation_name, None)
27
28 if relation_object is None:
29 dal_dict[relation_name] = None
30
31 elif not relation_value.get('multivalue', False):
32 dal_dict[relation_name] = {
33 # "$ref": "run-registry"
34 '$id': hash_function(relation_object),
35 }
36
37 else:
38 dal_dict[relation_name] = [
39 {
40 "$id": hash_function(one_relation_object)
41 # "$ref": "run-registry"
42 }
43 for one_relation_object in relation_object
44 ]
45
46 return dict(sorted(dal_dict.items()))
47
48

◆ hash_function()

jsonify.hash_function ( obj)

Definition at line 9 of file jsonify.py.

9def hash_function(obj):
10 # I guess we could get ObjectId from MongoDB
11 return hash(f'{obj.id}@{obj.className()}')
12
13

◆ jsonify_xml_data()

jsonify.jsonify_xml_data ( oksfile,
output )

Definition at line 49 of file jsonify.py.

49def jsonify_xml_data(oksfile, output):
50
51 sys.setrecursionlimit(10000)
52
53 log.info(f"JSonifying database \'{oksfile}\' to \'{output}\'.")
54
55 log.debug("Reading database")
56 db = conffwk.Configuration("oksconflibs:" + oksfile)
57
58 dals = db.get_all_dals()
59 the_big_dict = {}
60
61 for dal_str in dals:
62 dal = dals[dal_str]
63 key_name = f"{dal.id}@{dal.className()}"
64 log.debug(f"Processing DAL {key_name}")
65 if key_name in the_big_dict:
66 log.error(f"Duplicate DAL id {key_name}")
67 continue
68
69 dal_dict = convert_to_dict(db, dal)
70 the_big_dict[key_name] = dal_dict
71
72 with open(output, 'w') as f:
73 json.dump(dict(sorted(the_big_dict.items())), f, indent=4)
74

Variable Documentation

◆ log

jsonify.log = getLogger('daqconf.jsonify')

Definition at line 6 of file jsonify.py.