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