ATLAS Offline Software
Loading...
Searching...
No Matches
ReadLumiFromCool.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# ReadLumiFromCool.py
6# Sanya Solodkov <Sanya.Solodkov@cern.ch>
7#
8# Purpose: Read lumi values from CALO COOL DB
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 schema to use, ONL or OFL for RUN1 or ONL2 or OFL2 for RUN2 or MC")
20 print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
21 print ("-d, --dbname= specify the database name e.g. CONDBR2")
22 print ("-f, --folder= specify folder to use e.g. /CALO/Ofl/Noise/PileUpNoiseLumi")
23 print ("-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or tag suffix like RUN2-UPD4-04")
24 print ("-c, --channel= specify COOL channel, by default COOL channels 0 and 1 are used")
25 print ("-r, --run= specify run number, by default uses latest iov")
26 print ("-l, --lumi= specify lumi block number, default is 0")
27 print ("-b, --begin= specify run number of first iov in multi-iov mode, by default uses very first iov")
28 print ("-e, --end= specify run number of last iov in multi-iov mode, by default uses latest iov")
29
30letters = "hS:s:d:t:f:c:r:l:b:e:"
31keywords = ["help","server=","schema=","dbname=","tag=","folder=","channel=","run=","lumi=","begin=","end="]
32
33try:
34 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
35except getopt.GetoptError as err:
36 print (str(err))
37 usage()
38 sys.exit(2)
39
40# defaults
41run = 2147483647
42lumi = 0
43server = ''
44schema = 'OFL2'
45folderPath = ''
46dbName = 'CONDBR2'
47tag = 'UPD4'
48begin = -1
49end = 2147483647
50iov = False
51channels = [0,1]
52
53for o, a in opts:
54 a = a.strip()
55 if o in ("-s","--schema"):
56 schema = a
57 elif o in ("-S","--server"):
58 server = a
59 elif o in ("-d","--dbname"):
60 dbName = a
61 elif o in ("-f","--folder"):
62 folderPath = a
63 elif o in ("-t","--tag"):
64 tag = a
65 elif o in ("-c","--channel"):
66 channels = [int(a)]
67 elif o in ("-r","--run"):
68 run = int(a)
69 elif o in ("-l","--lumi"):
70 lumi = int(a)
71 elif o in ("-b","--begin"):
72 begin = int(a)
73 iov = True
74 elif o in ("-e","--end"):
75 end = int(a)
76 iov = True
77 elif o in ("-h","--help"):
78 usage()
79 sys.exit(2)
80 else:
81 usage()
82 sys.exit(2)
83
84from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
85
86#=== get a logger
87log = CaloCondLogger.getLogger("ReadLumi")
88import logging
89log.setLevel(logging.DEBUG)
90
91#=== Set tag and schema name:
92
93if schema=='ONL': # shortcut for COOLONL_CALO/COMP200
94 schema='COOLONL_CALO/COMP200'
95 if tag=='UPD1' or tag=='UPD4':
96 tag='UPD1-00' # change default to latest RUN1 tag
97elif schema=='ONL2': # shortcut for COOLONL_CALO/CONDBR2
98 schema='COOLONL_CALO/CONDBR2'
99 if tag=='UPD1' or tag=='UPD4':
100 tag='RUN2-UPD1-00' # change default to the only tag available online
101elif schema=='OFL': # shortcut for COOLOFL_CALO/COMP200
102 schema='COOLOFL_CALO/COMP200'
103 if tag=='UPD1':
104 tag='UPD1-00' # change default to latest RUN1 tag
105 if tag=='UPD4':
106 tag='UPD4-02' # change default to latest RUN1 tag
107elif schema=='OFL2': # shortcut for COOLOFL_CALO/CONDBR2
108 schema='COOLOFL_CALO/CONDBR2'
109elif schema=='ONLMC': # shortcut for COOLONL_CALO/OFLP200
110 schema='COOLONL_CALO/OFLP200'
111 if tag=='UPD4':
112 tag='OFLCOND-RUN12-SDR-07' # change default to latest RUN1-RUN2 tag
113elif schema=='OFLMC' or schema=='MC': # shortcut for COOLOFL_CALO/OFLP200
114 schema='COOLOFL_CALO/OFLP200'
115 if tag=='UPD4':
116 tag='OFLCOND-MC23-SDR-RUN3-02' # change default to tag used in MC23
117
118if tag=="HEAD":
119 tag=""
120
121if os.path.isfile(schema):
122 schema = 'sqlite://;schema='+schema+';dbname='+dbName
123else:
124 log.info("File %s was not found, assuming it's full schema string" , schema)
125
126#=== Open DB connections
127db = CaloCondTools.openDbConn(schema, server)
128
129if len(folderPath)==0:
130 if 'ONL' in schema:
131 folderPath = '/CALO/Noise/PileUpNoiseLumi'
132 else:
133 folderPath = '/CALO/Ofl/Noise/PileUpNoiseLumi'
134
135if tag=='UPD1' or tag=='UPD4' or 'COND'in tag:
136 from TileCalibBlobPython import TileCalibTools
137 folderTag = TileCalibTools.getFolderTag(schema if 'COMP200' in schema or 'OFLP200' in schema else db, folderPath, tag )
138elif folderPath.startswith('/CALO/Ofl/Noise/PileUpNoiseLumi'):
139 folderTag = 'CALOOflNoisePileUpNoiseLumi-'+tag
140elif folderPath.startswith('/CALO/Noise/PileUpNoiseLumi'):
141 folderTag = 'CALONoisePileUpNoiseLumi-'+tag
142else:
143 folderTag = tag
144
145log.info("Initializing folder %s with tag %s", folderPath, folderTag)
146
147folder = db.getFolder(folderPath)
148
149#=== Filling the iovList
150iovList = []
151if iov:
152 try:
153 blobReader = CaloCondTools.CaloBlobReader(db,folderPath, folderTag)
154 dbobjs = blobReader.getDBobjsWithinRange(0)
155 if (dbobjs is None):
156 raise Exception("No DB objects retrieved when building IOV list!")
157 while dbobjs.goToNext():
158 obj = dbobjs.currentRef()
159 since = CaloCondTools.runLumiFromIov(obj.since())
160 until = CaloCondTools.runLumiFromIov(obj.until())
161 iovList.append((since, until))
162 except Exception:
163 log.warning( "Warning: can not read IOVs from input DB file" )
164 sys.exit(2)
165
166 be=iovList[0][0][0]
167 en=iovList[-1][0][0]
168
169 if begin != be or end != en:
170 ib=0
171 ie=len(iovList)
172 for i,iovs in enumerate(iovList):
173 run = iovs[0][0]
174 lumi = iovs[0][1]
175 if (run<begin and run>be) or (run==begin and lumi==0) :
176 be=run
177 ib=i
178 if run>=end and run<en:
179 en=run
180 ie=i+1
181 log.info( "" )
182 if be != begin:
183 log.info( "Changing begin run from %d to %d (start of IOV)", begin,be)
184 begin=be
185 if en != end:
186 if en>end:
187 log.info( "Changing end run from %d to %d (start of next IOV)", end,en)
188 else:
189 log.info( "Changing end run from %d to %d (start of last IOV)", end,en)
190 end=en
191 iovList=iovList[ib:ie]
192 log.info( "%d IOVs in total", len(iovList) )
193else:
194 iovList.append(((run,lumi),(CaloCondTools.MAXRUN, CaloCondTools.MAXLBK)))
195
196log.info( "\n" )
197
198#=== loop over all iovs and COOL channels
199obj = None
200pref = ""
201pref1 = ""
202suff = ""
203for iovs in iovList:
204 if iov:
205 pref = "(%i,%i) " % (iovs[0][0],iovs[0][1])
206 pref1 = pref
207 since = CaloCondTools.iovFromRunLumi(iovs[0][0],iovs[0][1])
208 values = []
209 for chan in channels:
210 try:
211 obj = folder.findObject( since, chan, folderTag )
212 try:
213 values += [[obj.payload()[0],obj.payload()[1]]]
214 pref1 = pref+"lumi"
215 except Exception:
216 #log.warning( "Warning: can not interpert data as Lumi values" )
217 pref1 = pref
218 values += [obj.payload()[0]]
219 except Exception:
220 obj = None
221 log.warning( "Warning: can not read data from input DB" )
222 if not iov and obj is not None:
223 (sinceRun,sinceLum) = CaloCondTools.runLumiFromIov(obj.since())
224 (untilRun,untilLum) = CaloCondTools.runLumiFromIov(obj.until())
225 suff = " iov since [%d,%d] until (%d,%d)" % (sinceRun,sinceLum,untilRun,untilLum)
226 if len(values)==1:
227 print(pref1,values[0],suff)
228 else:
229 print(pref1,values,suff)
230
231#=== close DB
232db.closeDatabase()
void print(char *figname, TCanvas *c1)