ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TileCalorimeter
TileCalib
TileCalibBlobPython
scripts
WriteLumiToCrest.py
Go to the documentation of this file.
1
#!/bin/env python
2
3
# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4
#
5
# File: WriteLumiToCrest.py
6
# Sanya Solodkov <Sanya.Solodkov@cern.ch>, 2025-12-12
7
#
8
# Purpose: Prepare JSON file with new lumi values
9
# specified at command line with --value= and --value2= options
10
#
11
12
import
getopt,sys,os
13
os.environ[
'TERM'
] =
'linux'
14
15
def
usage
():
16
print
(
"Usage: "
,sys.argv[0],
" [OPTION] ... "
)
17
print
(
"Prepare sqlite file with Lumi values for CALO database"
)
18
print
(
""
)
19
print
(
"-h, --help shows this help"
)
20
print
(
"-i, --inschema= specify name of input JSON file or CREST_SERVER_PATH"
)
21
print
(
"-o, --outschema= specify name of output JSON file, default is CaloNoise.json"
)
22
print
(
"-t, --tag= specify the tag"
)
23
print
(
"-f, --folder= specify folder to use e.g. /CALO/Ofl/Noise/PileUpNoiseLumi "
)
24
print
(
"-x, --txtfile= specify the text file with the new noise constants"
)
25
print
(
"-v, --value= specify new lumi value"
)
26
print
(
"-V, --value2= specify new valid flag"
)
27
print
(
"-c, --channel= specify COOL channel, by default COOL channels 0 and 1 are used"
)
28
print
(
"-r, --run= specify run number for start of IOV"
)
29
print
(
"-l, --lumi= specify lumiblock number for start of IOV, default is 0"
)
30
31
letters =
"hi:o:t:f:x:v:V:c:r:l:u"
32
keywords = [
"help"
,
"inschema="
,
"outschema="
,
"tag="
,
"folder="
,
"txtfile="
,
"value="
,
"value2="
,
"channel="
,
"run="
,
"lumi="
,
"update"
,
"infile="
,
"outfile="
]
33
34
try
:
35
opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
36
except
getopt.GetoptError
as
err:
37
print
(str(err))
38
usage
()
39
sys.exit(2)
40
41
# defaults
42
inSchema =
'CREST'
43
outSchema =
'PileUp.json'
44
folderPath =
'/CALO/Ofl/Noise/PileUpNoiseLumi'
45
tag =
'UPD4'
46
txtFile =
''
47
value =
None
48
value2 =
None
49
run = -1
50
lumi = 0
51
update =
False
52
channels = [0,1]
53
54
for
o, a
in
opts:
55
a = a.strip()
56
if
o
in
(
"-i"
,
"--inschema"
,
"--infile"
):
57
inSchema = a
58
elif
o
in
(
"-o"
,
"--outschema"
,
"--outfile"
):
59
outSchema = a
60
elif
o
in
(
"-t"
,
"--tag"
):
61
tag = a
62
elif
o
in
(
"-f"
,
"--folder"
):
63
folderPath = a
64
elif
o
in
(
"-c"
,
"--channel"
):
65
channels = [int(a)]
66
elif
o
in
(
"-r"
,
"--run"
):
67
run = int(a)
68
elif
o
in
(
"-l"
,
"--lumi"
):
69
lumi = int(a)
70
elif
o
in
(
"-u"
,
"--update"
):
71
update =
True
72
elif
o
in
(
"-x"
,
"--txtfile"
):
73
txtFile = a
74
elif
o
in
(
"-v"
,
"--value"
):
75
value = float(a)
76
elif
o
in
(
"-V"
,
"--value2"
):
77
value2 = int(a)
78
elif
o
in
(
"-h"
,
"--help"
):
79
usage
()
80
sys.exit(2)
81
else
:
82
print
(o, a)
83
usage
()
84
sys.exit(2)
85
86
#=== check presence of all parameters
87
print
(
""
)
88
inputIsFile = os.path.isfile(inSchema)
89
tagIsFullTag = tag.upper().startswith(
'CALO'
)
90
if
len(inSchema)<1:
91
print
(
"Please, provide inschema (e.g. --inschema=PileUp.json or --inschema=CREST)"
)
92
sys.exit(2)
93
if
len(outSchema)<1:
94
print
(
"Please, provide outschema (e.g. --outschema=PileUp.json)"
)
95
sys.exit(2)
96
if
not
inputIsFile:
97
if
len(folderPath)<1
and
not
tagIsFullTag:
98
print
(
"Please, provide folder (e.g. --folder=/CALO/Ofl/Noise/PileUpNoiseLumi)"
)
99
sys.exit(2)
100
if
len(tag)<1:
101
print
(
"Please, provide tag (e.g. --tag=RUN2-UPD4-05 or --tag=CALOOflNoisePileUpNoiseLumi-RUN2-UPD4-05)"
)
102
sys.exit(2)
103
else
:
104
if
not
tagIsFullTag:
105
print
(
"Please, provide full tag (e.g. --tag=CALOOflNoisePileUpNoiseLumi-RUN2-UPD4-05)"
)
106
sys.exit(2)
107
108
if
run<0:
109
print
(
"Please, provide run number (e.g. --run=123456)"
)
110
sys.exit(2)
111
112
from
TileCalibBlobPython
import
TileCalibCrest
113
from
TileCalibBlobPython.TileCalibLogger
import
getLogger
114
115
#=== get a logger
116
log = getLogger(
"WriteLumi"
)
117
import
logging
118
log.setLevel(logging.DEBUG)
119
120
#=== Initialize blob reader
121
folder = folderPath
122
if
tagIsFullTag:
123
folder=
""
124
if
not
inputIsFile:
125
log.info(
"Initializing folder %s with tag %s"
, folder, tag)
126
reader = TileCalibCrest.TileBlobReaderCrest(inSchema,folder,tag,run,lumi,channels[0],channels[-1],
True
)
127
obj = reader.getPayload(
None
,
False
)
128
if
obj
is
None
:
129
log.critical(
"Could not read payload from CREST DB"
)
130
sys.exit(1)
131
if
not
tagIsFullTag:
132
tag = reader.getTag()
133
134
for
chan
in
channels:
135
try
:
136
if
value
is
not
None
:
137
obj[str(chan)][0] = value
138
if
value2
is
not
None
:
139
obj[str(chan)][1] = value2
140
except
Exception:
141
log.critical(f
"Can not set values for channel {chan}"
)
142
log.critical(
"Full payload is: "
+str(obj))
143
sys.exit(1)
144
145
if
len(txtFile):
146
try
:
147
with
open(txtFile,
"r"
)
as
f:
148
allData = f.readlines()
149
except
Exception:
150
print
(
"\nCan not read input file %s"
% (txtFile))
151
sys.exit(2)
152
153
for
line
in
allData:
154
fields = line.strip().
split
()
155
#=== ignore empty and comment lines
156
if
not
len(fields) :
157
continue
158
if
fields[0].startswith(
"#"
):
159
continue
160
try
:
161
ch = int(fields[0])
162
for
chan
in
(channels
if
ch<0
else
[ch]):
163
if
len(fields)>1
and
fields[1].lower() !=
"keep"
:
164
obj[str(chan)][0] = float(fields[1])
165
if
len(fields)>2
and
fields[2].lower() !=
"keep"
:
166
obj[str(chan)][1] = int(fields[2])
167
except
Exception:
168
log.error(f
"Can not process line {line} - skipping"
)
169
170
log.info(
"Writing payload "
+str(obj) )
171
writer = TileCalibCrest.TileBlobWriterCrest(outSchema,folder,
None
,obj)
172
writer.register((run,lumi), tag)
173
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
WriteLumiToCrest.usage
usage()
Definition
WriteLumiToCrest.py:15
Generated on
for ATLAS Offline Software by
1.17.0