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