4 from AthenaPython.PyAthena 
import StatusCode
 
    6 from PyCool 
import cool
 
    8 import LArBadChannelBrowserTools
 
   20 STATUS_NOT_MISSING_FEB=
"0K" 
   21 STATUS_MISSING_FEB=
"missing" 
   25     def __init__(self,nspace_LArBadChannelDBTools,class_LArBadChanBitPacking,class_LArBadChannel,class_HWIdentifier,onLineID,larCablingSvc):
 
   44         channelSize=payload[
'ChannelSize']
 
   45         endianness=payload[
'Endianness']
 
   46         version=payload[
'Version']
 
   54         print (vect_MissingFebHWid.size())
 
   55         for s 
in vect_MissingFebHWid:
 
   69         for key 
in sChannelDict.keys():
 
   86         for sHWid 
in listHWidKeys:
 
  107         barrel_ec=self.
onlineID.barrel_ec(obj_HWid)
 
  108         pos_neg=self.
onlineID.pos_neg(obj_HWid)
 
  109         feedthrough=self.
onlineID.feedthrough(obj_HWid)
 
  114             print (
"    %5d :  %-10s  %1d %1d %2d %2d %3d %40s   %s " % (iChanCmpt+1,obj_HWid.getString(),
 
  115                                                                     barrel_ec,pos_neg,feedthrough,slot,channel,
 
  116                                                                     sChanName,sStatusValue))
 
  118             print (
"%3s %5d :  %-10s  %1d %1d %2d %2d %3d %40s   %s %s" % (sMessage,iChanCmpt+1,obj_HWid.getString(),
 
  119                                                                         barrel_ec,pos_neg,feedthrough,slot,channel,
 
  120                                                                         sChanName,sStatusValue,sValueInit))
 
  128         print (
"Correction summary : ")
 
  130         for index,sHWid 
in enumerate(listHWidKeys):
 
  142         """ Transform the missing FEB decoded from blob object into a python dictionnary """ 
  144         print (
"--------------------------- Blob SIZE : ",vMissingFEBHWid.size())
 
  145         iNbMissingFEB=vMissingFEBHWid.size()
 
  148         sChannelDict_Status={}
 
  149         for i 
in range(0,iNbMissingFEB):
 
  151             obj_HWid=vMissingFEBHWid.at(i)
 
  152             sHexaString=obj_HWid.getString()
 
  154             sChannelName=self.
onlineID.channel_name(vMissingFEBHWid.at(i))
 
  155             sInitialValues=sHexaString+
" "+STATUS_MISSING_FEB
 
  156             sChannelDict[sHexaString]=(sChannelName,STATUS_MISSING_FEB,sInitialValues)
 
  157             sChannelDict_Status[sHexaString]=STATUS_INIT
 
  159         return (sChannelDict,sChannelDict_Status)
 
  169         bEndOfCorrection=
False 
  170         while not bEndOfCorrection:
 
  173             print (
".. To add a missing feb    : enter barrel_ec pos_neg feedthrough slot ")
 
  174             print (
".. To remove a missing feb : enter -(channel index) ")
 
  175             print (
".. Other :   s (summary)  /  r (refresh list)  /  a (abort)  / q (save and quit)      .. > ",)
 
  176             tty = 
open(
"/dev/tty", 
"r+")
 
  190                 barrel_ec,pos_neg,feedthrough,slot=rep.split(
' ')
 
  202                     sTxtAnswer=
"save-quit" 
  206                         if iSelection 
in range(1,iNbBadChannel+1):
 
  207                             iSelectedIndex=iSelection
 
  208                         if iSelection 
in range(-iNbBadChannel-1,0):
 
  209                             iSelectedIndex=iSelection
 
  210                         if iSelectedIndex==-99999:
 
  211                             bReadableAnswer=
False 
  214                         bReadableAnswer=
False 
  217             if bReadableAnswer 
is False:
 
  218                 print (
"could not decode answer... ")
 
  219                 bEndOfCorrection=
False 
  223             if sTxtAnswer==
"abort":
 
  224                 iAbortConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to quit ? ")
 
  225                 if iAbortConfirmation==1:
 
  227                 bEndOfCorrection=
False 
  230             if sTxtAnswer==
"refresh":
 
  232                 bEndOfCorrection=
False 
  235             if sTxtAnswer==
"summary":
 
  237                 bEndOfCorrection=
False 
  240             if sTxtAnswer==
"save-quit":
 
  246                 sHWid=listHWidKeys[-iSelectedIndex-1]
 
  248                 iDeleteConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to delete "+sChanName+
" ? ")
 
  249                 if iDeleteConfirmation==1:
 
  252                 bEndOfCorrection=
False 
  255             if iSelectedIndex>0 
or iCombinationAnswer==1:
 
  258                     sHWid=listHWidKeys[iSelectedIndex-1]
 
  263                         print (
"FEB already defined as missing")
 
  269                 bEndOfCorrection=
False 
  275         return StatusCode.Success
 
  279         """ Get channel HW identifier and its status """ 
  282         print (
str(barrel_ec)+
" "+
str(pos_neg)+
" "+
str(feedthrough)+
" "+
str(slot)+
" "+
str(channel)+
"  =>  ",sid.getString())
 
  285         bValidWHidentifier=
False 
  287             bValidWHidentifier=
True 
  288         if self.
onlineID.isEMECchannel(sid):
 
  289             bValidWHidentifier=
True 
  291             bValidWHidentifier=
True 
  292         if self.
onlineID.isFCALchannel(sid):
 
  293             bValidWHidentifier=
