ATLAS Offline Software
Loading...
Searching...
No Matches
ReadLumiFromCrest.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: ReadLumiFromCrest.py
6# Sanya Solodkov <Sanya.Solodkov@cern.ch>, 2025-12-12
7#
8# Purpose: Read lumi values from CALO*PileUpNoiseLumi* tags
9#
10
11import getopt,sys,os
12os.environ['TERM'] = 'linux'
13
14def usage():
15 print ("Usage: ",sys.argv[0]," [OPTION] ... ")
16 print ("Dump Lumi values from online or offline CALO DB or from sqlite file")
17 print ("")
18 print ("-h, --help shows this help")
19 print ("-s, --schema= specify name of input JSON file or CREST_SERVER_PATH")
20 print ("-f, --folder= specify folder to use e.g. /CALO/Ofl/Noise/PileUpNoiseLumi")
21 print ("-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or tag suffix like RUN2-UPD4-04")
22 print ("-c, --channel= specify COOL channel, by default COOL channels 0 and 1 are used")
23 print ("-r, --run= specify run number, by default uses latest iov")
24 print ("-l, --lumi= specify lumi block number, default is 0")
25 print ("-b, --begin= specify run number of first iov in multi-iov mode, by default uses very first iov")
26 print ("-e, --end= specify run number of last iov in multi-iov mode, by default uses latest iov")
27
28letters = "hs:t:f:c:r:l:b:e:"
29keywords = ["help","schema=","tag=","folder=","channel=","run=","lumi=","begin=","end="]
30
31try:
32 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
33except getopt.GetoptError as err:
34 print (str(err))
35 usage()
36 sys.exit(2)
37
38# defaults
39run = 2147483647
40lumi = 0
41schema = 'CREST'
42#folderPath = '/CALO/Noise/PileUpNoiseLumi'
43folderPath = '/CALO/Ofl/Noise/PileUpNoiseLumi'
44dbName = 'CONDBR2'
45tag = 'UPD4'
46begin = 0
47end = 2147483647
48iov = False
49channels = [0,1]
50
51for o, a in opts:
52 a = a.strip()
53 if o in ("-s","--schema"):
54 schema = a
55 elif o in ("-f","--folder"):
56 folderPath = a
57 elif o in ("-t","--tag"):
58 tag = a
59 elif o in ("-c","--channel"):
60 channels = [int(a)]
61 elif o in ("-r","--run"):
62 run = int(a)
63 elif o in ("-l","--lumi"):
64 lumi = int(a)
65 elif o in ("-b","--begin"):
66 begin = int(a)
67 iov = True
68 elif o in ("-e","--end"):
69 end = int(a)
70 iov = True
71 elif o in ("-h","--help"):
72 usage()
73 sys.exit(2)
74 else:
75 usage()
76 sys.exit(2)
77
78from TileCalibBlobPython import TileCalibCrest
79from TileCalibBlobPython.TileCalibLogger import getLogger
80
81#=== get a logger
82log = getLogger("ReadLumi")
83import logging
84log.setLevel(logging.DEBUG)
85
86#=== Set tag and schema name:
87
88#=== Initialize blob reader
89folderTAG = tag.upper()
90if folderTAG.startswith("CALO") :
91 folderPath=""
92if not os.path.isfile(schema):
93 log.info("Initializing folder %s with tag %s", folderPath, tag)
94blobReader = TileCalibCrest.TileBlobReaderCrest(schema, folderPath, tag, run, lumi, channels[0], channels[-1], True)
95
96#=== Filling the iovList
97iovList = []
98if iov:
99 iovList = blobReader.getIovs((begin,0),(end,0))
100 be=iovList[0][0]
101 en=iovList[-1][0]
102
103 if begin != be or end != en:
104 log.info( "" )
105 if be != begin:
106 log.info( "Changing begin run from %d to %d (start of IOV)", begin,be)
107 begin=be
108 if en != end:
109 if en>end:
110 log.info( "Changing end run from %d to %d (start of next IOV)", end,en)
111 else:
112 log.info( "Changing end run from %d to %d (start of last IOV)", end,en)
113 end=en
114 log.info( "%d IOVs in total", len(iovList) )
115else:
116 iovList.append((run,lumi))
117
118log.info( "\n" )
119
120#=== loop over all iovs
121obj = None
122pref = ""
123pref1 = ""
124suff = ""
125for iovs in iovList:
126 if iov:
127 pref = "(%i,%i) " % (iovs[0],iovs[1])
128 pref1 = pref
129 values = []
130 try:
131 obj = blobReader.getPayload(iovs, False)
132 for chan in channels:
133 values += [obj[str(chan)]]
134 pref1 = pref+"lumi"
135 except Exception:
136 obj = None
137 log.warning( "Warning: can not read data from input DB" )
138 if not iov and obj is not None:
139 io = blobReader.getIov()
140 (sinceRun,sinceLum) = (io[0][0],io[0][1])
141 (untilRun,untilLum) = (io[1][0],io[1][1])
142 suff = " iov since [%d,%d] until (%d,%d)" % (sinceRun,sinceLum,untilRun,untilLum)
143 if len(values)==1:
144 print(pref1,values[0],suff)
145 else:
146 print(pref1,values,suff)
void print(char *figname, TCanvas *c1)