4 from AthenaPython.PyAthena
import StatusCode
5 import AthenaPython.PyAthena
as PyAthena
7 from PyCool
import cool
10 import LArBadChannelBrowserTools
11 import LArDBFolderBrowser_BadChan
12 import LArDBFolderBrowser_MissingFEBs
22 STATUS_NOT_MISSING_FEB=
"0K"
23 STATUS_MISSING_FEB=
"missing"
26 """My first python algorithm ( and most probably not the last one... )
29 def __init__(self, name="LArBadChannelBrowserAlg", **kw):
32 super(LArBadChannelBrowserAlg,self).
__init__(**kw)
44 self.
msg.
info(
'initializing [%s]...',self.name())
45 self.
msg.
debug(
'retrieve StoreGateSvc pointer...')
46 self.
sg = PyAthena.py_svc(
'StoreGateSvc')
48 self.
msg.
error(
'Problem retrieving StoreGateSvc pointer !')
49 return StatusCode.Failure
55 self.
msg.
debug(
'retrieve DetectorStoreSvc pointer...')
56 self.
det = PyAthena.py_svc(
'DetDescrCnvSvc')
58 self.
msg.
error(
'Problem retrieving DetectorStoreSvc pointer !')
59 return StatusCode.Failure
65 self.
msg.
info(
'initializing [%s]...',self.name())
66 self.
msg.
debug(
'retrieve MessageSvc pointer...')
67 self.
msgSvc = PyAthena.py_svc(
'MessageSvc')
69 self.
msg.
error(
'Problem retrieving MessageSvc pointer !')
70 return StatusCode.Failure
76 self.
msg.
debug(
'retrieve database service...')
77 self.
dbSvc = cool.DatabaseSvcFactory.databaseService()
82 dbstring=
"COOLONL_LAR/CONDBR2"
85 except Exception
as e:
86 print (
'Problem opening database',e)
88 print (
"Opened database",dbstring)
92 self.
msg.
info(
'inlineID initialization...')
93 from StoreGateBindings.Bindings
import StoreGate
94 detStore = StoreGate.pointer(
"DetectorStore")
95 self.
onlineID=detStore.retrieve(
"LArOnlineID",
"LArOnlineID")
101 self.
msg.
error(
'Problem retrieving LArCablingService pointer !')
102 return StatusCode.Failure
106 return StatusCode.Success
110 self.
msg.
info(
'running execute...')
115 listOfFolders=[
"/LAR/BadChannels/BadChannels",
"/LAR/BadChannels/MissingFEBs"]
116 iSelectedFolder=LArBadChannelBrowserTools.ChooseOptionFromList(
"Folder list : ",
"",
"",listOfFolders,+1,
False,{})
118 if iSelectedFolder==1:
133 LArBadChannelDBTools=cppyy.makeNamespace(
'LArBadChannelDBTools')
160 iSelectedTag=LArBadChannelBrowserTools.ChooseOptionFromList(
"Tag list : ",
"",
"",listOfTags,+1,
False,{})
187 bEndOfCoolChannelModification=
False
188 while not bEndOfCoolChannelModification:
199 sDBName=os.environ[
"PWD"]+
"/MissingFebUpdate.db"
200 if os.path.isfile(sDBName):
202 dbstring=
"sqlite://;schema="+sDBName+
";dbname=BADCHAN"
211 sCoolChannelMenuDict=[(
"s",
"(summary)"),(
"a",
"(abort)"),(
"q",
"(save and quit)")]
215 repCoolChan=LArBadChannelBrowserTools.ChooseOptionFromList(
"Cool channel list : ",
"",
"",listCoolChannel,
216 0,
False,sCoolChannelMenuDict)
219 iAbortConfirmation=LArBadChannelBrowserTools.YesNoQuestion(
"Are you sure you want to quit ? ")
220 if iAbortConfirmation==1:
222 elif repCoolChan==
"q":
223 print (
" SAUVEGARDE FINALE")
225 sDBName=os.environ[
"PWD"]+
"/BadChannelUpdate.db"
226 if os.path.isfile(sDBName):
228 dbstring=
"sqlite://;schema="+sDBName+
";dbname=BADCHAN"
232 bEndOfCoolChannelModification=
True
233 elif repCoolChan==
"s":
239 coolChan=
int(repCoolChan)
247 return StatusCode.Success
251 """ First database browsing => retrieve tag names, IOVs and number of channels """
255 f = self.
db.getFolder(folderName)
256 print (
"Analysing Folder " +
str(folderName))
258 print (
"Skipping " +
str(folderName))
268 f.countObjects( cool.ValidityKeyMin,
270 cool.ChannelSelection.all(),
273 objs = f.browseObjects( cool.ValidityKeyMin,
275 cool.ChannelSelection.all(),
277 while objs.hasNext():
280 if obj.channelId()>iMaxChannelNumber:
281 iMaxChannelNumber=obj.channelId()
284 if keyTag
not in sIOVBeginEnd:
285 sIOVBeginEnd[keyTag]={}
287 keyChan=obj.channelId()
288 if keyChan
not in sIOVBeginEnd[keyTag]:
289 sIOVBeginEnd[keyTag][keyChan]=[]
291 sIOVBeginEnd[keyTag][keyChan].
append((obj.since()>>32%0x100000000,obj.until()>>32%0x100000000))
297 return (tags,sIOVBeginEnd,iMaxChannelNumber+1)
301 """ Second database browsing => read cool channel corresponding to selected tag """
307 f = self.
db.getFolder(folderName)
308 print (
"Analysing Folder " +
str(folderName))
310 print (
"Skipping " +
str(folderName))
321 print (
"-> tag : ",tag)
323 f.countObjects( cool.ValidityKeyMin,
325 cool.ChannelSelection.all(),
328 objs = f.browseObjects( cool.ValidityKeyMin,
330 cool.ChannelSelection.all(),
333 while objs.hasNext():
337 if (obj.since()>>32%0x100000000)==tagIOVNumber[obj.channelId()]:
339 print (
"Found object", iObjet, end=
'')
340 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
341 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
342 print (
"payload", obj.payload(), end=
'')
343 print (
"chan",obj.channelId())
345 payload=obj.payload()
348 sChannelKey=obj.channelId()
349 sChannelName=self.
dbBrowserBadChan.BadChan_SetBadChannelDataFromPayload(sChannelKey,payload)
351 sChannelKey=obj.channelId()
352 sChannelName=self.
dbBrowserMissingFeb.MissingFeb_SetBadChannelDataFromPayload(sChannelKey,payload)
354 print (sChannelKey,
" ",sChannelName)
355 channelNameDict[sChannelKey]=sChannelName
356 print (
str(channelNameDict))
362 return channelNameDict
372 dbase = dbSvc.openDatabase(dbName,
False)
373 except Exception
as e:
374 print (
'Problem opening database',e)
376 print (
"Opened database",dbName)
379 folders = dbase.listAllNodes()
383 f = dbase.getFolder(ff)
384 print (
"Analysing Folder " +
str(ff))
386 print (
"Skipping " +
str(ff))
394 tags.push_back(
"notag")
404 nobjs = f.countObjects( cool.ValidityKeyMin,
406 cool.ChannelSelection.all())
408 print (
"number of objects", nobjs)
410 objs = f.browseObjects( cool.ValidityKeyMin,
412 cool.ChannelSelection.all())
414 while objs.hasNext():
416 print (
"Found object", i, end=
'')
417 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
418 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
419 print (
"payload", obj.payload(), end=
'')
420 print (
"chan",obj.channelId() )
427 dbase.closeDatabase()