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