ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TriggerCommon
TriggerMenuMT
scripts
generateBunchGroupSetFromOldKey.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
4
5
import
sys
6
import
json
7
8
from
TriggerMenuMT.L1.Base.BunchGroupSet
import
BunchGroupSet
9
from
TriggerMenuMT.L1.Base.L1MenuFlags
import
L1MenuFlags
10
from
AthenaCommon.Logging
import
logging
11
log = logging.getLogger(
"generateBunchGroupSetFromOldKey"
)
12
13
L1MenuFlags.CTPVersion = 4
14
L1MenuFlags.BunchGroupPartitioning = [1, 15, 15]
15
16
default_bgsname =
"generateBunchGroupSetFromOldKey"
17
18
default_bgnames = [
19
"BCRVETO"
,
20
"Paired"
,
21
"Calreq"
,
22
"Empty"
,
23
"UnpairedIsolated"
,
24
"UnpairedNonisolated"
,
25
"EmptyAfterFilled"
,
26
"Unpaired"
,
27
"NotUsed"
,
28
"NotUsed"
,
29
"NotUsed"
,
30
"NotUsed"
,
31
"NotUsed"
,
32
"NotUsed"
,
33
"NotUsed"
,
34
"NotUsed"
35
]
36
37
def
transform2
(oldbgs,bgsname,bgnames):
38
newbgs = BunchGroupSet(bgsname)
39
for
idx,bg
in
enumerate(oldbgs):
40
newbg = BunchGroupSet.BunchGroup(name = bgnames[idx], internalNumber = idx)
41
for
b
in
bg:
42
newbg.addBunch(b)
43
newbg.normalize()
44
newbgs.addBunchGroup(newbg)
45
return
newbgs
46
47
def
main
():
48
49
if
len(sys.argv)<2:
50
print
(
"Please run\n%s <old-style.json>\n"
% sys.argv[0].
split
(
'/'
)[-1])
# noqa: ATL901
51
print
(
"The old-style json file can be downloaded from the web using https://atlas-trigconf.cern.ch/bunchgroups?key=<key>&type=json"
)
# noqa: ATL901
52
return
1
53
54
inputFN = sys.argv[1]
55
56
with
open(inputFN)
as
fn:
57
inputJson = json.load(fn)
58
59
oldBGS = inputJson[0][
'code'
]
60
61
if
'name'
in
inputJson[0]:
62
bgsname = inputJson[0][
'name'
] +
" from Run2 key "
63
if
'bgkey'
in
inputJson[0]:
64
bgsname += str(inputJson[0][
'bgkey'
])
65
else
:
66
bgsname = default_bgsname
67
68
if
'bgnames'
in
inputJson[0]:
69
bgnames = inputJson[0][
'bgnames'
]
70
# replace 0 - BCRVETO with BCRVETO
71
for
i
in
range(len(bgnames)):
72
if
bgnames[i].
find
(
" - "
):
73
bgnames[i] = bgnames[i].
split
(
" - "
, 1)[1]
74
else
:
75
bgnames = default_bgnames
76
77
newBGS =
transform2
(oldBGS,bgsname,bgnames)
78
79
outputFN = inputFN.replace(
".json"
,
".newstyle.json"
)
80
newBGS.writeJSON(outputFN)
81
82
83
84
if
__name__ ==
"__main__"
:
85
sys.exit(
main
())
86
87
88
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
find
std::string find(const std::string &s)
return a remapped string
Definition
hcg.cxx:140
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
generateBunchGroupSetFromOldKey.main
main()
Definition
generateBunchGroupSetFromOldKey.py:47
generateBunchGroupSetFromOldKey.transform2
transform2(oldbgs, bgsname, bgnames)
Definition
generateBunchGroupSetFromOldKey.py:37
Generated on
for ATLAS Offline Software by
1.17.0