ATLAS Offline Software
Loading...
Searching...
No Matches
WriteCalibToCrest.py
Go to the documentation of this file.
1#!/bin/env python
2
3# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4#
5# File: WriteCalibToCrest.py
6# Sanya Solodkov <Sanya.Solodkov@cern.ch>, 2025-02-04
7#
8# Purpose: Prepare JSON file with new calibration constants
9# reading them from ascii file specified after --txtfile= option
10# All modules are always written, for channels which are not
11# mentioned in ascii file previous values are copied from CREST DB
12#
13# modified Siarhei Harkusha 2025-05-19
14# modified Laura Sargsyan 2025-09-16
15# various fixes Sanya Solodkov 2025-10-17
16
17import getopt,sys,os,bisect
18os.environ['TERM'] = 'linux'
19
20def usage():
21 print ("Usage: ",sys.argv[0]," [OPTION] ... ")
22 print ("Update TileCal calibration constants in CREST")
23 print ("")
24 print ("-h, --help shows this help")
25 print ("-f, --folder= specify folder to use f.i. /TILE/OFL02/CALIB/CIS/LIN or /TILE/OFL02/TIME/CHANNELOFFSET/GAP/LAS")
26 print ("-F, --outfolder= specify the name of output folder if different from input folder")
27 print ("-t, --tag= specify tag to use, f.i. RUN2-HLT-UPD1-00 or RUN2-UPD4-00")
28 print ("-T, --outtag= specify output tag if different from input tag")
29 print ("-r, --run= specify run number, default is 0")
30 print ("-R, --run2= specify run number for new IOV where correction is undone")
31 print ("-l, --lumi= specify lumi block number, default is 0")
32 print ("-L, --lumi2= specify lumi block number for new IOV where correction is undone")
33 print ("-b, --begin= specify run number of first iov in multi-iov mode, by default uses very first iov")
34 print ("-e, --end= specify run number of last iov in multi-iov mode, by default uses latest iov")
35 print ("-A, --adjust in multi-iov mode adjust iov boundaries to nearest iov available in DB, default is False")
36 print ("-D, --module= specify module to use in multi-IOV update, default is all")
37 print ("-c, --channel if present, means that one constant per channel is expected (i.e. no gain field)")
38 print ("-d, --default if present, means that default values stored in AUX01-AUX20 will NOT be saved")
39 print ("-a, --all if present, means that NOT all drawers are saved, but only those which were updated")
40 print ("-z, --zero if present, means that zero-sized blob is written for missing drawers")
41 print ("-Z, --allzero if present, means that zero-sized blob is created for all drawers which are not present in input file")
42 print ("-C, --nchannel= specify number of channels to store to DB, default is 0 - means the same as in input DB")
43 print ("-G, --ngain= specify number of gains to store to DB, default is 0 - means the same as in input DB")
44 print ("-n, --nval= specify number of values to store to DB, default is 0 - means all")
45 print ("-v, --version= specify blob version, by default version from input DB is used" )
46 print ("-x, --txtfile= specify the text file with the new constants for reading")
47 print ("-m, --comment= specify comment which should be written to DB, in multi-iov mode it is appended to old comment")
48 print ("-M, --Comment= specify comment which should be written to DB, in mutli-iov mode it overwrites old comment")
49 print ("-U, --user= specify username for comment")
50 print ("-p, --prefix= specify prefix which is expected on every line in input file, default - no prefix")
51 print ("-k, --keep= field numbers or channel numbers to ignore, e.g. '0,2,3,EBch0,EBch1,EBch12,EBch13,EBspD4ch18,EBspD4ch19,EBspC10ch4,EBspC10ch5' ")
52 print ("-i, --inschema= specify name of input JSON file or CREST_SERVER_PATH")
53 print ("-o, --outschema= specify name of output JSON file, default is tileCalib.json")
54 print ("-s, --schema= the same as --o, --outschema")
55 print ("-w, --swap= specify pair of modules which will be swapped in multi-IOV update, e.g. swap=EBA61,EBA63")
56
57letters = "hr:l:R:L:b:e:AD:s:i:o:t:T:f:F:C:G:n:v:x:m:M:U:p:dcazZw:k:"
58keywords = ["help","run=","lumi=","run2=","lumi2=","begin=","end=","adjust","module=","schema=","inschema=","outschema=","tag=","outtag=","folder=","outfolder=","nchannel=","ngain=","nval=","version=","txtfile=","comment=","Comment=","user=","prefix=","default","channel","all","zero","allzero","swap=","keep="]
59
60try:
61 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
62except getopt.GetoptError as err:
63 print (str(err))
64 usage()
65 sys.exit(2)
66
67# defaults
68run = -1
69lumi = 0
70run2 = -1
71lumi2 = 0
72inSchema = 'CREST'
73outSchema = 'tileCalib.json'
74folderPath = "/TILE/OFL02/TIME/CHANNELOFFSET/GAP/LAS"
75tag = "UPD1"
76outfolderPath = None
77outtag = None
78readGain=True
79rosmin = 0
80rosmax = 5
81all=True
82zero=False
83allzero=False
84nchan = 0
85ngain = 0
86nval = 0
87blobVersion = -1
88txtFile= ""
89comment = ""
90Comment = None
91prefix = ""
92keep=[]
93iov = False
94beg = 0
95end = 2147483647
96moduleList = []
97adjust = False
98swap=[]
99modmin = 0
100modmax = 99999
101
102
103try:
104 user=os.getlogin()
105except Exception:
106 user="UnknownUser"
107
108for o, a in opts:
109 a = a.strip()
110 if o in ("-f","--folder"):
111 folderPath = a
112 elif o in ("-F","--outfolder"):
113 outfolderPath = a
114 elif o in ("-t","--tag"):
115 tag = a
116 elif o in ("-T","--outtag"):
117 outtag = a
118 elif o in ("-s","--schema"):
119 outSchema = a
120 elif o in ("-i","--inschema"):
121 inSchema = a
122 elif o in ("-o","--outschema"):
123 outSchema = a
124 elif o in ("-n","--nval"):
125 nval = int(a)
126 elif o in ("-G","--ngain"):
127 ngain = int(a)
128 elif o in ("-C","--nchannel"):
129 nchan = int(a)
130 elif o in ("-v","--version"):
131 blobVersion = int(a)
132 elif o in ("-d","--default"):
133 rosmin = 1
134 elif o in ("-c","--channel"):
135 readGain = False
136 elif o in ("-a","--all"):
137 all = False
138 elif o in ("-z","--zero"):
139 zero = True
140 elif o in ("-Z","--allzero"):
141 allzero = True
142 elif o in ("-w","--swap"):
143 swap += a.split(",")
144 elif o in ("-r","--run"):
145 run = int(a)
146 elif o in ("-l","--lumi"):
147 lumi = int(a)
148 elif o in ("-R","--run2"):
149 run2 = int(a)
150 elif o in ("-L","--lumi2"):
151 lumi2 = int(a)
152 elif o in ("-b","--begin"):
153 beg = int(a)
154 iov = True
155 elif o in ("-e","--end"):
156 end = int(a)
157 iov = True
158 elif o in ("-A","--adjust"):
159 adjust = True
160 elif o in ("-D","--module"):
161 moduleList += a.split(",")
162 elif o in ("-x","--txtfile"):
163 txtFile = a
164 elif o in ("-m","--comment"):
165 comment = a
166 elif o in ("-M","--Comment"):
167 Comment = a
168 comment = a
169 elif o in ("-U","--user"):
170 user = a
171 elif o in ("-p","--prefix"):
172 prefix = a
173 elif o in ("-k","--keep"):
174 keep = a.split(",")
175 elif o in ("-h","--help"):
176 usage()
177 sys.exit(2)
178 else:
179 raise RuntimeError("unhandeled option")
180
181moduleSwap={}
182if len(swap)>0:
183 if len(swap)!=2:
184 RuntimeError("wrong module list for swap option")
185 else:
186 from TileCalibBlobPython import TileBchCrest
187 for i in range(2):
188 m1=swap[i]
189 m2=swap[1-i]
190 moduleSwap[m1]=TileBchCrest.TileBchMgr.decodeModule(None,m2)
191else:
192 swap=False
193
194if outfolderPath is None:
195 outfolderPath=folderPath
196elif tag=='UPD5' and outfolderPath!=folderPath:
197 print ('--tag="UPD5" option is not compatible with --outfolderPath option')
198 sys.exit(2)
199if outtag is None:
200 outtag = tag
201if tag=='UPD5':
202 tag='UPD4'
203
204import cppyy
205
206from TileCalibBlobPython import TileCalibCrest
207from TileCalibBlobPython import TileCalibTools
208from TileCalibBlobObjs.Classes import TileCalibUtils, TileCalibType
209
210if iov and end >= TileCalibCrest.MAXRUN:
211 end = TileCalibCrest.MAXRUN
212 lumi2 = TileCalibCrest.MAXLBK
213until = (TileCalibCrest.MAXRUN,TileCalibCrest.MAXLBK)
214
215from TileCalibBlobPython.TileCalibLogger import getLogger
216log = getLogger("WriteCalibToCrest")
217import logging
218if iov:
219 log.setLevel(logging.INFO)
220else:
221 log.setLevel(logging.DEBUG)
222
223#=== set database
224folderTag = tag
225if folderTag.upper().startswith("TILE") or folderTag.upper().startswith("CALO"):
226 folderPath=""
227log.info("Initializing folder %s with tag %s", folderPath, folderTag)
228
229iovAll = []
230iovList = []
231iovUntil = []
232iovListMOD = []
233iovListCMT = []
234iovUntilCMT = []
235
236blobReader = TileCalibCrest.TileBlobReaderCrest(inSchema,folderPath, folderTag, None, None,
237 TileCalibUtils.getDrawerIdx(max(rosmin,0),max(modmin,0)),
238 TileCalibUtils.getDrawerIdx(min(rosmax-1,4),max(0,min(modmax-1,TileCalibUtils.getMaxDrawer(min(rosmax-1,4))-1))))
239if outtag=='UPD5':
240 folderTag = blobReader.getFolderTag(outfolderPath,None,'UPD4')
241 tag2=folderTag.split('-')
242 tag2[len(tag2)-1]="%02d"%(int(tag2[len(tag2)-1])+1)
243 outfolderTag="-".join(tag2)
244elif outtag.upper().startswith("TILE") or outtag.upper().startswith("CALO"):
245 outfolderTag = outtag
246else:
247 outfolderTag = blobReader.getFolderTag(outfolderPath,None,outtag)
248
249blobWriter2 = None
250if iov:
251 #=== filling the iovList
252 log.info( "Looking for IOVs" )
253 iovMod = blobReader.getIovs()
254 if moduleList!=['CMT']:
255 for ros in range(rosmin,5):
256 for mod in range(min(64,TileCalibUtils.getMaxDrawer(ros))):
258 if len(moduleList)>0 and modName not in moduleList and 'ALL' not in moduleList:
259 iovAll+=[[]]
260 else:
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 = iovMod
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
352else:
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.getNextRunNumber()
362 log.warning( "Run number is not specified, using next 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
383flt=None
384r=5
385d=0
386blobT=None
387while 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)
395if 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
404else:
405 mchan=-1
406 mgain=-1
407 mval=-1
408nchanDef=nchan
409ngainDef=ngain
410
411
412if blobT:
413 typeName = TileCalibType.getClassName(blobT)[-3:]
414else:
415 typeName = 'Flt'
416
417if blobWriter2:
418 blobWriter2 = TileCalibCrest.TileBlobWriterCrest(outSchema,outfolderPath,typeName)
419
420comments = []
421blobWriters = []
422nvalUpdated = []
423commentsSplit = []
424for 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 blobWriters += [TileCalibCrest.TileBlobWriterCrest(outSchema,outfolderPath,typeName)]
431log.info( "\n" )
432
433if len(txtFile)>0:
434 #=== create default: one number per ADC
435 if typeName=='Flt':
436 defConst = cppyy.gbl.std.vector('std::vector<float>')()
437 default = cppyy.gbl.std.vector('float')()
438 defVal = 0.
439 else:
440 defConst = cppyy.gbl.std.vector('std::vector<int>')()
441 default = cppyy.gbl.std.vector('int')()
442 defVal = 0
443
444 for n in range(nval if nval>0 else mval):
445 default.push_back(defVal)
446
447 for ng in range(ngain if ngain>0 else mgain):
448 defConst.push_back(default) # low/high gain
449
450 blobParser = TileCalibTools.TileASCIIParser2(txtFile,prefix,readGain)
451 mval=0
452
453 #=== loop over all IOVs
454 for io,since in enumerate(iovList):
455
456 if since==iovUntil[io]: # dummy IOV without update
457 continue
458
459 log.info( "Updating IOV %s", str(since) )
460 nold=0
461 nnew=0
462 ndef=0
463 nvold=0
464 nvnew=0
465 nvdef=0
466 nvnewdef=0
467
468 #=== loop over whole detector
469 irm=-1
470 for ros in range(rosmin,5):
471 for mod in range(min(64,TileCalibUtils.getMaxDrawer(ros))):
472 irm+=1
473 if iov and since!=begin and (since not in iovAll[irm]):
474 continue
475 modName = TileCalibUtils.getDrawerString(ros,mod)
476 if modName in ['EBA39','EBA40','EBA41','EBA42','EBA55','EBA56','EBA57','EBA58',
477 'EBC39','EBC40','EBC41','EBC42','EBC55','EBC56','EBC57','EBC58' ]:
478 modSpec = 'EBspC10'
479 elif modName in ['EBA15','EBC18']:
480 modSpec = 'EBspD4'
481 else:
482 modSpec = modName
483 newDrawer=True
484 flt1 = blobReader.getDrawer(ros, mod, since, False, False)
485 if flt1:
486 oldNchan = flt1.getNChans()
487 oldNgain = flt1.getNGains()
488 oldVsize = flt1.getObjSizeUint32()
489 else:
490 oldNchan = 0
491 oldNgain = 0
492 oldVsize = 0
493 nchan = nchanDef if nchanDef>0 else (flt1.getNChans() if flt1 else TileCalibUtils.max_chan())
494 ngain = ngainDef if ngainDef>0 else (flt1.getNGains() if flt1 else TileCalibUtils.max_gain())
495
496 (rosR,modR,modNameR) = (ros,mod,modName)
497 (rosW,modW,modNameW) = (ros,mod,modName)
498 if swap and modName in moduleSwap:
499 (rosW,modW) = moduleSwap[modName]
500 modNameW = TileCalibUtils.getDrawerString(rosW,modW)
501 log.warning("Swap: read %s write %s", modName,modNameW)
502 for chn in range(nchan):
503 #=== loop over gains
504 for adc in range(ngain):
505 data = blobParser.getData(rosR,modR,chn,adc,since)
506 if not len(data) and allzero:
507 continue
508 if not len(data) and (not all or (not flt1 and not rosmin)):
509 if not rosmin:
510 log.warning("%i/%2i/%2i/%i: No value found in file", rosR,modR,chn,adc)
511 continue
512 #=== need to invalidate previous blob in DB when reading from ASCII file
513 if newDrawer:
514 newDrawer=False
515 blobWriters[io].zeroBlob(rosW,modW)
516 #=== init drawer for first entry
517 calibDrawer = blobWriters[io].getDrawer(rosW,modW)
518 if not calibDrawer.getNObjs():
519 log.info("Initializing drawer %s", modNameW)
520 flt = blobReader.getDrawer(rosR, modR, since)
521 if nval<1:
522 mval = flt.getObjSizeUint32()
523 default.clear()
524 for n in range(mval):
525 default.push_back(defVal)
526 defConst.clear()
527 for ng in range(ngain):
528 defConst.push_back(default) # low/high gain
529 else:
530 mval = nval
531 kval = mval if mval < flt.getObjSizeUint32() else flt.getObjSizeUint32()
532 if blobVersion<0:
533 blobVersion = flt.getObjVersion()
534 calibDrawer.init(defConst,nchan,blobVersion)
535 if undo:
536 calibDrawer2 = blobWriter2.getDrawer(rosW,modW)
537 calibDrawer2.init(defConst,nchan,blobVersion)
538 for ch in range(nchan):
539 for ad in range(ngain):
540 nold+=1
541 for n in range(0,kval):
542 nvold+=1
543 val=flt.getData(ch,ad,n)
544 log.debug("%i/%2i/%2i/%i: old data[%i] = %f", rosR,modR,ch,ad, n, val)
545 calibDrawer.setData(ch,ad,n,val)
546 if undo:
547 calibDrawer2.setData(ch,ad,n,val)
548 for n in range(kval,nval):
549 nvdef+=1
550 val=calibDrawer.getData(ch,ad,n)
551 log.debug("%i/%2i/%2i/%i: def data[%i] = %f", rosR,modR,ch,ad, n, val)
552
553 if not len(data):
554 if not rosmin:
555 log.warning("%i/%2i/%2i/%i: No value found in file", rosR,modR,chn,adc)
556 continue
557 #=== loop over new data
558 if nval<1:
559 mval = flt.getObjSizeUint32()
560 else:
561 mval = nval
562 nnew+=1
563 kval=mval-len(data)
564 if kval>0:
565 if chn>=oldNchan or adc>=oldNgain:
566 ndef+=1
567 mval-=kval
568 for n in range(mval):
569 coef=None
570 strval=data[n]
571 if strval.startswith("*"):
572 coef=float(strval[1:])
573 val = calibDrawer.getData(chn,adc,n)*coef
574 log.debug("%i/%2i/%2i/%i: new data[%i] = %s scale old value by %s", rosW,modW,chn,adc, n, val, coef)
575 elif strval.startswith("++") or strval.startswith("+-") :
576 coef=float(strval[1:])
577 val = calibDrawer.getData(chn,adc,n)+coef
578 log.debug("%i/%2i/%2i/%i: new data[%i] = %s shift old value by %s", rosW,modW,chn,adc, n, val, coef)
579 elif strval=="sync":
580 val = calibDrawer.getData(chn,adc,n)
581 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
582 val = calibDrawer.getData(chn,1-adc,n)
583 elif strval=="copy":
584 val = calibDrawer.getData(chn,1-adc,n) # copy from another gain
585 elif strval=="lg" and adc==1:
586 val = calibDrawer.getData(chn,0,n) # copy from low gain
587 elif strval=="hg" and adc==0:
588 val = calibDrawer.getData(chn,1,n) # copy from high gain
589 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 \
590 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 \
591 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:
592 val = None
593 else:
594 if "x" in strval or "X" in strval:
595 val = int(strval,16)
596 elif typeName=='Flt':
597 val = float(strval)
598 else:
599 val = int(strval)
600 if val is not None:
601 nvnew+=1
602 if n>=oldVsize:
603 nvdef-=1
604 nvnewdef+=1
605 calibDrawer.setData(chn,adc,n,val)
606 if coef is None:
607 log.debug("%i/%2i/%2i/%i: new data[%i] = %s", rosW,modW,chn,adc, n, val)
608 else:
609 val = calibDrawer.getData(chn,adc,n)
610 if n>=oldVsize:
611 log.debug("%i/%2i/%2i/%i: DEF data[%i] = %s", rosW,modW,chn,adc, n, val)
612 else:
613 log.debug("%i/%2i/%2i/%i: OLD data[%i] = %s", rosW,modW,chn,adc, n, val)
614 for n in range(mval,kval+mval):
615 val = calibDrawer.getData(chn,adc,n)
616 if n>=flt.getObjSizeUint32():
617 log.debug("%i/%2i/%2i/%i: DEF data[%i] = %s", rosW,modW,chn,adc, n, val)
618 else:
619 log.debug("%i/%2i/%2i/%i: OLD data[%i] = %s", rosW,modW,chn,adc, n, val)
620 if (zero or allzero) and newDrawer:
621 blobWriters[io].zeroBlob(rosW,modW)
622 if rosW==0 and modW==0:
623 if blobVersion<0:
624 blobVersion = flt.getObjVersion()
625 calibDrawer = blobWriters[io].getDrawer(rosW,modW)
626 calibDrawer.init(defConst,1,blobVersion)
627
628 nvalUpdated[io]=nvnew
629 log.info("%d/%d old channels*gains/values have been read from database", nold,nvold)
630 log.info("%d/%d new channels*gains/values have been read from input ascii file", nnew,nvnew)
631 if nold>nnew or nvold>(nvnew-nvnewdef):
632 log.info("%d/%d old channels*gains/values remain unchanged", nold-nnew,nvold-nvnew+nvnewdef)
633 if nold<nnew or nvold<(nvnew-nvnewdef):
634 log.info("%d/%d new channels*gains/values have been added to database", nnew-nold,nvnew-nvold-nvnewdef)
635 if ndef or nvdef:
636 log.info("%d/%d new channels*gains/values with default values have been added to database", ndef,nvdef)
637
638#=== commit changes
639if (mval!=0 or Comment is not None) and (len(comment)>0 or len(txtFile)>0):
640 if not iov:
641 iovList = [begin]
642
643 #=== loop over all IOVs
644 for io,since in enumerate(iovList):
645
646 untilMod = iovUntil[io]
647 untilCmt = iovUntilCMT[io]
648 appendCmt = (untilCmt < (TileCalibCrest.MAXRUN,TileCalibCrest.MAXLBK)) or iov
649
650 if since==untilMod: # empty IOV
651 if since==untilCmt:
652 continue # nothing to do
653 undoCmt = True # only comments with UNDO text will be written
654 else:
655 undoCmt = False
656 if len(moduleList)!=1:
657 untilMod = until # more than one module updated
658 untilCmt = until # will use IOV till very end
659 elif untilCmt>untilMod:
660 untilCmt = untilMod
661
662 if iov:
663 log.info( "Updating IOV %s => %s => %s", str(io), str(since), comments[io] )
664 else:
665 log.info( "Updating IOV %s", str(since) )
666
667 #=== set comment
668 if Comment is not None:
669 comm = Comment
670 if undoCmt:
671 comm = "UNDO " + comm
672 author = user
673 else:
674 if (comment is None) or (comment == "None"):
675 comm = "None"
676 author = "None"
677 elif comment == "keep":
678 comm = comments[io]
679 author = commentsSplit[io]
680 else:
681 if len(comment)==0:
682 if undoCmt:
683 if since[1]==0 and begin[1]==0:
684 comm="Update for run %i - undoing changes done for run %i from file %s" % (since[0],begin[0],txtFile)
685 else:
686 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)
687 else:
688 if since[1]==0:
689 comm="Update for run %i from file %s" % (since[0],txtFile)
690 else:
691 comm="Update for run,lumi %i,%i from file %s" % (since[0],since[1],txtFile)
692 else:
693 comm = comment
694 if undoCmt:
695 comm = "UNDO " + comm
696 if (iov and appendCmt) or (not iov and adjust):
697 comm += " // " + comments[io]
698 if not undoCmt and iov and nvalUpdated[io]==0:
699 author = commentsSplit[io]
700 else:
701 author = user
702 blobWriters[io].setComment(author,comm)
703
704 #=== commit changes
705 if untilCmt!=untilMod:
706 cmtOnly = (since in iovListCMT and since not in iovListMOD)
707 if not cmtOnly and untilMod>since:
708 blobWriters[io].register(since,outfolderTag)
709 if untilCmt>since:
710 blobWriters[io].register(since,outfolderTag)
711 else:
712 blobWriters[io].register(since,outfolderTag)
713
714 if undo:
715 if (comment is None) or (comment == "None"):
716 blobWriter2.setComment("None","None")
717 else:
718 if run2>begin[0] and lumi2==0 and begin[1]==0:
719 comment="Update for run %i - undoing changes done for run %i from file %s" % (run2,begin[0],txtFile)
720 else:
721 comment="Update for run,lumi %i,%i - undoing changes done for %i,%i from file %s" % (run2,lumi2,begin[0],begin[1],txtFile)
722 blobWriter2.setComment(user,comment)
723 blobWriter2.register((run2,lumi2), outfolderTag)
724 elif run2>=0 and (run2<begin[0] or (run2==begin[0] and lumi2<begin[1]) and lumi2!=0):
725 log.warning("(run2,lumi2)=(%i,%i) is smaller than (run,lumi)=(%i,%i) - will not create second IOV", run2,lumi2,begin[0],begin[1])
726else:
727 log.warning("Nothing to update")
728
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
static std::string getClassName(TileCalibType::TYPE type)
Returns the class name.
static unsigned int max_gain()
Python compatibility function.
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static unsigned int max_chan()
Python compatibility function.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
STL class.