True 
  294         if bValidWHidentifier 
is False:
 
  295             return (-1,sid.getString(),
"",0)
 
  300                 if sid.getString()==sHWid:            
 
  301                     return (0,sid.getString(),sChannelName,sFebStatus)
 
  303         return (1,sid.getString(),sChannelName,STATUS_MISSING_FEB)
 
  314         vect_MissingFebHWid=cppyy.gbl.std.vector(
'HWIdentifier')()
 
  320         for key 
in listHWidKeys:
 
  337             vect_MissingFebHWid.push_back(obj_HWid)
 
  343             print (
"No correcton to save")
 
  347         attrListSpec=cppyy.gbl.coral.AttributeListSpecification()
 
  348         athenaAttrList=cppyy.gbl.AthenaAttributeList()
 
  355             dbSave = dbSvc.createDatabase(dbstring)
 
  356         except Exception 
as e:
 
  357             print (
'Problem opening database',e)
 
  359         print (
"Opened database",dbstring)
 
  361         desc=
'<timeStamp>run-event</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>' 
  364         coolSpec=cool.RecordSpecification()
 
  365         for iElemt 
in range(0,attrListSpec.size()):
 
  366             attrSpec=attrListSpec[iElemt]
 
  367             typeName=attrSpec.typeName()
 
  368             if typeName==
"unsigned int":
 
  369                 coolSpec.extend(attrSpec.name(),cool.StorageType.UInt32)
 
  370             elif typeName==
"blob":
 
  371                 coolSpec.extend(attrSpec.name(),cool.StorageType.Blob64k)
 
  373                 print (
"Undefined cool.StorageType "+typeName)
 
  375         myfolder=dbSave.createFolder(dbFolderName, coolSpec, desc, cool.FolderVersioning.MULTI_VERSION,
True)
 
  378         IOVBeginEnd=[
"90",
"9999999"]
 
  379         beginRun = string.atoi(IOVBeginEnd[0]) << 32
 
  380         endRun   = string.atoi(IOVBeginEnd[1]) << 32
 
  383         coolPayload=cool.Record(coolSpec)
 
  384         for iElemt 
in range(0,attrListSpec.size()):
 
  385             attrSpec=attrListSpec[iElemt]
 
  386             coolPayload[attrSpec.name()]=athenaAttrList[attrSpec.name()]
 
  389             myfolder.storeObject(beginRun,endRun,coolPayload,coolChan,selectedTag)
 
  392         dbSave.closeDatabase()
 
  400             dbase = dbSvc.openDatabase(dbName,
False)
 
  401         except Exception 
as e:
 
  402             print (
'Problem opening database',e)
 
  404         print (
"Opened database",dbName)
 
  408             f = dbase.getFolder(dbFolderName)
 
  409             print (
"Analysing Folder " + 
str(dbFolderName))
 
  411             print (
"Skipping " + 
str(dbFolderName))
 
  419             tags.push_back(
"notag")
 
  421         print (
"for tags ", end=
'')
 
  426         bSavingProcessError=
False 
  435             f.countObjects( cool.ValidityKeyMin,cool.ValidityKeyMax,cool.ChannelSelection.all())
 
  436             objs = f.browseObjects( cool.ValidityKeyMin,cool.ValidityKeyMax,cool.ChannelSelection.all())
 
  438             while objs.hasNext():
 
  440                 print (
"Found object", i, end=
'')
 
  441                 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
 
  442                 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
 
  443                 print (
"payload", obj.payload(), end=
'')
 
  444                 print (
"chan",obj.channelId() )
 
  447                 payload=obj.payload()
 
  448                 channelSize=payload[
'ChannelSize']
 
  449                 endianness=payload[
'Endianness']
 
  450                 version=payload[
'Version']
 
  461                 sChannelKey=obj.channelId()
 
  463                 for key 
in sChannelDict.keys():
 
  466                 print (
" -> SQlite database content vs initial data : channel ", sChannelKey)
 
  469                 listHWidKeys=[x 
for x 
in sChannelDict.keys()]
 
  471                     if x 
not in listHWidKeys:
 
  472                         listHWidKeys.append(x)
 
  475                 for keyHWid 
in listHWidKeys:
 
  478                         sChanName,sFebStatus,sValueInit=sChannelDict[keyHWid]
 
  480                         sChanName=
"UNDEFINED" 
  487                             sSuffix=
"  no modification was done"+keyHWid
 
  488                             bSavingProcessError=
True 
  494                         if keyHWid 
in sChannelDict:
 
  496                             sSuffix=
" deletion not taken into accout"+keyHWid
 
  497                             bSavingProcessError=
True 
  499                             sPrefix=STATUS_REMOVED
 
  506                             sSuffix=
" error while saving new status "+keyHWid
 
  507                             bSavingProcessError=
True 
  515                             sSuffix=
" error while saving modified status "+keyHWid
 
  516                             bSavingProcessError=
True 
  518                             sPrefix=STATUS_MODIFIED
 
  521                     HWidChecked[keyHWid]=1
 
  526                         print (
"ERROR : initial ",key,
" has not been saved")
 
  527                     elif key 
in HWidChecked 
and HWidChecked[key]==0:
 
  528                         print (
"ERROR : ",key,
" has not been checked")
 
  535         if bTagFound 
is False:
 
  536             print (
"ERROR : tag "+selectedTag+
" not found in saved SQlite file")
 
  538         if bSavingProcessError 
is True:
 
  539             print (
"ERROR : found while making comparison between corrected and saved datas" )
 
  542         dbase.closeDatabase()