ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
DQUtils
tests
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
5
import
gc
6
7
from
collections
import
namedtuple
8
9
from
DQUtils.db
import
Databases, fetch_iovs
10
from
DQUtils.quick_retrieve
import
browse_coracool
11
12
from
time
import
time
13
14
import
os
15
os.environ[
'CLING_STANDARD_PCH'
] =
'none'
#See bug ROOT-10789
16
from
PyCool
import
cool
17
18
folder_path =
"/SCT/DAQ/Configuration/Module"
19
20
database = Databases.get_instance(
"COOLONL_SCT/COMP200"
)
21
folder = database.getFolder(folder_path)
22
since, until = 1221973544491128285, 1221995264779751560
23
24
25
def
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
34
def
test_coracool
():
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
60
def
test_refcounting
():
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
119
if
__name__ ==
"__main__"
:
120
121
test_coracool
()
122
test_refcounting
()
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
set
STL class.
browse_coracool
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)
Definition
pythonic_coracool.cxx:189
test_coracool
Definition
test_coracool.py:1
test_coracool.fetch_lb_timestamps
fetch_lb_timestamps(since, until)
Definition
test_coracool.py:25
test_coracool.test_refcounting
test_refcounting()
Definition
test_coracool.py:60
test_coracool.test_coracool
test_coracool()
Definition
test_coracool.py:34
type
Generated on
for ATLAS Offline Software by
1.17.0