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"
25 """My first python algorithm ( and most probably not my last... ;-)) )
28 def __init__(self,nspace_LArBadChannelDBTools,class_LArBadChanBitPacking,class_LArBadChannel,class_HWIdentifier,
29 onLineID,larCablingSvc,msg):
49 for key
in channelNameDict.keys():
59 channelSize=payload[
'ChannelSize']
60 statusWordSize=payload[
'StatusWordSize']
61 endianness=payload[
'Endianness']
62 version=payload[
'Version']
76 obj_HWid=vect_BadChanEntry.at(0).first
82 for key
in sChannelDict.keys():
98 for sHWid
in listHWidKeys:
120 barrel_ec=self.
onlineID.barrel_ec(obj_HWid)
121 pos_neg=self.
onlineID.pos_neg(obj_HWid)
122 feedthrough=self.
onlineID.feedthrough(obj_HWid)
130 print (
" %5d : %-10s %1d %1d %2d %2d %3d %40s %s " % (iChanCmpt+1,obj_HWid.getString(),
131 barrel_ec,pos_neg,feedthrough,slot,channel,
132 sChanName,sStatusString))
134 print (
"%3s %5d : %-10s %1d %1d %2d %2d %3d %40s %s %s" % (sMessage,iChanCmpt+1,obj_HWid.getString(),
135 barrel_ec,pos_neg,feedthrough,slot,channel,
136 sChanName,sStatusString,sValueInit))
147 blob = attrList[
'Blob']
148 channelSize = attrList[
'ChannelSize']
149 statusWordSize = attrList[
'StatusWordSize']
150 endianness = attrList[
'Endianness']
151 version = attrList[
'Version']
154 print (
"BadChanEntry vector size : ",vect_BadChanEntry.size())
162 listHWidKeys=[x
for x
in sChannelDict.keys()]
166 for sHWid
in listHWidKeys:
168 (sChannelName,larBadChannelStatus,sStatusValue)=sChannelDict[sHWid]
174 """ Transform the BadChanEntry decoded from blob object into a python dictionnary """
176 print (
"--------------------------- Blob SIZE : ",vBadChanEntry.size())
177 iNbBadChannel=vBadChanEntry.size()
180 sChannelDict_Status={}
181 for i
in range(0,iNbBadChannel):
182 larBadChannel=vBadChanEntry.at(i).second
183 obj_HWid=vBadChanEntry.at(i).first
184 sHexaString=obj_HWid.getString()
186 sChannelName=self.
onlineID.channel_name(vBadChanEntry.at(i).first)
188 sChannelDict[sHexaString]=(sChannelName,larBadChannel.packedData(),sInitialValues)
189 sChannelDict_Status[sHexaString]=STATUS_INIT
191 return (sChannelDict,sChannelDict_Status)
197 """ Get channel HW identifier and its status """
200 print (
str(barrel_ec)+
" "+
str(pos_neg)+
" "+
str(feedthrough)+
" "+
str(slot)+
" "+
str(channel)+
" => ",sid.getString())
203 bValidWHidentifier=
False
205 bValidWHidentifier=
True
206 if self.
onlineID.isEMECchannel(sid):
207 bValidWHidentifier=
True
209 bValidWHidentifier=
True
210 if self.
onlineID.isFCALchannel(sid):
211 bValidWHidentifier=
True
212 if bValidWHidentifier
is False:
213 return (-1,sid.getString(),
"",0)
220 if sid.getString()==sHWid:
224 return (0,sid.getString(),sChannelName,badChan_word)
227 sChannelName=self.
onlineID.channel_name(sid)
229 return (1,sid.getString(),sChannelName,badChan_word)
233 """ Get bad channel ProblemType names """
237 if larBadChannel.statusBad(i):
244 """ Get bad channel ProblemType indexes """
248 if larBadChannel.statusBad(i):
249 iBadChannelPb.append(i)
255 """ Get channel name from HW identifier (only for text menu purpose)"""
261 if self.
onlineID.isEMBchannel(sHWid):
263 iEnumChannel=inst_larBadChannelState.EMBA
265 iEnumChannel=inst_larBadChannelState.EMBC
266 if self.
onlineID.isEMECchannel(sHWid):
268 iEnumChannel=inst_larBadChannelState.EMECA
270 iEnumChannel=inst_larBadChannelState.EMECC
271 if self.
onlineID.isHECchannel(sHWid):
273 iEnumChannel=inst_larBadChannelState.HECA
275 iEnumChannel=inst_larBadChannelState.HECC
276 if self.
onlineID.isFCALchannel(sHWid):
278 iEnumChannel=inst_larBadChannelState.FCALA
280 iEnumChannel=inst_larBadChannelState.FCALC
282 sChannelName=inst_larBadChannelState.coolChannelName(iEnumChannel)+
" ("+
str(iEnumChannel)+
")"
287 """ Get list of problem type defines in LArBadChanBitPacking file """
297 print (
"ENUM ProblemType : ")
310 bEndOfCorrection=
False
311 while not bEndOfCorrection:
314 print (
".. To select a channel : enter channel index or barrel_ec pos_neg feedthrough slot channel ")
315 print (
".. To add a channel : enter barrel_ec pos_neg feedthrough slot channel ")
316 print (
".. To remove a channel : enter -(channel index) ")
317 print (
".. Other : s (summary) / r (refresh list) / a (abort) / q (save and quit) .. > ", end=
'')
318 tty =
open(
"/dev/tty",
"r+")
332 barrel_ec,pos_neg,feedthrough,slot,channel=rep.split(
' ')
343 sTxtAnswer=
"save-quit"
347 if iSelection
in range(1,iNbBadChannel+1):
348 iSelectedIndex=iSelection
349 if iSelection
in range(-iNbBadChannel-1,0):
350 iSelectedIndex=iSelection
351 if iSelectedIndex==-99999:
352 bReadableAnswer=
False
355 bReadableAnswer=
False
358 if bReadableAnswer
is False:
359 print (
"could not decode answer... ")
360 bEndOfCorrection=
False
364 if sTxtAnswer==
"abort":
365 iAbortConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to quit ? ")
366 if iAbortConfirmation==1:
368 bEndOfCorrection=
False
371 if sTxtAnswer==
"refresh":
373 bEndOfCorrection=
False
376 if sTxtAnswer==
"summary":
378 bEndOfCorrection=
False
381 if sTxtAnswer==
"save-quit":
382 bEndOfCorrection=
True
386 sHWid=listHWidKeys[-iSelectedIndex-1]
388 iDeleteConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to delete "+sChanName+
" ? ")
389 if iDeleteConfirmation==1:
392 bEndOfCorrection=
False
395 if iSelectedIndex>0
or iCombinationAnswer==1:
398 bNewHWidentifier=
False
400 sHWid=listHWidKeys[iSelectedIndex-1]
405 print (
"An error occured while computing HW identifier -> computed HW identifier does not exist")
406 bChangeHWstatus=
False
408 bNewHWidentifier=
True
412 for i
in range(0,50):
415 for i
in range(0,50):
423 print (
"MODIFICATION STATUS : ",badChan_word,
" ",sNewStatus)
425 if iRes==0
and sNewStatus!=badChan_word:
426 if bNewHWidentifier
is False:
439 bEndOfCorrection=
False
442 return StatusCode.Success
446 """ Get Cabling Service param from HW identifier """
452 cblSvc_string = self.
onlineID.print_to_string(cblSvc_id)
466 for index,sHWid
in enumerate(listHWidKeys):
479 badChan_word=badChan_wordInit
485 sTmp=sTmp+
"%2d %-20s" % (index,s)
489 print (
".. to add/remove a pb : enter index/-index or sequence of indexes")
490 print (
".. other : a : abort / c : cancel correction / r : reset to valid / n : next channel")
493 bEndOfStatusCorrection=
False
495 while not bEndOfStatusCorrection:
500 print (
".. > ", end=
'')
501 tty =
open(
"/dev/tty",
"r+")
506 iAbortConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to quit ? ")
507 if iAbortConfirmation==1:
508 return (-1,badChan_wordInit)
509 bEndOfStatusCorrection=
False
511 badChan_word=larBadChannel.packedData()
512 return (0,badChan_word)
513 bEndOfStatusCorrection=
True
515 iCancelConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to cancel correction ? ")
516 if iCancelConfirmation==1:
517 return (1,STATUS_INIT)
518 bEndOfStatusCorrection=
True
521 reSplitScheme=re.compile(
'[ ,;]+')
522 sTmp=reSplitScheme.split(rep)
523 sRepSeq=[x
for x
in sTmp
if x !=
'']
530 for index
in sRepSeq:
534 iProblemList.append(iNewPb)
536 iProblemList.remove(-iNewPb)
541 for iPb
in iProblemList:
542 inst_larBadChanBitPacking.setBit(iPb,larBadChannel)
543 badChan_word=larBadChannel.packedData()
546 return (-1,badChan_word)
561 for coolChan
in listKeys:
563 vect_BadChanEntry=cppyy.gbl.std.vector(
'std::pair<HWIdentifier,LArBadChannel>')()
568 for key
in listHWidKeys:
584 pair_BadChanEntry=cppyy.gbl.pair(
'HWIdentifier,LArBadChannel')(obj_HWid, larBadChannel)
585 vect_BadChanEntry.push_back(pair_BadChanEntry)
589 for sEntry
in vect_BadChanEntry:
590 inst_larBadChannelState.add(sEntry,coolChan)
595 attrListSpec=cppyy.gbl.coral.AttributeListSpecification()
596 athenaAttrList=cppyy.gbl.AthenaAttributeList()
602 if bNewDBCreated
is False:
604 dbSave = dbSvc.createDatabase(dbstring)
605 except Exception
as e:
606 print (
'Problem opening database',e)
608 print (
"Opened database",dbstring)
610 desc=
'<timeStamp>run-event</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>'
613 coolSpec=cool.RecordSpecification()
614 for iElemt
in range(0,attrListSpec.size()):
615 attrSpec=attrListSpec[iElemt]
616 typeName=attrSpec.typeName()
617 if typeName==
"unsigned int":
618 coolSpec.extend(attrSpec.name(),cool.StorageType.UInt32)
619 elif typeName==
"blob":
620 coolSpec.extend(attrSpec.name(),cool.StorageType.Blob64k)
622 print (
"Undefined cool.StorageType "+typeName)
625 myfolder=dbSave.createFolder(dbFolderName, coolSpec, desc, cool.FolderVersioning.MULTI_VERSION,
True)
628 IOVBeginEnd=[
"90",
"9999999"]
629 beginRun = string.atoi(IOVBeginEnd[0]) << 32
630 endRun = string.atoi(IOVBeginEnd[1]) << 32
635 coolPayload=cool.Record(coolSpec)
636 for iElemt
in range(0,attrListSpec.size()):
637 attrSpec=attrListSpec[iElemt]
638 coolPayload[attrSpec.name()]=athenaAttrList[attrSpec.name()]
641 myfolder.storeObject(beginRun,endRun,coolPayload,coolChan,selectedTag)
644 if bNewDBCreated
is True:
645 dbSave.closeDatabase()
653 dbase = dbSvc.openDatabase(dbName,
False)
654 except Exception
as e:
655 print (
'Problem opening database',e)
657 print (
"Opened database",dbName)
661 f = dbase.getFolder(dbFolderName)
662 print (
"Analysing Folder " +
str(dbFolderName))
664 print (
"Skipping " +
str(dbFolderName))
672 tags.push_back(
"notag")
679 bSavingProcessError=
False
688 f.countObjects( cool.ValidityKeyMin,cool.ValidityKeyMax,cool.ChannelSelection.all())
689 objs = f.browseObjects( cool.ValidityKeyMin,cool.ValidityKeyMax,cool.ChannelSelection.all())
691 while objs.hasNext():
693 print (
"Found object", i, end=
'')
694 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
695 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
696 print (
"payload", obj.payload(), end=
'')
697 print (
"chan",obj.channelId() )
700 payload=obj.payload()
701 channelSize=payload[
'ChannelSize']
702 statusWordSize=payload[
'StatusWordSize']
703 endianness=payload[
'Endianness']
704 version=payload[
'Version']
714 sChannelKey=obj.channelId()
716 for key
in sChannelDict.keys():
719 print (
" -> SQlite database content vs initial data : channel ", sChannelKey)
722 listHWidKeys=[x
for x
in sChannelDict.keys()]
724 if x
not in listHWidKeys:
725 listHWidKeys.append(x)
728 for keyHWid
in listHWidKeys:
731 sChanName,badChan_word,sValueInit=sChannelDict[keyHWid]
733 sChanName=
"UNDEFINED"
740 sSuffix=
" no modification was done"+keyHWid
741 bSavingProcessError=
True
747 if keyHWid
in sChannelDict:
749 sSuffix=
" deletion not taken into accout"+keyHWid
750 bSavingProcessError=
True
752 sPrefix=STATUS_REMOVED
759 sSuffix=
" error while saving new status "+keyHWid
760 bSavingProcessError=
True
768 sSuffix=
" error while saving modified status "+keyHWid
769 bSavingProcessError=
True
771 sPrefix=STATUS_MODIFIED
774 HWidChecked[keyHWid]=1
779 print (
"ERROR : initial ",key,
" has not been saved")
780 elif key
in HWidChecked
and HWidChecked[key]==0:
781 print (
"ERROR : ",key,
" has not been checked")
788 if bTagFound
is False:
789 print (
"ERROR : tag "+selectedTag+
" not found in saved SQlite file")
791 if bSavingProcessError
is True:
792 print (
"ERROR : found while making comparison between corrected and saved datas" )
795 dbase.closeDatabase()