ATLAS Offline Software
Loading...
Searching...
No Matches
WriteLumiToCool.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# WriteLumiToCool.py
6# Sanya Solodkov <Sanya.Solodkov@cern.ch>
7#
8# Purpose: Manual update of lumi values in 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 ("Prepare sqlite file with Lumi values for CALO database")
17 print ("")
18 print ("-h, --help shows this help")
19 print ("-i, --infile= specify the input sqlite file for comparison or full schema string")
20 print ("-o, --outfile= specify the output sqlite file")
21 print ("-t, --tag= specify the tag")
22 print ("-f, --folder= specify folder to use e.g. /CALO/Ofl/Noise/PileUpNoiseLumi ")
23 print ("-d, --dbname= specify the database name e.g. OFLP200")
24 print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
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 print ("-u --update set this flag if output sqlite file should be updated, otherwise it'll be recreated")
31
32letters = "hi:o:t:f:d:S:v:V:c:r:l:u"
33keywords = ["help","infile=","outfile=","tag=","folder=","dbname=","server=","value=","value2=","channel=","run=","lumi=","update"]
34
35try:
36 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
37except getopt.GetoptError as err:
38 print (str(err))
39 usage()
40 sys.exit(2)
41
42# defaults
43inFile = 'COOLOFL_CALO/CONDBR2'
44outFile = 'caloSqlite.db'
45tag = ''
46folderPath = ''
47dbName = 'CONDBR2'
48server = ''
49value = None
50value2 = 0
51run = -1
52lumi = 0
53update = False
54channels = [0,1]
55
56for o, a in opts:
57 a = a.strip()
58 if o in ("-i","--infile"):
59 inFile = a
60 elif o in ("-o","--outfile"):
61 outFile = a
62 elif o in ("-t","--tag"):
63 tag = a
64 elif o in ("-f","--folder"):
65 folderPath = a
66 elif o in ("-d","--dbname"):
67 dbName = a
68 elif o in ("-S","--server"):
69 server = a
70 elif o in ("-c","--channel"):
71 channels = [int(a)]
72 elif o in ("-r","--run"):
73 run = int(a)
74 elif o in ("-l","--lumi"):
75 lumi = int(a)
76 elif o in ("-u","--update"):
77 update = True
78 elif o in ("-v","--value"):
79 value = a
80 elif o in ("-V","--value2"):
81 value2 = a
82 elif o in ("-h","--help"):
83 usage()
84 sys.exit(2)
85 else:
86 print (o, a)
87 usage()
88 sys.exit(2)
89
90#=== check presence of all parameters
91print ("")
92if len(inFile)<1:
93 raise Exception("Please, provide infile (e.g. --infile=COOLOFL_TILE/OFLP200)")
94if len(outFile)<1:
95 raise Exception("Please, provide outfile (e.g. --outfile=caloSqlite.db)")
96if len(tag)<1:
97 raise Exception("Please, provide tag (e.g. --tag=RUN2-UPD4-04)")
98if len(dbName)<1:
99 raise Exception("Please, provide dbname (e.g. --dbname=OFLP200 or --dbname=CONDBR2)")
100if value is None:
101 raise Exception("Please, provide value (e.g. --value=12345)")
102if run<0:
103 raise Exception("Please, provide run number (e.g. --run=123456)")
104
105from PyCool import cool
106from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
107
108#=== get a logger
109log = CaloCondLogger.getLogger("WriteLumi")
110import logging
111log.setLevel(logging.DEBUG)
112
113#=== Set tag and schema name:
114
115if tag=="HEAD":
116 tag=""
117
118if os.path.isfile(inFile):
119 ischema = 'sqlite://;schema='+inFile+';dbname='+dbName
120else:
121 log.info("File %s was not found, assuming it's full schema string" , inFile)
122 ischema = inFile
123 # possible strings for inFile - full schema connection string or short names like
124 # COOLONL_CALO/CONDBR2 COOLOFL_CALO/CONDBR2 COOLOFL_CALO/OFLP200
125
126#=== Open DB connections
127oschema = 'sqlite://;schema='+outFile+';dbname='+dbName
128dbr = CaloCondTools.openDbConn(ischema,server)
129update = update or (inFile==outFile)
130dbw = CaloCondTools.openDbConn(oschema,('UPDATE' if update else 'RECREATE'))
131
132if len(folderPath)==0:
133 if 'ONL' in ischema:
134 folderPath = '/CALO/Noise/PileUpNoiseLumi'
135 else:
136 folderPath = '/CALO/Ofl/Noise/PileUpNoiseLumi'
137
138if tag=='UPD1' or tag=='UPD4':
139 from TileCalibBlobPython import TileCalibTools
140 folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag )
141elif folderPath.startswith('/CALO/Ofl/Noise/PileUpNoiseLumi'):
142 folderTag = 'CALOOflNoisePileUpNoiseLumi-'+tag
143elif folderPath.startswith('/CALO/Noise/PileUpNoiseLumi'):
144 folderTag = 'CALONoisePileUpNoiseLumi-'+tag
145else:
146 folderTag = tag
147
148#=== creating folder specifications
149spec = cool.RecordSpecification()
150spec.extend( 'LBAvInstLumi', cool.StorageType.Float )
151spec.extend( 'Valid', cool.StorageType.UInt32 )
152
153multiVersion=(len(folderTag)>0)
154
155if multiVersion:
156 folderMode = cool.FolderVersioning.MULTI_VERSION
157 folderSpec = cool.FolderSpecification(folderMode, spec)
158else:
159 folderMode = cool.FolderVersioning.SINGLE_VERSION
160 folderSpec = cool.FolderSpecification(folderMode, spec)
161
162log.info( "Using folder %s with tag %s", folderPath,folderTag )
163folderDescr = CaloCondTools.getAthenaFolderDescr()
164folderR = dbr.getFolder(folderPath)
165if update:
166 try:
167 folderW = dbw.getFolder(folderPath)
168 except Exception:
169 folderW = dbw.createFolder(folderPath, folderSpec, folderDescr, True)
170else:
171 folderW = dbw.createFolder(folderPath, folderSpec, folderDescr, True)
172
173newval1 = float(value)
174newval2 = int(value2)
175newiov = "[%d,%d] - infinity" % (run, lumi)
176since = CaloCondTools.iovFromRunLumi( run, lumi )
177until = CaloCondTools.iovFromRunLumi( CaloCondTools.MAXRUN, CaloCondTools.MAXLBK )
178
179for chan in channels:
180 try:
181 obj = folderR.findObject( since, chan, folderTag )
182 (sinceRun,sinceLum) = CaloCondTools.runLumiFromIov(obj.since())
183 (untilRun,untilLum) = CaloCondTools.runLumiFromIov(obj.until())
184 val1 = obj.payload()[0]
185 val2 = obj.payload()[1]
186 oldiov = "[%d,%d] - (%d,%d)" % (sinceRun,sinceLum,untilRun,untilLum)
187 except Exception:
188 val1 = None
189 val2 = None
190 oldiov = "[NaN,NaN] - (NaN,NaN)"
191 #log.warning("IOV [%d,%d] was not found in input DB", run, lumi )
192
193 print("COOL channel",chan,"old iov",oldiov," old values [",val1,",",val2,
194 "] new values [",newval1,",",newval2,"] new iov",newiov)
195
196 spec = folderW.payloadSpecification()
197 data = cool.Record( spec )
198 data['LBAvInstLumi'] = newval1
199 data['Valid'] = newval2
200 folderW.storeObject(since, until, data, chan, folderTag, multiVersion)
201
202#=== Cleanup
203dbw.closeDatabase()
204dbr.closeDatabase()
void print(char *figname, TCanvas *c1)