ATLAS Offline Software
WriteCalibToCool.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #
5 # WriteCalibToCool.py
6 # Sanya Solodkov 2014-08-29
7 # change Yuri Smirnov 2014-12-24
8 
9 import getopt,sys,os,bisect
10 os.environ['TERM'] = 'linux'
11 
12 def usage():
13  print ("Usage: ",sys.argv[0]," [OPTION] ... ")
14  print ("Update TileCal calibration constants in COOL")
15  print ("")
16  print ("-h, --help shows this help")
17  print ("-f, --folder= specify folder to use f.i. /TILE/OFL02/CALIB/CIS/LIN or /TILE/OFL02/TIME/CHANNELOFFSET/GAP/LAS")
18  print ("-F, --outfolder= specify the name of output folder if different from input folder")
19  print ("-t, --tag= specify tag to use, f.i. RUN2-HLT-UPD1-00 or RUN2-UPD4-00")
20  print ("-T, --outtag= specify output tag if different from input tag")
21  print ("-r, --run= specify run number, default is 0")
22  print ("-R, --run2= specify run number for new IOV where correction is undone")
23  print ("-l, --lumi= specify lumi block number, default is 0")
24  print ("-L, --lumi2= specify lumi block number for new IOV where correction is undone")
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  print ("-A, --adjust in multi-iov mode adjust iov boundaries to nearest iov available in DB, default is False")
28  print ("-D, --module= specify module to use in multi-IOV update, default is all")
29  print ("-c, --channel if present, means that one constant per channel is expected (i.e. no gain field)")
30  print ("-d, --default if present, means that also default values stored in AUX01-AUX20 should be updated")
31  print ("-a, --all if present, means that all drawers are saved, otherwise only those which were updated")
32  print ("-z, --zero if present, means that zero-sized blob is written for missing drawers")
33  print ("-Z, --allzero if present, means that zero-sized blob is created for all drawers which are not present in input file")
34  print ("-C, --nchannel= specify number of channels to store to DB, default is 0 - means the same as in input DB")
35  print ("-G, --ngain= specify number of gains to store to DB, default is 0 - means the same as in input DB")
36  print ("-n, --nval= specify number of values to store to DB, default is 0 - means all")
37  print ("-v, --version= specify blob version, by default version from input DB is used" )
38  print ("-x, --txtfile= specify the text file with the new constants for reading")
39  print ("-m, --comment= specify comment which should be written to DB, in multi-iov mode it is appended to old comment")
40  print ("-M, --Comment= specify comment which should be written to DB, in mutli-iov mode it overwrites old comment")
41  print ("-U, --user= specify username for comment")
42  print ("-p, --prefix= specify prefix which is expected on every line in input file, default - no prefix")
43  print ("-k, --keep= field numbers or channel numbers to ignore, e.g. '0,2,3,EBch0,EBch1,EBch12,EBch13,EBspD4ch18,EBspD4ch19,EBspC10ch4,EBspC10ch5' ")
44  print ("-i, --inschema= specify the input schema to use, default is 'COOLOFL_TILE/CONDBR2'")
45  print ("-o, --outschema= specify the output schema to use, default is 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2'")
46  print ("-s, --schema= specify input/output schema to use when both input and output schemas are the same")
47  print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
48  print ("-u --update set this flag if output sqlite file should be updated, otherwise it'll be recreated")
49  print ("-w, --swap= specify pair of modules which will be swapped in multi-IOV update, e.g. swap=EBA61,EBA63")
50 
51 letters = "hr:l:R:L:b:e:AD:S:s:i:o:t:T:f:F:C:G:n:v:x:m:M:U:p:dcazZuw:k:"
52 keywords = ["help","run=","lumi=","run2=","lumi2=","begin=","end=","adjust","module=","server=","schema=","inschema=","outschema=","tag=","outtag=","folder=","outfolder=","nchannel=","ngain=","nval=","version=","txtfile=","comment=","Comment=","user=","prefix=","default","channel","all","zero","allzero","update","swap=","keep="]
53 
54 try:
55  opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
56 except getopt.GetoptError as err:
57  print (str(err))
58  usage()
59  sys.exit(2)
60 
61 # defaults
62 run = -1
63 lumi = 0
64 run2 = -1
65 lumi2 = 0
66 server = ''
67 schema = 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2'
68 inSchema = 'COOLOFL_TILE/CONDBR2'
69 outSchema = 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2'
70 folderPath = "/TILE/OFL02/TIME/CHANNELOFFSET/GAP/LAS"
71 tag = "UPD1"
72 outfolderPath = None
73 outtag = None
74 readGain=True
75 rosmin = 1
76 all=False
77 zero=False
78 allzero=False
79 nchan = 0
80 ngain = 0
81 nval = 0
82 blobVersion = -1
83 txtFile= ""
84 comment = ""
85 Comment = None
86 prefix = ""
87 update = False
88 keep=[]
89 iov = False
90 beg = 0
91 end = 2147483647
92 moduleList = []
93 adjust = False
94 swap=[]
95 
96 try:
97  user=os.getlogin()
98 except Exception:
99  user="UnknownUser"
100 
101 for o, a in opts:
102  a = a.strip()
103  if o in ("-f","--folder"):
104  folderPath = a
105  elif o in ("-F","--outfolder"):
106  outfolderPath = a
107  elif o in ("-t","--tag"):
108  tag = a
109  elif o in ("-T","--outtag"):
110  outtag = a
111  elif o in ("-S","--server"):
112  server = a
113  elif o in ("-s","--schema"):
114  schema = a
115  inSchema = a
116  outSchema = a
117  elif o in ("-i","--inschema"):
118  inSchema = a
119  elif o in ("-o","--outschema"):
120  outSchema = a
121  elif o in ("-n","--nval"):
122  nval = int(a)
123  elif o in ("-G","--ngain"):
124  ngain = int(a)
125  elif o in ("-C","--nchannel"):
126  nchan = int(a)
127  elif o in ("-v","--version"):
128  blobVersion = int(a)
129  elif o in ("-d","--default"):
130  rosmin = 0
131  elif o in ("-c","--channel"):
132  readGain = False
133  elif o in ("-a","--all"):
134  all = True
135  elif o in ("-z","--zero"):
136  zero = True
137  elif o in ("-Z","--allzero"):
138  allzero = True
139  elif o in ("-u","--update"):
140  update = True
141  elif o in ("-w","--swap"):
142  swap += a.split(",")
143  elif o in ("-r","--run"):
144  run = int(a)
145  elif o in ("-l","--lumi"):
146  lumi = int(a)
147  elif o in ("-R","--run2"):
148  run2 = int(a)
149  elif o in ("-L","--lumi2"):
150  lumi2 = int(a)
151  elif o in ("-b","--begin"):
152  beg = int(a)
153  iov = True
154  elif o in ("-e","--end"):
155  end = int(a)
156  iov = True
157  elif o in ("-A","--adjust"):
158  adjust = True
159  elif o in ("-D","--module"):
160  moduleList += a.split(",")
161  elif o in ("-x","--txtfile"):
162  txtFile = a
163  elif o in ("-m","--comment"):
164  comment = a
165  elif o in ("-M","--Comment"):
166  Comment = a
167  comment = a
168  elif o in ("-U","--user"):
169  user = a
170  elif o in ("-p","--prefix"):
171  prefix = a
172  elif o in ("-k","--keep"):
173  keep = a.split(",")
174  elif o in ("-h","--help"):
175  usage()
176  sys.exit(2)
177  else:
178  raise RuntimeError("unhandeled option")
179 
180 moduleSwap={}
181 if len(swap)>0:
182  if len(swap)!=2:
183  RuntimeError("wrong module list for swap option")
184  else:
185  from TileCalibBlobPython import TileBchTools
186  for i in range(2):
187  m1=swap[i]
188  m2=swap[1-i]
189  moduleSwap[m1]=TileBchTools.TileBchMgr.decodeModule(None,m2)
190 else:
191  swap=False
192 
193 if not len(outSchema):
194  outSchema=schema
195 else:
196  schema=outSchema
197 if not len(inSchema):
198  inSchema=schema
199 update = update or (inSchema==outSchema)
200 
201 if outfolderPath is None:
202  outfolderPath=folderPath
203 elif tag=='UPD5' and outfolderPath!=folderPath:
204  print ('--tag="UPD5" option is not compatible with --outfolderPath option')
205  sys.exit(2)
206 if outtag is None:
207  outtag = tag
208 
209 import cppyy
210 
211 from TileCalibBlobPython import TileCalibTools
212 from TileCalibBlobObjs.Classes import TileCalibUtils, TileCalibType
213 
214 if iov and end >= TileCalibTools.MAXRUN:
215  end = TileCalibTools.MAXRUN
216  lumi2 = TileCalibTools.MAXLBK
217 until = (TileCalibTools.MAXRUN,TileCalibTools.MAXLBK)
218 
219 from TileCalibBlobPython.TileCalibLogger import getLogger
220 log = getLogger("WriteCalibToCool")
221 import logging
222 if iov:
223  log.setLevel(logging.INFO)
224 else:
225  log.setLevel(logging.DEBUG)
226 
227 #=== set database
228 dbr = TileCalibTools.openDbConn(inSchema,server)
229 dbw = TileCalibTools.openDbConn(outSchema,('UPDATE' if update else 'RECREATE'))
230 if tag=='UPD5':
231  tag='UPD4'
232  outtag='UPD4'
233  outfolderPath=folderPath
234  folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag )
235  tag2=folderTag.split('-')
236  tag2[len(tag2)-1]="%02d"%(int(tag2[len(tag2)-1])+1)
237  outfolderTag="-".join(tag2)
238 else:
239  folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag )
240  if outfolderPath==folderPath and outtag==tag:
241  outfolderTag = folderTag
242  else:
243  outfolderTag = TileCalibTools.getFolderTag(dbr, outfolderPath, outtag )
244 log.info("Initializing folder %s with tag %s", folderPath, folderTag)
245 
246 iovAll = []
247 iovList = []
248 iovUntil = []
249 iovListMOD = []
250 iovListCMT = []
251 iovUntilCMT = []
252 blobReader = TileCalibTools.TileBlobReader(dbr,folderPath, folderTag)
253 blobWriter2 = None
254 if iov:
255  #=== filling the iovList
256  log.info( "Looking for IOVs" )
257  if moduleList!=['CMT']:
258  for ros in range(rosmin,5):
259  for mod in range(min(64,TileCalibUtils.getMaxDrawer(ros))):
261  if len(moduleList)>0 and modName not in moduleList and 'ALL' not in moduleList:
262  iovAll+=[[]]
263  else:
264  iovMod = blobReader.getIOVsWithinRange(ros,mod)
265  iovAll+=[iovMod]
266  iovList+=iovMod
267  if 'ALL' in moduleList:
268  moduleList.remove('ALL')
269  else:
270  for ros in range(rosmin,5):
271  iovAll+=[[]]*min(64,TileCalibUtils.getMaxDrawer(ros))
272  if 'CMT' in moduleList:
273  iovListMOD = iovList
274  iovListCMT = blobReader.getIOVsWithinRange(-1,1000)
275  if len(iovList)==0:
276  iovList = iovListCMT
277  iovAll+=[iovListCMT]
278  else:
279  moduleList.remove('CMT')
280 
281  import functools
282  def compare(item1,item2):
283  if item1[0]!=item2[0]:
284  return item1[0]-item2[0]
285  else:
286  return item1[1]-item2[1]
287  iovList=list(set(iovList))
288  iovList=sorted(iovList,key=functools.cmp_to_key(compare))
289  iovList+=[until]
290  iovListCMT+=[until]
291 
292  since=(beg,lumi)
293  ib=bisect.bisect(iovList,since)-1
294  if ib<0:
295  ib=0
296  if iovList[ib] != since:
297  if adjust:
298  since = iovList[ib]
299  log.info( "Moving beginning of first IOV with new constants from (%d,%d) to (%d,%d)", beg,lumi,since[0],since[1])
300  else:
301  iovList[ib] = since
302  log.info( "Creating new IOV starting from (%d,%d) with new constants", beg,lumi)
303 
304  if end<0:
305  ie=ib+1
306  if ie>=len(iovList):
307  ie=ib
308  until=iovList[ie]
309  log.info( "Next IOV without new constants starts from (%d,%d)", until[0],until[1])
310  else:
311  until=(end,lumi2)
312  ie=bisect.bisect_left(iovList,until)
313  if ie>=len(iovList):
314  ie=len(iovList)-1
315 
316  if iovList[ie] != until:
317  if adjust:
318  until=iovList[ie]
319  log.info( "Moving end of last IOV from (%d,%d) to (%d,%d)", end,lumi2,until[0],until[1])
320  else:
321  log.info( "Keeping end of last IOV at (%d,%d) - new IOV is shorter than IOV in input DB", end,lumi2)
322  iovList[ie] = until
323 
324 
325  iovList = iovList[ib:ie]
326  iovUntil = iovList[1:] + [until]
327  begin = since
328  run = since[0]
329  lumi = since[1]
330  undo = False
331  log.info( "IOVs: %s", str(iovList))
332 
333  if len(iovListMOD)>0 and len(iovListCMT)>0:
334  if Comment is None:
335  iovList += [until] # one more IOV for "UNDO" comment
336  iovUntil += [until] # one more IOV for "UNDO" comment
337  iovUntilCMT = []
338  for io,since in enumerate(iovList):
339  p = bisect.bisect(iovListCMT,since)
340  if p<len(iovListCMT):
341  iovUntilCMT += [iovListCMT[p]]
342  if iovUntil[io] != iovListCMT[p]:
343  log.info( "End of iov %s in comments record is %s", str(since),str(iovListCMT[p]))
344  else:
345  if since!=until:
346  iovUntilCMT += [since]
347  else:
348  iovList.pop(-1)
349  break
350  since = begin
351  else:
352  iovUntilCMT = iovUntil
353 
354  log.info( "%d IOVs in total, end of last IOV is %s", ie-ib,str(until))
355 
356 else:
357  #=== set run number
358  if run==0:
359  begin=(0,0)
360  if run<=0:
361  if "UPD4" in outtag:
362  run=TileCalibTools.getPromptCalibRunNumber()
363  log.warning( "Run number is not specified, using minimal run number in calibration loop %d", run )
364  else:
365  run=TileCalibTools.getLastRunNumber()
366  log.warning( "Run number is not specified, using current run number %d", run )
367  if run<0:
368  log.error( "Bad run number" )
369  sys.exit(2)
370 
371  since = (run, lumi)
372  iovList = [since]
373  iovUntil = [until]
374  iovUntilCMT = [until]
375  if "begin" not in dir():
376  begin=since
377  if run2<0:
378  run2=begin[0]
379  if run2>begin[0] or (run2==begin[0] and lumi2>begin[1]):
380  undo=True
381  blobWriter2 = True
382  else:
383  undo=False
384 
385  log.info("Initializing for run %d, lumiblock %d", run,lumi)
386 
387 flt=None
388 r=5
389 d=0
390 blobT=None
391 while not flt:
392  d-=1
393  if d<0:
394  r-=1
395  if r<0:
396  break
398  flt = blobReader.getDrawer(r, d, since, False, False)
399 if flt:
400  blobT=flt.getObjType()
401  blobV=flt.getObjVersion()
402  mchan=flt.getNChans()
403  mgain=flt.getNGains()
404  mval=flt.getObjSizeUint32()
405  log.info( "Blob type: %d version: %d Nchannels: %d Ngains: %d Nval: %d", blobT,blobV,mchan,mgain,mval)
406  if blobVersion<0:
407  blobVersion = blobV
408 else:
409  mchan=-1
410  mgain=-1
411  mval=-1
412 nchanDef=nchan
413 ngainDef=ngain
414 
415 
416 if blobT:
417  typeName = TileCalibType.getClassName(blobT)[-3:]
418 else:
419  typeName = 'Flt'
420 
421 if blobWriter2:
422  blobWriter2 = TileCalibTools.TileBlobWriter(dbw,outfolderPath,typeName,(True if len(outtag) else False))
423 
424 comments = []
425 blobWriters = []
426 nvalUpdated = []
427 commentsSplit = []
428 for since in iovList:
429  comm=blobReader.getComment(since)
430  log.info("Comment: %s", comm)
431  comments+=[comm]
432  nvalUpdated += [0]
433  commentsSplit+=[blobReader.getComment(since,True)]
434  blobWriters += [TileCalibTools.TileBlobWriter(dbw,outfolderPath,typeName,(True if len(outtag) else False))]
435 log.info( "\n" )
436 
437 if len(txtFile)>0:
438  #=== create default: one number per ADC
439  if typeName=='Flt':
440  defConst = cppyy.gbl.std.vector('std::vector<float>')()
441  default = cppyy.gbl.std.vector('float')()
442  defVal = 0.
443  else:
444  defConst = cppyy.gbl.std.vector('std::vector<int>')()
445  default = cppyy.gbl.std.vector('int')()
446  defVal = 0
447 
448  for n in range(nval if nval>0 else mval):
449  default.push_back(defVal)
450 
451  for ng in range(ngain if ngain>0 else mgain):
452  defConst.push_back(default) # low/high gain
453 
454  blobParser = TileCalibTools.TileASCIIParser2(txtFile,prefix,readGain)
455  mval=0
456 
457  #=== loop over all IOVs
458  for io,since in enumerate(iovList):
459 
460  if since==iovUntil[io]: # dummy IOV without update
461  continue
462 
463  log.info( "Updating IOV %s", str(since) )
464  nold=0
465  nnew=0
466  ndef=0
467  nvold=0
468  nvnew=0
469  nvdef=0
470  nvnewdef=0
471 
472  #=== loop over whole detector
473  irm=-1
474  for ros in range(rosmin,5):
475  for mod in range(min(64,TileCalibUtils.getMaxDrawer(ros))):
476  irm+=1
477  if iov and since!=begin and (since not in iovAll[irm]):
478  continue
479  modName = TileCalibUtils.getDrawerString(ros,mod)
480  if modName in ['EBA39','EBA40','EBA41','EBA42','EBA55','EBA56','EBA57','EBA58',
481  'EBC39','EBC40','EBC41','EBC42','EBC55','EBC56','EBC57','EBC58' ]:
482  modSpec = 'EBspC10'
483  elif modName in ['EBA15','EBC18']:
484  modSpec = 'EBspD4'
485  elif modName in ['EBC29','EBC32','EBC34','EBC37']:
486  modSpec = 'EBspE4'
487  elif modName in ['EBA07', 'EBA25', 'EBA44', 'EBA53',
488  'EBC07', 'EBC25', 'EBC44', 'EBC53',
489  'EBC28', 'EBC31', 'EBC35', 'EBC38' ]:
490  modSpec = 'EBspE1'
491  elif modName in ['EBA08', 'EBA24', 'EBA43', 'EBA54',
492  'EBC08', 'EBC24', 'EBC43', 'EBC54' ]:
493  modSpec = 'EBMBTS'
494  else:
495  modSpec = modName
496  newDrawer=True
497  flt1 = blobReader.getDrawer(ros, mod, since, False, False)
498  if flt1:
499  oldNchan = flt1.getNChans()
500  oldNgain = flt1.getNGains()
501  oldVsize = flt1.getObjSizeUint32()
502  else:
503  oldNchan = 0
504  oldNgain = 0
505  oldVsize = 0
506  nchan = nchanDef if nchanDef>0 else (flt1.getNChans() if flt1 else TileCalibUtils.max_chan())
507  ngain = ngainDef if ngainDef>0 else (flt1.getNGains() if flt1 else TileCalibUtils.max_gain())
508 
509  (rosR,modR,modNameR) = (ros,mod,modName)
510  (rosW,modW,modNameW) = (ros,mod,modName)
511  if swap and modName in moduleSwap:
512  (rosW,modW) = moduleSwap[modName]
513  modNameW = TileCalibUtils.getDrawerString(rosW,modW)
514  log.warning("Swap: read %s write %s", modName,modNameW)
515  for chn in range(nchan):
516  #=== loop over gains
517  for adc in range(ngain):
518  data = blobParser.getData(rosR,modR,chn,adc,since)
519  if not len(data) and allzero:
520  continue
521  if not len(data) and (not all or (not flt1 and not rosmin)):
522  if not rosmin:
523  log.warning("%i/%2i/%2i/%i: No value found in file", rosR,modR,chn,adc)
524  continue
525  #=== need to invalidate previous blob in DB when reading from ASCII file
526  if newDrawer:
527  newDrawer=False
528  blobWriters[io].zeroBlob(rosW,modW)
529  #=== init drawer for first entry
530  calibDrawer = blobWriters[io].getDrawer(rosW,modW)
531  if not calibDrawer.getNObjs():
532  log.info("Initializing drawer %s", modNameW)
533  flt = blobReader.getDrawer(rosR, modR, since)
534  if nval<1:
535  mval = flt.getObjSizeUint32()
536  default.clear()
537  for n in range(mval):
538  default.push_back(defVal)
539  defConst.clear()
540  for ng in range(ngain):
541  defConst.push_back(default) # low/high gain
542  else:
543  mval = nval
544  kval = mval if mval < flt.getObjSizeUint32() else flt.getObjSizeUint32()
545  if blobVersion<0:
546  blobVersion = flt.getObjVersion()
547  calibDrawer.init(defConst,nchan,blobVersion)
548  if undo:
549  calibDrawer2 = blobWriter2.getDrawer(rosW,modW)
550  calibDrawer2.init(defConst,nchan,blobVersion)
551  for ch in range(nchan):
552  for ad in range(ngain):
553  nold+=1
554  for n in range(0,kval):
555  nvold+=1
556  val=flt.getData(ch,ad,n)
557  log.debug("%i/%2i/%2i/%i: old data[%i] = %f", rosR,modR,ch,ad, n, val)
558  calibDrawer.setData(ch,ad,n,val)
559  if undo:
560  calibDrawer2.setData(ch,ad,n,val)
561  for n in range(kval,nval):
562  nvdef+=1
563  val=calibDrawer.getData(ch,ad,n)
564  log.debug("%i/%2i/%2i/%i: def data[%i] = %f", rosR,modR,ch,ad, n, val)
565 
566  if not len(data):
567  if not rosmin:
568  log.warning("%i/%2i/%2i/%i: No value found in file", rosR,modR,chn,adc)
569  continue
570  #=== loop over new data
571  if nval<1:
572  mval = flt.getObjSizeUint32()
573  else:
574  mval = nval
575  nnew+=1
576  kval=mval-len(data)
577  if kval>0:
578  if chn>=oldNchan or adc>=oldNgain:
579  ndef+=1
580  mval-=kval
581  for n in range(mval):
582  coef=None
583  strval=data[n]
584  if strval.startswith("*"):
585  coef=float(strval[1:])
586  val = calibDrawer.getData(chn,adc,n)*coef
587  log.debug("%i/%2i/%2i/%i: new data[%i] = %s scale old value by %s", rosW,modW,chn,adc, n, val, coef)
588  elif strval.startswith("++") or strval.startswith("+-") :
589  coef=float(strval[1:])
590  val = calibDrawer.getData(chn,adc,n)+coef
591  log.debug("%i/%2i/%2i/%i: new data[%i] = %s shift old value by %s", rosW,modW,chn,adc, n, val, coef)
592  elif strval=="sync":
593  val = calibDrawer.getData(chn,adc,n)
594  if val==0.0 or val==-1.0 or val==1.0: # copy from another gain only if in this gain one of default values
595  val = calibDrawer.getData(chn,1-adc,n)
596  elif strval=="copy":
597  val = calibDrawer.getData(chn,1-adc,n) # copy from another gain
598  elif strval=="lg" and adc==1:
599  val = calibDrawer.getData(chn,0,n) # copy from low gain
600  elif strval=="hg" and adc==0:
601  val = calibDrawer.getData(chn,1,n) # copy from high gain
602  elif strval=="keep" or strval=="None" or str(n) in keep or modName in keep or modSpec in keep or modName[:3] in keep or modName[:2] in keep \
603  or ("%sch%i"% (modName,chn)) in keep or ("%sch%i"% (modSpec,chn)) in keep or ("%sch%i"% (modName[:3],chn)) in keep or ("%sch%i"% (modName[:2],chn)) in keep \
604  or ("%sch%ig%i"% (modName,chn,adc)) in keep or ("%sch%ig%i"% (modSpec,chn,adc)) in keep or ("%sch%ig%i"% (modName[:3],chn,adc)) in keep or ("%sch%ig%i"% (modName[:2],chn,adc)) in keep:
605  val = None
606  else:
607  if "x" in strval or "X" in strval:
608  val = int(strval,16)
609  elif typeName=='Flt':
610  val = float(strval)
611  else:
612  val = int(strval)
613  if val is not None:
614  nvnew+=1
615  if n>=oldVsize:
616  nvdef-=1
617  nvnewdef+=1
618  calibDrawer.setData(chn,adc,n,val)
619  if coef is None:
620  log.debug("%i/%2i/%2i/%i: new data[%i] = %s", rosW,modW,chn,adc, n, val)
621  else:
622  val = calibDrawer.getData(chn,adc,n)
623  if n>=oldVsize:
624  log.debug("%i/%2i/%2i/%i: DEF data[%i] = %s", rosW,modW,chn,adc, n, val)
625  else:
626  log.debug("%i/%2i/%2i/%i: OLD data[%i] = %s", rosW,modW,chn,adc, n, val)
627  for n in range(mval,kval+mval):
628  val = calibDrawer.getData(chn,adc,n)
629  if n>=flt.getObjSizeUint32():
630  log.debug("%i/%2i/%2i/%i: DEF data[%i] = %s", rosW,modW,chn,adc, n, val)
631  else:
632  log.debug("%i/%2i/%2i/%i: OLD data[%i] = %s", rosW,modW,chn,adc, n, val)
633  if (zero or allzero) and newDrawer:
634  blobWriters[io].zeroBlob(rosW,modW)
635  if rosW==0 and modW==0:
636  if blobVersion<0:
637  blobVersion = flt.getObjVersion()
638  calibDrawer = blobWriters[io].getDrawer(rosW,modW)
639  calibDrawer.init(defConst,1,blobVersion)
640 
641  nvalUpdated[io]=nvnew
642  log.info("%d/%d old channels*gains/values have been read from database", nold,nvold)
643  log.info("%d/%d new channels*gains/values have been read from input ascii file", nnew,nvnew)
644  if nold>nnew or nvold>(nvnew-nvnewdef):
645  log.info("%d/%d old channels*gains/values remain unchanged", nold-nnew,nvold-nvnew+nvnewdef)
646  if nold<nnew or nvold<(nvnew-nvnewdef):
647  log.info("%d/%d new channels*gains/values have been added to database", nnew-nold,nvnew-nvold-nvnewdef)
648  if ndef or nvdef:
649  log.info("%d/%d new channels*gains/values with default values have been added to database", ndef,nvdef)
650 
651 #=== commit changes
652 if (mval!=0 or Comment is not None) and (len(comment)>0 or len(txtFile)>0):
653  if not iov:
654  iovList = [begin]
655 
656  #=== loop over all IOVs
657  for io,since in enumerate(iovList):
658 
659  untilMod = iovUntil[io]
660  untilCmt = iovUntilCMT[io]
661  appendCmt = (untilCmt < (TileCalibTools.MAXRUN,TileCalibTools.MAXLBK)) or iov
662 
663  if since==untilMod: # empty IOV
664  if since==untilCmt:
665  continue # nothing to do
666  undoCmt = True # only comments with UNDO text will be written
667  else:
668  undoCmt = False
669  if len(moduleList)!=1:
670  untilMod = until # more than one module updated
671  untilCmt = until # will use IOV till very end
672  elif untilCmt>untilMod:
673  untilCmt = untilMod
674 
675  if iov:
676  log.info( "Updating IOV %s => %s => %s", str(io), str(since), comments[io] )
677  else:
678  log.info( "Updating IOV %s", str(since) )
679 
680  #=== set comment
681  if Comment is not None:
682  comm = Comment
683  if undoCmt:
684  comm = "UNDO " + comm
685  author = user
686  else:
687  if (comment is None) or (comment == "None"):
688  comm = "None"
689  author = "None"
690  else:
691  if len(comment)==0:
692  if undoCmt:
693  if since[1]==0 and begin[1]==0:
694  comm="Update for run %i - undoing changes done for run %i from file %s" % (since[0],begin[0],txtFile)
695  else:
696  comm="Update for run,lumi %i,%i - undoing changes done for %i,%i from file %s" % (since[0],since[1],begin[0],begin[1],txtFile)
697  else:
698  if since[1]==0:
699  comm="Update for run %i from file %s" % (since[0],txtFile)
700  else:
701  comm="Update for run,lumi %i,%i from file %s" % (since[0],since[1],txtFile)
702  else:
703  comm = comment
704  if undoCmt:
705  comm = "UNDO " + comm
706  if iov and appendCmt:
707  comm += " // " + comments[io]
708  if not undoCmt and iov and (nvalUpdated[io]==0 or comment=="keep"):
709  author = commentsSplit[io]
710  else:
711  author = user
712  blobWriters[io].setComment(author,comm)
713 
714  #=== commit changes
715  if untilCmt!=untilMod:
716  cmtOnly = (since in iovListCMT and since not in iovListMOD)
717  if not cmtOnly and untilMod>since:
718  blobWriters[io].register(since,untilMod,outfolderTag,1)
719  if untilCmt>since:
720  blobWriters[io].register(since,untilCmt,outfolderTag,-1)
721  else:
722  blobWriters[io].register(since,untilMod,outfolderTag)
723 
724  if undo:
725  if (comment is None) or (comment == "None"):
726  blobWriter2.setComment("None","None")
727  else:
728  if run2>begin[0] and lumi2==0 and begin[1]==0:
729  comment="Update for run %i - undoing changes done for run %i from file %s" % (run2,begin[0],txtFile)
730  else:
731  comment="Update for run,lumi %i,%i - undoing changes done for %i,%i from file %s" % (run2,lumi2,begin[0],begin[1],txtFile)
732  blobWriter2.setComment(user,comment)
733  blobWriter2.register((run2,lumi2), until, outfolderTag)
734  elif run2>=0 and (run2<begin[0] or (run2==begin[0] and lumi2<begin[1]) and lumi2!=0):
735  log.warning("(run2,lumi2)=(%i,%i) is smaller than (run,lumi)=(%i,%i) - will not create second IOV", run2,lumi2,begin[0],begin[1])
736 else:
737  log.warning("Nothing to update")
738 
739 #=== close DB
740 dbr.closeDatabase()
741 dbw.closeDatabase()
TileCalibUtils::getMaxDrawer
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
Definition: TileCalibUtils.cxx:136
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TileCalibType::getClassName
static std::string getClassName(TileCalibType::TYPE type)
Returns the class name.
Definition: TileCalibType.cxx:10
register
#define register
Definition: dictionary.h:21
TileCalibUtils::max_gain
static unsigned int max_gain()
Python compatibility function.
Definition: TileCalibUtils.h:114
WriteCalibToCool.compare
def compare(item1, item2)
Definition: WriteCalibToCool.py:282
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
WriteCalibToCool.usage
def usage()
Definition: WriteCalibToCool.py:12
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
beamspotman.dir
string dir
Definition: beamspotman.py:623
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
min
#define min(a, b)
Definition: cfImp.cxx:40
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
TileCalibUtils::getDrawerString
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
Definition: TileCalibUtils.cxx:145
TileCalibUtils::max_chan
static unsigned int max_chan()
Python compatibility function.
Definition: TileCalibUtils.h:112
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83
python.CaloCondLogger.getLogger
def getLogger(name="CaloCond")
Definition: CaloCondLogger.py:16