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"
24 """My first python algorithm ( and most probably not my last... ;-)) )
27 def __init__(self,nspace_LArBadChannelDBTools,class_LArBadChanBitPacking,class_LArBadChannel,class_HWIdentifier,
28 onLineID,larCablingSvc,msg):
48 for key
in channelNameDict.keys():
58 channelSize=payload[
'ChannelSize']
59 statusWordSize=payload[
'StatusWordSize']
60 endianness=payload[
'Endianness']
61 version=payload[
'Version']
75 obj_HWid=vect_BadChanEntry.at(0).first
81 for key
in sChannelDict.keys():
97 for sHWid
in listHWidKeys:
119 barrel_ec=self.
onlineID.barrel_ec(obj_HWid)
120 pos_neg=self.
onlineID.pos_neg(obj_HWid)
121 feedthrough=self.
onlineID.feedthrough(obj_HWid)
129 print (
" %5d : %-10s %1d %1d %2d %2d %3d %40s %s " % (iChanCmpt+1,obj_HWid.getString(),
130 barrel_ec,pos_neg,feedthrough,slot,channel,
131 sChanName,sStatusString))
133 print (
"%3s %5d : %-10s %1d %1d %2d %2d %3d %40s %s %s" % (sMessage,iChanCmpt+1,obj_HWid.getString(),
134 barrel_ec,pos_neg,feedthrough,slot,channel,
135 sChanName,sStatusString,sValueInit))
146 blob = attrList[
'Blob']
147 channelSize = attrList[
'ChannelSize']
148 statusWordSize = attrList[
'StatusWordSize']
149 endianness = attrList[
'Endianness']
150 version = attrList[
'Version']
153 print (
"BadChanEntry vector size : ",vect_BadChanEntry.size())
161 listHWidKeys=[x
for x
in sChannelDict.keys()]
165 for sHWid
in listHWidKeys:
167 (sChannelName,larBadChannelStatus,sStatusValue)=sChannelDict[sHWid]
173 """ Transform the BadChanEntry decoded from blob object into a python dictionnary """
175 print (
"--------------------------- Blob SIZE : ",vBadChanEntry.size())
176 iNbBadChannel=vBadChanEntry.size()
179 sChannelDict_Status={}
180 for i
in range(0,iNbBadChannel):
181 larBadChannel=vBadChanEntry.at(i).second
182 obj_HWid=vBadChanEntry.at(i).first
183 sHexaString=obj_HWid.getString()
185 sChannelName=self.
onlineID.channel_name(vBadChanEntry.at(i).first)
187 sChannelDict[sHexaString]=(sChannelName,larBadChannel.packedData(),sInitialValues)
188 sChannelDict_Status[sHexaString]=STATUS_INIT
190 return (sChannelDict,sChannelDict_Status)
196 """ Get channel HW identifier and its status """
199 print (
str(barrel_ec)+
" "+
str(pos_neg)+
" "+
str(feedthrough)+
" "+
str(slot)+
" "+
str(channel)+
" => ",sid.getString())
202 bValidWHidentifier=
False
204 bValidWHidentifier=
True
205 if self.
onlineID.isEMECchannel(sid):
206 bValidWHidentifier=
True
208 bValidWHidentifier=
True
209 if self.
onlineID.isFCALchannel(sid):
210 bValidWHidentifier=
True
211 if bValidWHidentifier
is False:
212 return (-1,sid.getString(),
"",0)
219 if sid.getString()==sHWid:
223 return (0,sid.getString(),sChannelName,badChan_word)
226 sChannelName=self.
onlineID.channel_name(sid)
228 return (1,sid.getString(),sChannelName,badChan_word)
232 """ Get bad channel ProblemType names """
236 if larBadChannel.statusBad(i):
243 """ Get bad channel ProblemType indexes """
247 if larBadChannel.statusBad(i):
248 iBadChannelPb.append(i)
254 """ Get channel name from HW identifier (only for text menu purpose)"""
260 if self.
onlineID.isEMBchannel(sHWid):
262 iEnumChannel=inst_larBadChannelState.EMBA
264 iEnumChannel=inst_larBadChannelState.EMBC
265 if self.
onlineID.isEMECchannel(sHWid):
267 iEnumChannel=inst_larBadChannelState.EMECA
269 iEnumChannel=inst_larBadChannelState.EMECC
270 if self.
onlineID.isHECchannel(sHWid):
272 iEnumChannel=inst_larBadChannelState.HECA
274 iEnumChannel=inst_larBadChannelState.HECC
275 if self.
onlineID.isFCALchannel(sHWid):
277 iEnumChannel=inst_larBadChannelState.FCALA
279 iEnumChannel=inst_larBadChannelState.FCALC
281 sChannelName=inst_larBadChannelState.coolChannelName(iEnumChannel)+
" ("+
str(iEnumChannel)+
")"
286 """ Get list of problem type defines in LArBadChanBitPacking file """
296 print (
"ENUM ProblemType : ")
309 bEndOfCorrection=
False
310 while not bEndOfCorrection:
313 print (
".. To select a channel : enter channel index or barrel_ec pos_neg feedthrough slot channel ")
314 print (
".. To add a channel : enter barrel_ec pos_neg feedthrough slot channel ")
315 print (
".. To remove a channel : enter -(channel index) ")
316 print (
".. Other : s (summary) / r (refresh list) / a (abort) / q (save and quit) .. > ", end=
'')
317 tty =
open(
"/dev/tty",
"r+")
331 barrel_ec,pos_neg,feedthrough,slot,channel=rep.split(
' ')
342 sTxtAnswer=
"save-quit"
346 if iSelection
in range(1,iNbBadChannel+1):
347 iSelectedIndex=iSelection
348 if iSelection
in range(-iNbBadChannel-1,0):
349 iSelectedIndex=iSelection
350 if iSelectedIndex==-99999:
351 bReadableAnswer=
False
354 bReadableAnswer=
False
357 if bReadableAnswer
is False:
358 print (
"could not decode answer... ")
359 bEndOfCorrection=
False
363 if sTxtAnswer==
"abort":
364 iAbortConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to quit ? ")
365 if iAbortConfirmation==1:
367 bEndOfCorrection=
False
370 if sTxtAnswer==
"refresh":
372 bEndOfCorrection=
False
375 if sTxtAnswer==
"summary":
377 bEndOfCorrection=
False
380 if sTxtAnswer==
"save-quit":
381 bEndOfCorrection=
True
385 sHWid=listHWidKeys[-iSelectedIndex-1]
387 iDeleteConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to delete "+sChanName+
" ? ")
388 if iDeleteConfirmation==1:
391 bEndOfCorrection=
False
394 if iSelectedIndex>0
or iCombinationAnswer==1:
397 bNewHWidentifier=
False
399 sHWid=listHWidKeys[iSelectedIndex-1]
404 print (
"An error occured while computing HW identifier -> computed HW identifier does not exist")
405 bChangeHWstatus=
False
407 bNewHWidentifier=
True
411 for i
in range(0,50):
414 for i
in range(0,50):
422 print (
"MODIFICATION STATUS : ",badChan_word,
" ",sNewStatus)
424 if iRes==0
and sNewStatus!=badChan_word:
425 if bNewHWidentifier
is False:
438 bEndOfCorrection=
False
441 return StatusCode.Success
445 """ Get Cabling Service param from HW identifier """
451 cblSvc_string = self.
onlineID.print_to_string(cblSvc_id)
465 for index,sHWid
in enumerate(listHWidKeys):
478 badChan_word=badChan_wordInit
484 sTmp=sTmp+
"%2d %-20s" % (index,s)
488 print (
".. to add/remove a pb : enter index/-index or sequence of indexes")
489 print (
".. other : a : abort / c : cancel correction / r : reset to valid / n : next channel")
492 bEndOfStatusCorrection=
False
494 while not bEndOfStatusCorrection:
499 print (
".. > ", end=
'')
500 tty =
open(
"/dev/tty",
"r+")
505 iAbortConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to quit ? ")
506 if iAbortConfirmation==1:
507 return (-1,badChan_wordInit)
508 bEndOfStatusCorrection=
False
510 badChan_word=larBadChannel.packedData()
511 return (0,badChan_word)
512 bEndOfStatusCorrection=
True
514 iCancelConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to cancel correction ? ")
515 if iCancelConfirmation==1:
516 return (1,STATUS_INIT)
517 bEndOfStatusCorrection=
True
520 reSplitScheme=re.compile(
'[ ,;]+')
521 sTmp=reSplitScheme.split(rep)
522 sRepSeq=[x
for x
in sTmp
if x !=
'']
529 for index
in sRepSeq:
533 iProblemList.append(iNewPb)
535 iProblemList.remove(-iNewPb)
540 for iPb
in iProblemList:
541 inst_larBadChanBitPacking.setBit(iPb,larBadChannel)
542 badChan_word=larBadChannel.packedData()
545 return (-1,badChan_word)
560 for coolChan
in listKeys:
562 vect_BadChanEntry=cppyy.gbl.std.vector(
'std::pair<HWIdentifier,LArBadChannel>')()
567 for key
in listHWidKeys:
583 pair_BadChanEntry=cppyy.gbl.pair(
'HWIdentifier,LArBadChannel')(obj_HWid, larBadChannel)
584 vect_BadChanEntry.push_back(pair_BadChanEntry)
588 for sEntry
in vect_BadChanEntry:
589 inst_larBadChannelState.add(sEntry,coolChan)
594 attrListSpec=cppyy.gbl.coral.AttributeListSpecification()
595 athenaAttrList=cppyy.gbl.AthenaAttributeList()
601 if bNewDBCreated
is False:
603 dbSave = dbSvc.createDatabase(dbstring)
604 except Exception
as e:
605 print (
'Problem opening database',e)
607 print (
"Opened database",dbstring)
609 desc=
'<timeStamp>run-event</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>'
612 coolSpec=cool.RecordSpecification()
613 for iElemt
in range(0,attrListSpec.size()):
614 attrSpec=attrListSpec[iElemt]
615 typeName=attrSpec.typeName()
616 if typeName==
"unsigned int":
617 coolSpec.extend(attrSpec.name(),cool.StorageType.UInt32)
618 elif typeName==
"blob":
619 coolSpec.extend(attrSpec.name(),cool.StorageType.Blob64k)
621 print (
"Undefined cool.StorageType "+typeName)
624 myfolder=dbSave.createFolder(dbFolderName, coolSpec, desc, cool.FolderVersioning.MULTI_VERSION,
True)
627 IOVBeginEnd=[
"90",
"9999999"]
628 beginRun = string.atoi(IOVBeginEnd[0]) << 32
629 endRun = string.atoi(IOVBeginEnd[1]) << 32
634 coolPayload=cool.Record(coolSpec)
635 for iElemt
in range(0,attrListSpec.size()):
636 attrSpec=attrListSpec[iElemt]
637 coolPayload[attrSpec.name()]=athenaAttrList[attrSpec.name()]
640 myfolder.storeObject(beginRun,endRun,coolPayload,coolChan,selectedTag)
643 if bNewDBCreated
is True:
644 dbSave.closeDatabase()
652 dbase = dbSvc.openDatabase(dbName,
False)
653 except Exception
as e:
654 print (
'Problem opening database',e)
656 print (
"Opened database",dbName)
660 f = dbase.getFolder(dbFolderName)
661 print (
"Analysing Folder " +
str(dbFolderName))
663 print (
"Skipping " +
str(dbFolderName))
671 tags.push_back(
"notag")
678 bSavingProcessError=
False
687 f.countObjects( cool.ValidityKeyMin,cool.ValidityKeyMax,cool.ChannelSelection.all())
688 objs = f.browseObjects( cool.ValidityKeyMin,cool.ValidityKeyMax,cool.ChannelSelection.all())
690 while objs.hasNext():
692 print (
"Found object", i, end=
'')
693 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
694 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
695 print (
"payload", obj.payload(), end=
'')
696 print (
"chan",obj.channelId() )
699 payload=obj.payload()
700 channelSize=payload[
'ChannelSize']
701 statusWordSize=payload[
'StatusWordSize']
702 endianness=payload[
'Endianness']
703 version=payload[
'Version']
713 sChannelKey=obj.channelId()
715 for key
in sChannelDict.keys():
718 print (
" -> SQlite database content vs initial data : channel ", sChannelKey)
721 listHWidKeys=[x
for x
in sChannelDict.keys()]
723 if x
not in listHWidKeys:
724 listHWidKeys.append(x)
727 for keyHWid
in listHWidKeys:
730 sChanName,badChan_word,sValueInit=sChannelDict[keyHWid]
732 sChanName=
"UNDEFINED"
739 sSuffix=
" no modification was done"+keyHWid
740 bSavingProcessError=
True
746 if keyHWid
in sChannelDict:
748 sSuffix=
" deletion not taken into accout"+keyHWid
749 bSavingProcessError=
True
751 sPrefix=STATUS_REMOVED
758 sSuffix=
" error while saving new status "+keyHWid
759 bSavingProcessError=
True
767 sSuffix=
" error while saving modified status "+keyHWid
768 bSavingProcessError=
True
770 sPrefix=STATUS_MODIFIED
773 HWidChecked[keyHWid]=1
778 print (
"ERROR : initial ",key,
" has not been saved")
779 elif key
in HWidChecked
and HWidChecked[key]==0:
780 print (
"ERROR : ",key,
" has not been checked")
787 if bTagFound
is False:
788 print (
"ERROR : tag "+selectedTag+
" not found in saved SQlite file")
790 if bSavingProcessError
is True:
791 print (
"ERROR : found while making comparison between corrected and saved datas" )
794 dbase.closeDatabase()