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-2025 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
225log.info("Initializing folder %s with tag %s", folderPath, folderTag)
226
227iovAll = []
228iovList = []
229iovUntil = []
230iovListMOD = []
231iovListCMT = []
232iovUntilCMT = []
233
234inRun=run
235inLumi=lumi
236if inRun<0:
237 if "UPD4" in outtag:
238 inRun=TileCalibTools.getPromptCalibRunNumber()
239 else:
240 inRun=TileCalibTools.getLastRunNumber()
241 if inRun<0:
242 log.error( "Bad run number" )
243 sys.exit(2)
244blobReader = TileCalibCrest.TileBlobReaderCrest(inSchema,folderPath, folderTag, inRun, inLumi,
245 TileCalibUtils.getDrawerIdx(max(rosmin,0),max(modmin,0)),
246 TileCalibUtils.getDrawerIdx(min(rosmax-1,4),max(0,min(modmax-1,TileCalibUtils.getMaxDrawer(min(rosmax-1,4))-1))))
247if outtag=='UPD5':
248 folderTag = blobReader.getFolderTag(outfolderPath,None,'UPD4')
249 tag2=folderTag.split('-')
250 tag2[len(tag2)-1]="%02d"%(int(tag2[len(tag2)-1])+1)
251 outfolderTag="-".join(tag2)
252else:
253 outfolderTag = blobReader.getFolderTag(outfolderPath,None,outtag)
254
255blobWriter2 = None
256if iov:
257 #=== filling the iovList
258 log.info( "Looking for IOVs" )
259 iovMod = blobReader.getIovs()
260 if moduleList!=['CMT']:
261 for ros in range(rosmin,5):
262 for mod in range(min(64,TileCalibUtils.getMaxDrawer(ros))):
264 if len(moduleList)>0 and modName not in moduleList and 'ALL' not in moduleList:
265 iovAll+=[[]]
266 else:
267 iovAll+=[iovMod]
268 iovList+=iovMod
269 if 'ALL' in moduleList:
270 moduleList.remove('ALL')
271 else:
272 for ros in range(rosmin,5):
273 iovAll+=[[]]*min(64,TileCalibUtils.getMaxDrawer(ros))
274 if 'CMT' in moduleList:
275 iovListMOD = iovList
276 iovListCMT = iovMod
277 if len(iovList)==0:
278 iovList = iovListCMT
279 iovAll+=[iovListCMT]
280 else:
281 moduleList.remove('CMT')
282
283 import functools
284 def compare(item1,item2):
285 if item1[0]!=item2[0]:
286 return item1[0]-item2[0]
287 else:
288 return item1[1]-item2[1]
289 iovList=list(set(iovList))
290 iovList=sorted(iovList,key=functools.cmp_to_key(compare))
291 iovList+=[until]
292 iovListCMT+=[until]
293
294 since=(beg,lumi)
295 ib=bisect.bisect(iovList,since)-1
296 if ib<0:
297 ib=0
298 if iovList[ib] != since:
299 if adjust:
300 since = iovList[ib]
301 log.info( "Moving beginning of first IOV with new constants from (%d,%d) to (%d,%d)", beg,lumi,since[0],since[1])
302 else:
303 iovList[ib] = since
304 log.info( "Creating new IOV starting from (%d,%d) with new constants", beg,lumi)
305
306 if end<0:
307 ie=ib+1
308 if ie>=len(iovList):
309 ie=ib
310 until=iovList[ie]
311 log.info( "Next IOV without new constants starts from (%d,%d)", until[0],until[1])
312 else:
313 until=(end,lumi2)
314 ie=bisect.bisect_left(iovList,until)
315 if ie>=len(iovList):
316 ie=len(iovList)-1
317
318 if iovList[ie] != until:
319 if adjust:
320 until=iovList[ie]
321 log.info( "Moving end of last IOV from (%d,%d) to (%d,%d)", end,lumi2,until[0],until[1])
322 else:
323 log.info( "Keeping end of last IOV at (%d,%d) - new IOV is shorter than IOV in input DB", end,lumi2)
324 iovList[ie] = until
325
326
327 iovList = iovList[ib:ie]
328 iovUntil = iovList[1:] + [until]
329 begin = since
330 run = since[0]
331 lumi = since[1]
332 undo = False
333 log.info( "IOVs: %s", str(iovList))
334
335 if len(iovListMOD)>0 and len(iovListCMT)>0:
336 if Comment is None:
337 iovList += [until] # one more IOV for "UNDO" comment
338 iovUntil += [until] # one more IOV for "UNDO" comment
339 iovUntilCMT = []
340 for io,since in enumerate(iovList):
341 p = bisect.bisect(iovListCMT,since)
342 if p<len(iovListCMT):
343 iovUntilCMT += [iovListCMT[p]]
344 if iovUntil[io] != iovListCMT[p]:
345 log.info( "End of iov %s in comments record is %s", str(since),str(iovListCMT[p]))
346 else:
347 if since!=until:
348 iovUntilCMT += [since]
349 else:
350 iovList.pop(-1)
351 break
352 since = begin
353 else:
354 iovUntilCMT = iovUntil
355
356 log.info( "%d IOVs in total, end of last IOV is %s", ie-ib,str(until))
357
358else:
359 #=== set run number
360 if run==0:
361 begin=(0,0)
362 if run<=0:
363 if "UPD4" in outtag:
364 run=TileCalibTools.getPromptCalibRunNumber()
365 log.warning( "Run number is not specified, using minimal run number in calibration loop %d", run )
366 else:
367 run=TileCalibTools.getLastRunNumber()
368 log.warning( "Run number is not specified, using current run number %d", run )
369 if run<0:
370 log.error( "Bad run number" )
371 sys.exit(2)
372
373 since = (run, lumi)
374 iovList = [since]
375 iovUntil = [until]
376 iovUntilCMT = [until]
377 if "begin" not in dir():
378 begin=since
379 if run2<0:
380 run2=begin[0]
381 if run2>begin[0] or (run2==begin[0] and lumi2>begin[1]):
382 undo=True
383 blobWriter2 = True
384 else:
385 undo=False
386
387 log.info("Initializing for run %d, lumiblock %d", run,lumi)
388
389flt=None
390r=5
391d=0
392blobT=None
393while not flt:
394 d-=1
395 if d<0:
396 r-=1
397 if r<0:
398 break
400 flt = blobReader.getDrawer(r, d, since, False, False)
401if flt:
402 blobT=flt.getObjType()
403 blobV=flt.getObjVersion()
404 mchan=flt.getNChans()
405 mgain=flt.getNGains()
406 mval=flt.getObjSizeUint32()
407 log.info( "Blob type: %d version: %d Nchannels: %d Ngains: %d Nval: %d", blobT,blobV,mchan,mgain,mval)
408 if blobVersion<0:
409 blobVersion = blobV
410else:
411 mchan=-1
412 mgain=-1
413 mval=-1
414nchanDef=nchan
415ngainDef=ngain
416
417
418if blobT:
419 typeName = TileCalibType.getClassName(blobT)[-3:]
420else:
421 typeName = 'Flt'
422
423if blobWriter2:
424 blobWriter2 = TileCalibCrest.TileBlobWriterCrest(outSchema,outfolderPath,typeName)
425
426comments = []
427blobWriters = []
428nvalUpdated = []
429commentsSplit = []
430for since in iovList:
431 comm=blobReader.getComment(since)
432 log.info("Comment: %s", comm)
433 comments+=[comm]
434 nvalUpdated += [0]
435 #commentsSplit+=[blobReader.getComment(since,True)]
436 commentsSplit+=[blobReader.getComment(since)]
437 blobWriters += [TileCalibCrest.TileBlobWriterCrest(outSchema,outfolderPath,typeName)]
438log.info( "\n" )
439
440if len(txtFile)>0:
441 #=== create default: one number per ADC
442 if typeName=='Flt':
443 defConst = cppyy.gbl.std.vector('std::vector<float>')()
444 default = cppyy.gbl.std.vector('float')()
445 defVal = 0.
446 else:
447 defConst = cppyy.gbl.std.vector('std::vector<int>')()
448 default = cppyy.gbl.std.vector('int')()
449 defVal = 0
450
451 for n in range(nval if nval>0 else mval):
452 default.push_back(defVal)
453
454 for ng in range(ngain if ngain>0 else mgain):
455 defConst.push_back(default) # low/high gain
456
457 blobParser = TileCalibTools.TileASCIIParser2(txtFile,prefix,readGain)
458 mval=0
459
460 #=== loop over all IOVs
461 for io,since in enumerate(iovList):
462
463 if since==iovUntil[io]: # dummy IOV without update
464 continue
465
466 log.info( "Updating IOV %s", str(since) )
467 nold=0
468 nnew=0
469 ndef=0
470 nvold=0
471 nvnew=0
472 nvdef=0
473 nvnewdef=0
474
475 #=== loop over whole detector
476 irm=-1
477 for ros in range(rosmin,5):
478 for mod in range(min(64,TileCalibUtils.getMaxDrawer(ros))):
479 irm+=1
480 if iov and since!=begin and (since not in iovAll[irm]):
481 continue
482 modName = TileCalibUtils.getDrawerString(ros,mod)
483 if modName in ['EBA39','EBA40','EBA41','EBA42','EBA55','EBA56','EBA57','EBA58',
484 'EBC39','EBC40','EBC41','EBC42','EBC55','EBC56','EBC57','EBC58' ]:
485 modSpec = 'EBspC10'
486 elif modName in ['EBA15','EBC18']:
487 modSpec = 'EBspD4'
488 elif modName in ['EBC29','EBC32','EBC34','EBC37']:
489 modSpec = 'EBspE4'
490 elif modName in ['EBA07', 'EBA25', 'EBA44', 'EBA53',
491 'EBC07', 'EBC25', 'EBC44', 'EBC53',
492 'EBC28', 'EBC31', 'EBC35', 'EBC38' ]:
493 modSpec = 'EBspE1'
494 elif modName in ['EBA08', 'EBA24', 'EBA43', 'EBA54',
495 'EBC08', 'EBC24', 'EBC43', 'EBC54' ]:
496 modSpec = 'EBMBTS'
497 else:
498 modSpec = modName
499 newDrawer=True
500 flt1 = blobReader.getDrawer(ros, mod, since, False, False)
501 if flt1:
502 oldNchan = flt1.getNChans()
503 oldNgain = flt1.getNGains()
504 oldVsize = flt1.getObjSizeUint32()
505 else:
506 oldNchan = 0
507 oldNgain = 0
508 oldVsize = 0
509 nchan = nchanDef if nchanDef>0 else (flt1.getNChans() if flt1 else TileCalibUtils.max_chan())
510 ngain = ngainDef if ngainDef>0 else (flt1.getNGains() if flt1 else TileCalibUtils.max_gain())
511
512 (rosR,modR,modNameR) = (ros,mod,modName)
513 (rosW,modW,modNameW) = (ros,mod,modName)
514 if swap and modName in moduleSwap:
515 (rosW,modW) = moduleSwap[modName]
516 modNameW = TileCalibUtils.getDrawerString(rosW,modW)
517 log.warning("Swap: read %s write %s", modName,modNameW)
518 for chn in range(nchan):
519 #=== loop over gains
520 for adc in range(ngain):
521 data = blobParser.getData(rosR,modR,chn,adc,since)
522 if not len(data) and allzero:
523 continue
524 if not len(data) and (not all or (not flt1 and not rosmin)):
525 if not rosmin:
526 log.warning("%i/%2i/%2i/%i: No value found in file", rosR,modR,chn,adc)
527 continue
528 #=== need to invalidate previous blob in DB when reading from ASCII file
529 if newDrawer:
530 newDrawer=False
531 blobWriters[io].zeroBlob(rosW,modW)
532 #=== init drawer for first entry
533 calibDrawer = blobWriters[io].getDrawer(rosW,modW)
534 if not calibDrawer.getNObjs():
535 log.info("Initializing drawer %s", modNameW)
536 flt = blobReader.getDrawer(rosR, modR, since)
537 if nval<1:
538 mval = flt.getObjSizeUint32()
539 default.clear()
540 for n in range(mval):
541 default.push_back(defVal)
542 defConst.clear()
543 for ng in range(ngain):
544 defConst.push_back(default) # low/high gain
545 else:
546 mval = nval
547 kval = mval if mval < flt.getObjSizeUint32() else flt.getObjSizeUint32()
548 if blobVersion<0:
549 blobVersion = flt.getObjVersion()
550 calibDrawer.init(defConst,nchan,blobVersion)
551 if undo:
552 calibDrawer2 = blobWriter2.getDrawer(rosW,modW)
553 calibDrawer2.init(defConst,nchan,blobVersion)
554 for ch in range(nchan):
555 for ad in range(ngain):
556 nold+=1
557 for n in range(0,kval):
558 nvold+=1
559 val=flt.getData(ch,ad,n)
560 log.debug("%i/%2i/%2i/%i: old data[%i] = %f", rosR,modR,ch,ad, n, val)
561 calibDrawer.setData(ch,ad,n,val)
562 if undo:
563 calibDrawer2.setData(ch,ad,n,val)
564 for n in range(kval,nval):
565 nvdef+=1
566 val=calibDrawer.getData(ch,ad,n)
567 log.debug("%i/%2i/%2i/%i: def data[%i] = %f", rosR,modR,ch,ad, n, val)
568
569 if not len(data):
570 if not rosmin:
571 log.warning("%i/%2i/%2i/%i: No value found in file", rosR,modR,chn,adc)
572 continue
573 #=== loop over new data
574 if nval<1:
575 mval = flt.getObjSizeUint32()
576 else:
577 mval = nval
578 nnew+=1
579 kval=mval-len(data)
580 if kval>0:
581 if chn>=oldNchan or adc>=oldNgain:
582 ndef+=1
583 mval-=kval
584 for n in range(mval):
585 coef=None
586 strval=data[n]
587 if strval.startswith("*"):
588 coef=float(strval[1:])
589 val = calibDrawer.getData(chn,adc,n)*coef
590 log.debug("%i/%2i/%2i/%i: new data[%i] = %s scale old value by %s", rosW,modW,chn,adc, n, val, coef)
591 elif strval.startswith("++") or strval.startswith("+-") :
592 coef=float(strval[1:])
593 val = calibDrawer.getData(chn,adc,n)+coef
594 log.debug("%i/%2i/%2i/%i: new data[%i] = %s shift old value by %s", rosW,modW,chn,adc, n, val, coef)
595 elif strval=="sync":
596 val = calibDrawer.getData(chn,adc,n)
597 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
598 val = calibDrawer.getData(chn,1-adc,n)
599 elif strval=="copy":
600 val = calibDrawer.getData(chn,1-adc,n) # copy from another gain
601 elif strval=="lg" and adc==1:
602 val = calibDrawer.getData(chn,0,n) # copy from low gain
603 elif strval=="hg" and adc==0:
604 val = calibDrawer.getData(chn,1,n) # copy from high gain
605 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 \
606 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 \
607 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:
608 val = None
609 else:
610 if "x" in strval or "X" in strval:
611 val = int(strval,16)
612 elif typeName=='Flt':
613 val = float(strval)
614 else:
615 val = int(strval)
616 if val is not None:
617 nvnew+=1
618 if n>=oldVsize:
619 nvdef-=1
620 nvnewdef+=1
621 calibDrawer.setData(chn,adc,n,val)
622 if coef is None:
623 log.debug("%i/%2i/%2i/%i: new data[%i] = %s", rosW,modW,chn,adc, n, val)
624 else:
625 val = calibDrawer.getData(chn,adc,n)
626 if n>=oldVsize:
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 for n in range(mval,kval+mval):
631 val = calibDrawer.getData(chn,adc,n)
632 if n>=flt.getObjSizeUint32():
633 log.debug("%i/%2i/%2i/%i: DEF data[%i] = %s", rosW,modW,chn,adc, n, val)
634 else:
635 log.debug("%i/%2i/%2i/%i: OLD data[%i] = %s", rosW,modW,chn,adc, n, val)
636 if (zero or allzero) and newDrawer:
637 blobWriters[io].zeroBlob(rosW,modW)
638 if rosW==0 and modW==0:
639 if blobVersion<0:
640 blobVersion = flt.getObjVersion()
641 calibDrawer = blobWriters[io].getDrawer(rosW,modW)
642 calibDrawer.init(defConst,1,blobVersion)
643
644 nvalUpdated[io]=nvnew
645 log.info("%d/%d old channels*gains/values have been read from database", nold,nvold)
646 log.info("%d/%d new channels*gains/values have been read from input ascii file", nnew,nvnew)
647 if nold>nnew or nvold>(nvnew-nvnewdef):
648 log.info("%d/%d old channels*gains/values remain unchanged", nold-nnew,nvold-nvnew+nvnewdef)
649 if nold<nnew or nvold<(nvnew-nvnewdef):
650 log.info("%d/%d new channels*gains/values have been added to database", nnew-nold,nvnew-nvold-nvnewdef)
651 if ndef or nvdef:
652 log.info("%d/%d new channels*gains/values with default values have been added to database", ndef,nvdef)
653
654#=== commit changes
655if (mval!=0 or Comment is not None) and (len(comment)>0 or len(txtFile)>0):
656 if not iov:
657 iovList = [begin]
658
659 #=== loop over all IOVs
660 for io,since in enumerate(iovList):
661
662 untilMod = iovUntil[io]
663 untilCmt = iovUntilCMT[io]
664 appendCmt = (untilCmt < (TileCalibCrest.MAXRUN,TileCalibCrest.MAXLBK)) or iov
665
666 if since==untilMod: # empty IOV
667 if since==untilCmt:
668 continue # nothing to do
669 undoCmt = True # only comments with UNDO text will be written
670 else:
671 undoCmt = False
672 if len(moduleList)!=1:
673 untilMod = until # more than one module updated
674 untilCmt = until # will use IOV till very end
675 elif untilCmt>untilMod:
676 untilCmt = untilMod
677
678 if iov:
679 log.info( "Updating IOV %s => %s => %s", str(io), str(since), comments[io] )
680 else:
681 log.info( "Updating IOV %s", str(since) )
682
683 #=== set comment
684 if Comment is not None:
685 comm = Comment
686 if undoCmt:
687 comm = "UNDO " + comm
688 author = user
689 else:
690 if (comment is None) or (comment == "None"):
691 comm = "None"
692 author = "None"
693 else:
694 if len(comment)==0:
695 if undoCmt:
696 if since[1]==0 and begin[1]==0:
697 comm="Update for run %i - undoing changes done for run %i from file %s" % (since[0],begin[0],txtFile)
698 else:
699 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)
700 else:
701 if since[1]==0:
702 comm="Update for run %i from file %s" % (since[0],txtFile)
703 else:
704 comm="Update for run,lumi %i,%i from file %s" % (since[0],since[1],txtFile)
705 else:
706 comm = comment
707 if undoCmt:
708 comm = "UNDO " + comm
709 if iov and appendCmt:
710 comm += " // " + comments[io]
711 if not undoCmt and iov and (nvalUpdated[io]==0 or comment=="keep"):
712 author = commentsSplit[io]
713 else:
714 author = user
715 blobWriters[io].setComment(author,comm)
716
717 #=== commit changes
718 if untilCmt!=untilMod:
719 cmtOnly = (since in iovListCMT and since not in iovListMOD)
720 if not cmtOnly and untilMod>since:
721 blobWriters[io].register(since,outfolderTag)
722 if untilCmt>since:
723 blobWriters[io].register(since,outfolderTag)
724 else:
725 blobWriters[io].register(since,outfolderTag)
726
727 if undo:
728 if (comment is None) or (comment == "None"):
729 blobWriter2.setComment("None","None")
730 else:
731 if run2>begin[0] and lumi2==0 and begin[1]==0:
732 comment="Update for run %i - undoing changes done for run %i from file %s" % (run2,begin[0],txtFile)
733 else:
734 comment="Update for run,lumi %i,%i - undoing changes done for %i,%i from file %s" % (run2,lumi2,begin[0],begin[1],txtFile)
735 blobWriter2.setComment(user,comment)
736 blobWriter2.register((run2,lumi2), outfolderTag)
737 elif run2>=0 and (run2<begin[0] or (run2==begin[0] and lumi2<begin[1]) and lumi2!=0):
738 log.warning("(run2,lumi2)=(%i,%i) is smaller than (run,lumi)=(%i,%i) - will not create second IOV", run2,lumi2,begin[0],begin[1])
739else:
740 log.warning("Nothing to update")
741
#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.