Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
11 import getopt,sys,os,re
12 os.environ['TERM'] = 'linux'
13 
14 def 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 
32 letters = "hi:o:t:f:d:S:v:V:c:r:l:u"
33 keywords = ["help","infile=","outfile=","tag=","folder=","dbname=","server=","value=","value2=","channel=","run=","lumi=","update"]
34 
35 try:
36  opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
37 except getopt.GetoptError as err:
38  print (str(err))
39  usage()
40  sys.exit(2)
41 
42 # defaults
43 inFile = 'COOLOFL_CALO/CONDBR2'
44 outFile = 'caloSqlite.db'
45 tag = ''
46 folderPath = ''
47 dbName = 'CONDBR2'
48 server = ''
49 value = None
50 value2 = 0
51 run = -1
52 lumi = 0
53 update = False
54 channels = [0,1]
55 
56 for 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
91 print ("")
92 if len(inFile)<1:
93  raise Exception("Please, provide infile (e.g. --infile=COOLOFL_TILE/OFLP200)")
94 if len(outFile)<1:
95  raise Exception("Please, provide outfile (e.g. --outfile=caloSqlite.db)")
96 if len(tag)<1:
97  raise Exception("Please, provide tag (e.g. --tag=RUN2-UPD4-04)")
98 if len(dbName)<1:
99  raise Exception("Please, provide dbname (e.g. --dbname=OFLP200 or --dbname=CONDBR2)")
100 if value is None:
101  raise Exception("Please, provide value (e.g. --value=12345)")
102 if run<0:
103  raise Exception("Please, provide run number (e.g. --run=123456)")
104 
105 from PyCool import cool
106 from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
107 
108 #=== get a logger
109 log = CaloCondLogger.getLogger("WriteLumi")
110 import logging
111 log.setLevel(logging.DEBUG)
112 
113 #=== Set tag and schema name:
114 
115 if tag=="HEAD":
116  tag=""
117 
118 if os.path.isfile(inFile):
119  ischema = 'sqlite://;schema='+inFile+';dbname='+dbName
120 else:
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
127 oschema = 'sqlite://;schema='+outFile+';dbname='+dbName
128 dbr = CaloCondTools.openDbConn(ischema,server)
129 update = update or (inFile==outFile)
130 dbw = CaloCondTools.openDbConn(oschema,('UPDATE' if update else 'RECREATE'))
131 
132 if len(folderPath)==0:
133  if 'ONL' in ischema:
134  folderPath = '/CALO/Noise/PileUpNoiseLumi'
135  else:
136  folderPath = '/CALO/Ofl/Noise/PileUpNoiseLumi'
137 
138 if tag=='UPD1' or tag=='UPD4':
139  from TileCalibBlobPython import TileCalibTools
140  folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag )
141 elif folderPath.startswith('/CALO/Ofl/Noise/PileUpNoiseLumi'):
142  folderTag = 'CALOOflNoisePileUpNoiseLumi-'+tag
143 elif folderPath.startswith('/CALO/Noise/PileUpNoiseLumi'):
144  folderTag = 'CALONoisePileUpNoiseLumi-'+tag
145 else:
146  folderTag = tag
147 
148 #=== creating folder specifications
149 spec = cool.RecordSpecification()
150 spec.extend( 'LBAvInstLumi', cool.StorageType.Float )
151 spec.extend( 'Valid', cool.StorageType.UInt32 )
152 
153 multiVersion=(len(folderTag)>0)
154 
155 if multiVersion:
156  folderMode = cool.FolderVersioning.MULTI_VERSION
157  folderSpec = cool.FolderSpecification(folderMode, spec)
158 else:
159  folderMode = cool.FolderVersioning.SINGLE_VERSION
160  folderSpec = cool.FolderSpecification(folderMode, spec)
161 
162 log.info( "Using folder %s with tag %s", folderPath,folderTag )
163 folderDescr = CaloCondTools.getAthenaFolderDescr()
164 folderR = dbr.getFolder(folderPath)
165 if update:
166  try:
167  folderW = dbw.getFolder(folderPath)
168  except Exception:
169  folderW = dbw.createFolder(folderPath, folderSpec, folderDescr, True)
170 else:
171  folderW = dbw.createFolder(folderPath, folderSpec, folderDescr, True)
172 
173 newval1 = float(value)
174 newval2 = int(value2)
175 newiov = "[%d,%d] - infinity" % (run, lumi)
176 since = CaloCondTools.iovFromRunLumi( run, lumi )
177 until = CaloCondTools.iovFromRunLumi( CaloCondTools.MAXRUN, CaloCondTools.MAXLBK )
178 
179 for 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
203 dbw.closeDatabase()
204 dbr.closeDatabase()
python.LArMinBiasAlgConfig.int
int
Definition: LArMinBiasAlgConfig.py:59
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
WriteLumiToCool.usage
def usage()
Definition: WriteLumiToCool.py:14
str
Definition: BTagTrackIpAccessor.cxx:11
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65