ATLAS Offline Software
Loading...
Searching...
No Matches
test_coracool.py
Go to the documentation of this file.
1#! /usr/bin/env python
2
3# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4
5import gc
6
7from collections import namedtuple
8
9from DQUtils.db import Databases, fetch_iovs
10from DQUtils.quick_retrieve import browse_coracool
11
12from time import time
13
14import os
15os.environ['CLING_STANDARD_PCH'] = 'none' #See bug ROOT-10789
16from PyCool import cool
17
18folder_path = "/SCT/DAQ/Configuration/Module"
19
20database = Databases.get_instance("COOLONL_SCT/COMP200")
21folder = database.getFolder(folder_path)
22since, until = 1221973544491128285, 1221995264779751560
23
24
25def fetch_lb_timestamps(since, until):
26 """
27 Read the timestamps of all luminosity blocks between
28 the run-lumi IoV (since, until)
29 """
30 timestamps = fetch_iovs("COOLONL_TRIGGER/COMP200::/TRIGGER/LUMI/LBLB", since, until,
31 with_channel=False, what="all")
32 return timestamps[0].StartTime, timestamps[-1].EndTime, timestamps
33
35
36 if "<coracool>" not in folder.description():
37 print(f"{folder.fullPath()} is not a coracool folder")
38 return
39
40 variables = ["group", "id"]
41
42 record = namedtuple("coracool_record", "since until channel elements")
43 element = namedtuple("element", " ".join(variables))
44
45 start = time()
46
47 objects = browse_coracool(database, folder_path, since, until,
48 cool.ChannelSelection(), "", variables, record, element)
49
50 elapsed = time()-start
51 print("Took %.2f to browse_coracool" % elapsed)
52
53 print(len(objects))
54
55 bad = [x for x in objects if any(el.group == -1 for el in x.elements)]
56 print(len(bad))
57
58 return
59
61 record = namedtuple("coracool_record", "since until channel elements")
62 element = namedtuple("element", "group id")
63
64 from time import time
65 start = time()
66
67 # repr() can allocate a list object the first time it's called.
68 # (cf. Py_ReprEnter)
69 # Make sure that happens now, before we do the gc check.
70 repr([1])
71
72 objects = None
73
74 before_objects = set(id(x) for x in gc.get_objects())
75 gc.collect()
76
77 try: raise RuntimeError
78 except Exception: pass
79
80 print("Objects alive before call:", len(gc.get_objects()))
81
82 try:
83 objects = browse_coracool(database, folder_path, since, until,
84 cool.ChannelSelection(), "", ["group", "id"],
85 record, element)
86
87 except Exception as e:
88 print("Caught exception ", e)
89 del e
90
91 elapsed = time() - start
92 print("Took %.3f to browse folder" % elapsed)
93
94 assert objects is not None, 'Null return from browse_coracool'
95
96 print("Return type:", type(objects), type(objects[0]))
97 print("Result length =", len(objects))
98 print("Result index 0 length =", len(objects[0]))
99 print("Result index 0 =", objects[0])
100 del objects
101
102
103 print("Objects alive before cleanup:", len(gc.get_objects()))
104
105 gc.collect()
106
107 print("Objects alive after:", len(gc.get_objects()))
108
109 after_objects = gc.get_objects()
110
111 new_objects = set(id(x) for x in after_objects) - before_objects
112
113 # new_objects = filter(lambda x: id(x) in new_objects and x != before_objects, after_objects)
114 new_objects = [x for x in after_objects if id(x) in new_objects and x != before_objects and x != new_objects]
115
116 assert new_objects == [], 'Lingering objects after garbage collection'
117
118
119if __name__ == "__main__":
120
void print(char *figname, TCanvas *c1)
STL class.
PyObject * browse_coracool(IDatabasePtr cooldb, const string &folder, ValidityKey since, ValidityKey until, const ChannelSelection &cs=ChannelSelection::all(), const char *tag="", PyObject *to_fetch=NULL, PyObject *object_converter=NULL, PyObject *inner_object_converter=NULL, PyObject *iovkey_wrapper=NULL)
fetch_lb_timestamps(since, until)