5 rundb - Helper classes for retrieving information from the RunDB
6 ----------------------------------------------------------------
8 This modules contains classes useful to deal with the RunDB:
10 * `RunDB`, a simple API class to just get run information from the RunDB
19 Simple API class to just get run information from the RunDB.
22 apikey (str): RunDB API key (see `here <https://questions.belle2.org/question/9847/obtaining-api-key-for-rundb/>`_
24 username (str): DESY username
28 URL =
"https://rundb.belle2.org"
30 def __init__(self, apikey=None, username=None):
31 """Create an object and setup authentication."""
36 username = getpass.getuser()
38 self.
_session.auth = (username, getpass.getpass(f
"DESY password ({username}): "))
41 self.
_session.headers.update({
'Authorization': f
'Bearer {apikey}'})
43 self.
_session.headers.update({
'Content-Type':
'application/json'})
46 """Deal with API pagination of an initial request to the API.
48 It will return all the objects from all pages lazily requesting new pages
49 as objects are consumed. Will work for all list requests to the server.
53 request.raise_for_status()
55 result = request.json()
58 yield from result[
'results']
60 if result[
'next']
is None:
64 request = self.
_session.get(result[
'next'])
67 """Return the run information from the run registry.
69 All arguments are forwarded to the run registry ``/run/`` method
70 documented at the following `link <https://rundb.belle2.org/rest/v1/swagger/>`_.
71 Please check there for up to date documentation, at the time of
72 this writing the supported arguments are:
74 * min_experiment (int)
76 * max_experiment (int)
78 * min_date (iso8601 date string, e.g. 2020-05-06)
79 * max_date (iso8601 date string, e.g. 2020-05-06)
80 * all_detectors_running (bool)
81 * expand (bool): If true return full run objects, not just a summary
82 links to the run objects
84 If ``expand=False`` you can request the full objects for each run by calling
85 `get_details` with the returned run summary object as argument.
86 ``expand=False`` is much faster if no further details are needed but
87 getting the details in a separate step for many many runs will be slow
88 so depending on how many runs are selected one or the other may be
91 req = self.
_session.get(f
'{self.URL}/rest/v1/runs/', params=search_params)
96 Return details for a run summary object returned from `get_run_info`
97 if ``expand`` was not set to True
100 run_summary: a run summary object returned from `get_run_info`
103 req = self.
_session.get(run_summary[
'url'])
105 req.raise_for_status()