ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
HLT
Trigger
TrigControl
TrigCommon
python
AthHLT.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
#
3
# Utilities used in athenaHLT.py
4
#
5
from
typing
import
Any
6
from
AthenaCommon.Logging
import
logging
7
from
pycrest.api.crest_api
import
CrestApi
8
log = logging.getLogger(
'athenaHLT'
)
9
10
from
functools
import
cache
11
import
os
12
import
sys
13
14
class
CondDB
:
15
_run2 = 236108
16
def
__init__
(self, run):
17
self.
run
= run
18
def
db_instance
(self):
19
if
self.
run
>=self.
_run2
:
20
return
'CONDBR2'
21
else
:
22
return
'COMP200'
23
def
sor_folder
(self):
24
if
self.
run
>=self.
_run2
:
25
return
'/TDAQ/RunCtrl/SOR'
26
else
:
27
return
'/TDAQ/RunCtrl/SOR_Params'
28
29
@cache
30
def
get_sor_params
(run_number) -> dict[str, Any] | None:
31
from
CoolConvUtilities
import
AtlCoolLib
32
33
log.info(
'Reading SOR record for run %s from COOL'
, run_number)
34
35
cdb =
CondDB
(run_number)
36
dbcon = AtlCoolLib.readOpen(
'COOLONL_TDAQ/%s'
% cdb.db_instance())
37
folder = dbcon.getFolder(cdb.sor_folder())
# type: ignore
38
39
# need to keep sor variable while using payload (cannot do the following in
40
# one single line nor overwrite sor). Otherwise: 1) GC comes into play;
41
# 2) the object is deleted; 3) since it's a shared_ptr, the internal
42
# cool::IObject also gets deleted; 4) payload is not valid any longer
43
try
:
44
sor = folder.findObject(run_number << 32, 0)
45
except
Exception:
46
return
None
# This can happen for unknown run numbers
47
48
payload = sor.payload()
49
d = {k: payload[k]
for
k
in
payload}
50
return
d
51
52
@cache
53
def
get_eor_params_crest
(run_number, crest_server:str) -> dict[str, Any] |
None
:
54
from
TrigConfStorage.TriggerCrestUtil
import
TriggerCrestUtil
55
log.info(
'Reading EOR record for run %s from Crest'
, run_number)
56
return
TriggerCrestUtil.getEORParams(run_number, server=crest_server)
57
58
@cache
59
def
get_trigconf_keys
(run_number, lb_number):
60
"""Read Trigger keys from COOL"""
61
62
from
TrigConfStorage.TriggerCoolUtil
import
TriggerCoolUtil
63
confKeys: dict[str, Any] = TriggerCoolUtil.getTrigConfKeys(run_number, lb_number)
64
confKeys[
'DBAlias'
] = confKeys.pop(
'DB'
,
None
)
65
return
confKeys
66
67
68
@cache
69
def
get_trigconf_keys_crest
(run_number, lb_number, crest_server):
70
"""Read Trigger keys from CREST"""
71
from
TrigConfStorage.TriggerCrestUtil
import
TriggerCrestUtil
72
log.info(
"Using CREST server %s"
, crest_server)
73
api: CrestApi = TriggerCrestUtil.getCrestApi(server=crest_server)
74
confKeys: dict[str, Any] = TriggerCrestUtil.getTrigConfKeys(run_number, lb_number, api=api)
75
confKeys[
'DBAlias'
] = confKeys.pop(
'DB'
,
None
)
76
return
confKeys
77
78
def
getCACfg
(jopath):
79
"""Return the CA Cfg function based on joboptions path.
80
The format is MODULE[.FNC]. If no FNC is given, 'main' will be tried."""
81
82
import
importlib
83
84
sys.path.append(
'.'
)
# temporarily add local directory to search path
85
86
# try to import module as given:
87
try
:
88
module = importlib.import_module(jopath)
89
except
ModuleNotFoundError:
90
if
'.'
not
in
jopath:
91
raise
92
# or interpret as module.fnc:
93
mod_name, fnc_name = jopath.rsplit(
'.'
, maxsplit=1)
94
module = importlib.import_module(mod_name)
95
else
:
96
# if the first import worked we are using the 'main(flags)' function:
97
fnc_name =
'main'
98
99
sys.path.pop()
100
101
log.info(
"Loading %s.%s"
, module.__name__, fnc_name)
102
return
getattr(module, fnc_name)
103
104
105
106
unparsedArguments = []
107
def
fillFromUnparsedArgs
(flags):
108
"""Re-apply the flags given on the athenaEF command line."""
109
110
for
flag_arg
in
unparsedArguments:
111
flags.fillFromString(flag_arg)
112
113
114
def
reload_from_json
(filename, suppress_args=[], jobOptions=None):
115
"""Re-launch athenaHLT from the given json file. Optionally suppress
116
the list of command line args (e.g. flags).
117
jobOptions: the positional argument to be replaced by `filename`."""
118
119
# Remove all command line args that are not compatible with running from JSON:
120
argv = []
121
for
arg_index, arg
in
enumerate(sys.argv):
122
if
arg ==
'--dump-config-reload'
:
123
continue
124
if
arg
in
[
'--precommand'
,
'-c'
,
'--postcommand'
,
'-C'
]:
125
continue
126
if
arg_index > 0
and
sys.argv[arg_index-1]
in
[
'--precommand'
,
'-c'
,
'--postcommand'
,
'-C'
]:
127
continue
128
if
arg.startswith(
'--precommand'
)
or
arg.startswith(
'--postcommand'
):
129
continue
130
if
arg
in
suppress_args:
131
continue
132
argv.append(arg)
133
134
if
jobOptions
is
not
None
and
jobOptions
in
argv:
135
argv[argv.index(jobOptions)] = filename
136
else
:
137
argv[-1] = filename
138
log.info(
'Restarting %s from %s ...'
, argv[0], filename)
139
sys.stdout.flush()
140
sys.stderr.flush()
141
os.execvp(argv[0], argv)
142
143
144
#
145
# Testing (used as ctest)
146
#
147
if
__name__==
'__main__'
:
148
# Can be used as script, e.g.: python -m TrigCommon.AthHLT 327265
149
if
len(sys.argv)>1:
150
log.info(
'SOR parameters: %s'
,
get_sor_params
(int(sys.argv[1])))
151
sys.exit(0)
152
153
# Unit testing case:
154
d =
get_sor_params
(327265)
# Run-2
155
assert(d
is
not
None
)
156
if
d
is
not
None
:
157
print
(d)
158
assert(d[
'DetectorMask'
]==
'0000000000000000c10069fffffffff7'
)
159
160
d =
get_eor_params_crest
(327265,
"https://crest.cern.ch/api-v5.0"
)
# Run-2
161
assert(d
is
not
None
)
162
if
d
is
not
None
:
163
print
(d)
164
assert(d[
'DetectorMask'
]==
'0000000000000000c10069fffffffff7'
)
165
166
d =
get_sor_params
(216416)
# Run-1
167
assert(d
is
not
None
)
168
if
d
is
not
None
:
169
print
(d)
170
assert(d[
'DetectorMask'
]==281474976710647)
171
172
# Config keys
173
d =
get_trigconf_keys
(360026, 1)
174
print
(d)
175
assert(d[
'SMK'
]==2749)
176
assert(d[
'LVL1PSK'
]==15186)
177
assert(d[
'HLTPSK'
]==17719)
178
179
# Config keys crest
180
d =
get_trigconf_keys_crest
(360026, 1,
"https://crest.cern.ch/api-v5.0"
)
181
print
(d)
182
assert(d[
'SMK'
]==2749)
183
assert(d[
'LVL1PSK'
]==15186)
184
assert(d[
'HLTPSK'
]==17719)
185
186
d =
get_trigconf_keys
(360026, 100)
187
print
(d)
188
assert(d[
'SMK'
]==2749)
189
assert(d[
'LVL1PSK'
]==23504)
190
assert(d[
'HLTPSK'
]==17792)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
python.AthHLT.CondDB
Definition
AthHLT.py:14
python.AthHLT.CondDB.db_instance
db_instance(self)
Definition
AthHLT.py:18
python.AthHLT.CondDB.run
run
Definition
AthHLT.py:17
python.AthHLT.CondDB._run2
int _run2
Definition
AthHLT.py:15
python.AthHLT.CondDB.sor_folder
sor_folder(self)
Definition
AthHLT.py:23
python.AthHLT.CondDB.__init__
__init__(self, run)
Definition
AthHLT.py:16
python.AthHLT.get_sor_params
dict[str, Any]|None get_sor_params(run_number)
Definition
AthHLT.py:30
python.AthHLT.reload_from_json
reload_from_json(filename, suppress_args=[], jobOptions=None)
Definition
AthHLT.py:114
python.AthHLT.get_trigconf_keys_crest
get_trigconf_keys_crest(run_number, lb_number, crest_server)
Definition
AthHLT.py:69
python.AthHLT.get_eor_params_crest
dict[str, Any]|None get_eor_params_crest(run_number, str crest_server)
Definition
AthHLT.py:53
python.AthHLT.getCACfg
getCACfg(jopath)
Definition
AthHLT.py:78
python.AthHLT.get_trigconf_keys
get_trigconf_keys(run_number, lb_number)
Definition
AthHLT.py:59
python.AthHLT.fillFromUnparsedArgs
fillFromUnparsedArgs(flags)
Definition
AthHLT.py:107
Generated on
for ATLAS Offline Software by
1.17.0