3 from __future__
import print_function
5 from AthenaPython.PyAthena
import StatusCode
7 from PyCool
import cool
9 import LArBadChannelBrowserTools
21 STATUS_NOT_MISSING_FEB=
"0K"
22 STATUS_MISSING_FEB=
"missing"
26 def __init__(self,nspace_LArBadChannelDBTools,class_LArBadChanBitPacking,class_LArBadChannel,class_HWIdentifier,onLineID,larCablingSvc):
45 channelSize=payload[
'ChannelSize']
46 endianness=payload[
'Endianness']
47 version=payload[
'Version']
55 print (vect_MissingFebHWid.size())
56 for s
in vect_MissingFebHWid:
70 for key
in sChannelDict.keys():
87 for sHWid
in listHWidKeys:
108 barrel_ec=self.
onlineID.barrel_ec(obj_HWid)
109 pos_neg=self.
onlineID.pos_neg(obj_HWid)
110 feedthrough=self.
onlineID.feedthrough(obj_HWid)
115 print (
" %5d : %-10s %1d %1d %2d %2d %3d %40s %s " % (iChanCmpt+1,obj_HWid.getString(),
116 barrel_ec,pos_neg,feedthrough,slot,channel,
117 sChanName,sStatusValue))
119 print (
"%3s %5d : %-10s %1d %1d %2d %2d %3d %40s %s %s" % (sMessage,iChanCmpt+1,obj_HWid.getString(),
120 barrel_ec,pos_neg,feedthrough,slot,channel,
121 sChanName,sStatusValue,sValueInit))
129 print (
"Correction summary : ")
131 for index,sHWid
in enumerate(listHWidKeys):
143 """ Transform the missing FEB decoded from blob object into a python dictionnary """
145 print (
"--------------------------- Blob SIZE : ",vMissingFEBHWid.size())
146 iNbMissingFEB=vMissingFEBHWid.size()
149 sChannelDict_Status={}
150 for i
in range(0,iNbMissingFEB):
152 obj_HWid=vMissingFEBHWid.at(i)
153 sHexaString=obj_HWid.getString()
155 sChannelName=self.
onlineID.channel_name(vMissingFEBHWid.at(i))
156 sInitialValues=sHexaString+
" "+STATUS_MISSING_FEB
157 sChannelDict[sHexaString]=(sChannelName,STATUS_MISSING_FEB,sInitialValues)
158 sChannelDict_Status[sHexaString]=STATUS_INIT
160 return (sChannelDict,sChannelDict_Status)
170 bEndOfCorrection=
False
171 while not bEndOfCorrection:
174 print (
".. To add a missing feb : enter barrel_ec pos_neg feedthrough slot ")
175 print (
".. To remove a missing feb : enter -(channel index) ")
176 print (
".. Other : s (summary) / r (refresh list) / a (abort) / q (save and quit) .. > ",)
177 tty =
open(
"/dev/tty",
"r+")
191 barrel_ec,pos_neg,feedthrough,slot=rep.split(
' ')
203 sTxtAnswer=
"save-quit"
207 if iSelection
in range(1,iNbBadChannel+1):
208 iSelectedIndex=iSelection
209 if iSelection
in range(-iNbBadChannel-1,0):
210 iSelectedIndex=iSelection
211 if iSelectedIndex==-99999:
212 bReadableAnswer=
False
215 bReadableAnswer=
False
218 if bReadableAnswer
is False:
219 print (
"could not decode answer... ")
220 bEndOfCorrection=
False
224 if sTxtAnswer==
"abort":
225 iAbortConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to quit ? ")
226 if iAbortConfirmation==1:
228 bEndOfCorrection=
False
231 if sTxtAnswer==
"refresh":
233 bEndOfCorrection=
False
236 if sTxtAnswer==
"summary":
238 bEndOfCorrection=
False
241 if sTxtAnswer==
"save-quit":
247 sHWid=listHWidKeys[-iSelectedIndex-1]
249 iDeleteConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to delete "+sChanName+
" ? ")
250 if iDeleteConfirmation==1:
253 bEndOfCorrection=
False
256 if iSelectedIndex>0
or iCombinationAnswer==1:
259 sHWid=listHWidKeys[iSelectedIndex-1]
264 print (
"FEB already defined as missing")
270 bEndOfCorrection=
False
276 return StatusCode.Success
280 """ Get channel HW identifier and its status """
283 print (
str(barrel_ec)+
" "+
str(pos_neg)+
" "+
str(feedthrough)+
" "+
str(slot)+
" "+
str(channel)+
" => ",sid.getString())
286 bValidWHidentifier=
False
288 bValidWHidentifier=
True
289 if self.
onlineID.isEMECchannel(sid):
290 bValidWHidentifier=
True
292 bValidWHidentifier=
True
293 if self.
onlineID.isFCALchannel(sid):
294 bValidWHidentifier=
True
295 if bValidWHidentifier
is False:
296 return (-1,sid.getString(),
"",0)
301 if sid.getString()==sHWid:
302 return (0,sid.getString(),sChannelName,sFebStatus)
304 return (1,sid.getString(),sChannelName,STATUS_MISSING_FEB)
315 vect_MissingFebHWid=cppyy.gbl.std.vector(
'HWIdentifier')()
321 for key
in listHWidKeys:
338 vect_MissingFebHWid.push_back(obj_HWid)
344 print (
"No correcton to save")
348 attrListSpec=cppyy.gbl.coral.AttributeListSpecification()
349 athenaAttrList=cppyy.gbl.AthenaAttributeList()
356 dbSave = dbSvc.createDatabase(dbstring)
357 except Exception
as e:
358 print (
'Problem opening database',e)
360 print (
"Opened database",dbstring)
362 desc=
'<timeStamp>run-event</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>'
365 coolSpec=cool.RecordSpecification()
366 for iElemt
in range(0,attrListSpec.size()):
367 attrSpec=attrListSpec[iElemt]
368 typeName=attrSpec.typeName()
369 if typeName==
"unsigned int":
370 coolSpec.extend(attrSpec.name(),cool.StorageType.UInt32)
371 elif typeName==
"blob":
372 coolSpec.extend(attrSpec.name(),cool.StorageType.Blob64k)
374 print (
"Undefined cool.StorageType "+typeName)
376 myfolder=dbSave.createFolder(dbFolderName, coolSpec, desc, cool.FolderVersioning.MULTI_VERSION,
True)
379 IOVBeginEnd=[
"90",
"9999999"]
380 beginRun = string.atoi(IOVBeginEnd[0]) << 32
381 endRun = string.atoi(IOVBeginEnd[1]) << 32
384 coolPayload=cool.Record(coolSpec)
385 for iElemt
in range(0,attrListSpec.size()):
386 attrSpec=attrListSpec[iElemt]
387 coolPayload[attrSpec.name()]=athenaAttrList[attrSpec.name()]
390 myfolder.storeObject(beginRun,endRun,coolPayload,coolChan,selectedTag)
393 dbSave.closeDatabase()
401 dbase = dbSvc.openDatabase(dbName,
False)
402 except Exception
as e:
403 print (
'Problem opening database',e)
405 print (
"Opened database",dbName)
409 f = dbase.getFolder(dbFolderName)
410 print (
"Analysing Folder " +
str(dbFolderName))
412 print (
"Skipping " +
str(dbFolderName))
420 tags.push_back(
"notag")
422 print (
"for tags ", end=
'')
427 bSavingProcessError=
False
436 f.countObjects( cool.ValidityKeyMin,cool.ValidityKeyMax,cool.ChannelSelection.all())
437 objs = f.browseObjects( cool.ValidityKeyMin,cool.ValidityKeyMax,cool.ChannelSelection.all())
439 while objs.hasNext():
441 print (
"Found object", i, end=
'')
442 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
443 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
444 print (
"payload", obj.payload(), end=
'')
445 print (
"chan",obj.channelId() )
448 payload=obj.payload()
449 channelSize=payload[
'ChannelSize']
450 endianness=payload[
'Endianness']
451 version=payload[
'Version']
462 sChannelKey=obj.channelId()
464 for key
in sChannelDict.keys():
467 print (
" -> SQlite database content vs initial data : channel ", sChannelKey)
470 listHWidKeys=[x
for x
in sChannelDict.keys()]
472 if x
not in listHWidKeys:
473 listHWidKeys.append(x)
476 for keyHWid
in listHWidKeys:
479 sChanName,sFebStatus,sValueInit=sChannelDict[keyHWid]
481 sChanName=
"UNDEFINED"
488 sSuffix=
" no modification was done"+keyHWid
489 bSavingProcessError=
True
495 if keyHWid
in sChannelDict:
497 sSuffix=
" deletion not taken into accout"+keyHWid
498 bSavingProcessError=
True
500 sPrefix=STATUS_REMOVED
507 sSuffix=
" error while saving new status "+keyHWid
508 bSavingProcessError=
True
516 sSuffix=
" error while saving modified status "+keyHWid
517 bSavingProcessError=
True
519 sPrefix=STATUS_MODIFIED
522 HWidChecked[keyHWid]=1
527 print (
"ERROR : initial ",key,
" has not been saved")
528 elif key
in HWidChecked
and HWidChecked[key]==0:
529 print (
"ERROR : ",key,
" has not been checked")
536 if bTagFound
is False:
537 print (
"ERROR : tag "+selectedTag+
" not found in saved SQlite file")
539 if bSavingProcessError
is True:
540 print (
"ERROR : found while making comparison between corrected and saved datas" )
543 dbase.closeDatabase()