3 from __future__
import print_function
5 from AthenaPython.PyAthena
import StatusCode
6 import AthenaPython.PyAthena
as PyAthena
8 from PyCool
import cool
11 import LArBadChannelBrowserTools
12 import LArDBFolderBrowser_BadChan
13 import LArDBFolderBrowser_MissingFEBs
23 STATUS_NOT_MISSING_FEB=
"0K"
24 STATUS_MISSING_FEB=
"missing"
27 """My first python algorithm ( and most probably not the last one... )
30 def __init__(self, name="LArBadChannelBrowserAlg", **kw):
33 super(LArBadChannelBrowserAlg,self).
__init__(**kw)
45 self.
msg.
info(
'initializing [%s]...',self.name())
46 self.
msg.
debug(
'retrieve StoreGateSvc pointer...')
47 self.
sg = PyAthena.py_svc(
'StoreGateSvc')
49 self.
msg.
error(
'Problem retrieving StoreGateSvc pointer !')
50 return StatusCode.Failure
56 self.
msg.
debug(
'retrieve DetectorStoreSvc pointer...')
57 self.
det = PyAthena.py_svc(
'DetDescrCnvSvc')
59 self.
msg.
error(
'Problem retrieving DetectorStoreSvc pointer !')
60 return StatusCode.Failure
66 self.
msg.
info(
'initializing [%s]...',self.name())
67 self.
msg.
debug(
'retrieve MessageSvc pointer...')
68 self.
msgSvc = PyAthena.py_svc(
'MessageSvc')
70 self.
msg.
error(
'Problem retrieving MessageSvc pointer !')
71 return StatusCode.Failure
77 self.
msg.
debug(
'retrieve database service...')
78 self.
dbSvc = cool.DatabaseSvcFactory.databaseService()
83 dbstring=
"COOLONL_LAR/CONDBR2"
86 except Exception
as e:
87 print (
'Problem opening database',e)
89 print (
"Opened database",dbstring)
93 self.
msg.
info(
'inlineID initialization...')
94 from StoreGateBindings.Bindings
import StoreGate
95 detStore = StoreGate.pointer(
"DetectorStore")
96 self.
onlineID=detStore.retrieve(
"LArOnlineID",
"LArOnlineID")
102 self.
msg.
error(
'Problem retrieving LArCablingService pointer !')
103 return StatusCode.Failure
107 return StatusCode.Success
111 self.
msg.
info(
'running execute...')
116 listOfFolders=[
"/LAR/BadChannels/BadChannels",
"/LAR/BadChannels/MissingFEBs"]
117 iSelectedFolder=LArBadChannelBrowserTools.ChooseOptionFromList(
"Folder list : ",
"",
"",listOfFolders,+1,
False,{})
119 if iSelectedFolder==1:
134 LArBadChannelDBTools=cppyy.makeNamespace(
'LArBadChannelDBTools')
161 iSelectedTag=LArBadChannelBrowserTools.ChooseOptionFromList(
"Tag list : ",
"",
"",listOfTags,+1,
False,{})
188 bEndOfCoolChannelModification=
False
189 while not bEndOfCoolChannelModification:
200 sDBName=os.environ[
"PWD"]+
"/MissingFebUpdate.db"
201 if os.path.isfile(sDBName):
203 dbstring=
"sqlite://;schema="+sDBName+
";dbname=BADCHAN"
212 sCoolChannelMenuDict=[(
"s",
"(summary)"),(
"a",
"(abort)"),(
"q",
"(save and quit)")]
216 repCoolChan=LArBadChannelBrowserTools.ChooseOptionFromList(
"Cool channel list : ",
"",
"",listCoolChannel,
217 0,
False,sCoolChannelMenuDict)
220 iAbortConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to quit ? ")
221 if iAbortConfirmation==1:
223 elif repCoolChan==
"q":
224 print (
" SAUVEGARDE FINALE")
226 sDBName=os.environ[
"PWD"]+
"/BadChannelUpdate.db"
227 if os.path.isfile(sDBName):
229 dbstring=
"sqlite://;schema="+sDBName+
";dbname=BADCHAN"
233 bEndOfCoolChannelModification=
True
234 elif repCoolChan==
"s":
240 coolChan=
int(repCoolChan)
248 return StatusCode.Success
252 """ First database browsing => retrieve tag names, IOVs and number of channels """
256 f = self.
db.getFolder(folderName)
257 print (
"Analysing Folder " +
str(folderName))
259 print (
"Skipping " +
str(folderName))
269 f.countObjects( cool.ValidityKeyMin,
271 cool.ChannelSelection.all(),
274 objs = f.browseObjects( cool.ValidityKeyMin,
276 cool.ChannelSelection.all(),
278 while objs.hasNext():
281 if obj.channelId()>iMaxChannelNumber:
282 iMaxChannelNumber=obj.channelId()
285 if keyTag
not in sIOVBeginEnd:
286 sIOVBeginEnd[keyTag]={}
288 keyChan=obj.channelId()
289 if keyChan
not in sIOVBeginEnd[keyTag]:
290 sIOVBeginEnd[keyTag][keyChan]=[]
292 sIOVBeginEnd[keyTag][keyChan].
append((obj.since()>>32%0x100000000,obj.until()>>32%0x100000000))
298 return (tags,sIOVBeginEnd,iMaxChannelNumber+1)
302 """ Second database browsing => read cool channel corresponding to selected tag """
308 f = self.
db.getFolder(folderName)
309 print (
"Analysing Folder " +
str(folderName))
311 print (
"Skipping " +
str(folderName))
322 print (
"-> tag : ",tag)
324 f.countObjects( cool.ValidityKeyMin,
326 cool.ChannelSelection.all(),
329 objs = f.browseObjects( cool.ValidityKeyMin,
331 cool.ChannelSelection.all(),
334 while objs.hasNext():
338 if (obj.since()>>32%0x100000000)==tagIOVNumber[obj.channelId()]:
340 print (
"Found object", iObjet, end=
'')
341 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
342 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
343 print (
"payload", obj.payload(), end=
'')
344 print (
"chan",obj.channelId())
346 payload=obj.payload()
349 sChannelKey=obj.channelId()
350 sChannelName=self.
dbBrowserBadChan.BadChan_SetBadChannelDataFromPayload(sChannelKey,payload)
352 sChannelKey=obj.channelId()
353 sChannelName=self.
dbBrowserMissingFeb.MissingFeb_SetBadChannelDataFromPayload(sChannelKey,payload)
355 print (sChannelKey,
" ",sChannelName)
356 channelNameDict[sChannelKey]=sChannelName
357 print (
str(channelNameDict))
363 return channelNameDict
373 dbase = dbSvc.openDatabase(dbName,
False)
374 except Exception
as e:
375 print (
'Problem opening database',e)
377 print (
"Opened database",dbName)
380 folders = dbase.listAllNodes()
384 f = dbase.getFolder(ff)
385 print (
"Analysing Folder " +
str(ff))
387 print (
"Skipping " +
str(ff))
395 tags.push_back(
"notag")
405 nobjs = f.countObjects( cool.ValidityKeyMin,
407 cool.ChannelSelection.all())
409 print (
"number of objects", nobjs)
411 objs = f.browseObjects( cool.ValidityKeyMin,
413 cool.ChannelSelection.all())
415 while objs.hasNext():
417 print (
"Found object", i, end=
'')
418 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
419 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
420 print (
"payload", obj.payload(), end=
'')
421 print (
"chan",obj.channelId() )
428 dbase.closeDatabase()