ATLAS Offline Software
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 
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 
119 if __name__ == "__main__":
120 
121  test_coracool()
python.db.fetch_iovs
def fetch_iovs(folder_name, since=None, until=None, channels=None, tag="", what="all", max_records=-1, with_channel=True, loud=False, database=None, convert_time=False, named_channels=False, selection=None, runs=None, with_time=False, unicode_strings=False)
Definition: DQUtils/python/db.py:67
test_coracool.test_coracool
def test_coracool()
Definition: test_coracool.py:34
test_coracool.test_refcounting
def test_refcounting()
Definition: test_coracool.py:60
test_coracool.fetch_lb_timestamps
def fetch_lb_timestamps(since, until)
Definition: test_coracool.py:25
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
python.quick_retrieve.browse_coracool
browse_coracool
Definition: quick_retrieve.py:17
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
test_coracool
Definition: test_coracool.py:1
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28