topSequence = AlgSequence()

## get a handle to the ApplicationManager, to the ServiceManager and to the ToolSvc
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr, ToolSvc)

theApp.EvtMax = 10

from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelTimingAlg
theTester = LArBadChannelTimingAlg()
theTester.ReallyCheck = True
topSequence += theTester

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.ReadFromASCII = False
theLArBadChannelTool.DumpCache = False

#theLArBadChannelTool.EMBAfile = "badchan1.txt"
theLArBadChannelTool.EMBCfile = "badchan1.txt"

theLArBadChannelTool.OutputLevel = DEBUG
ToolSvc += theLArBadChannelTool

svcMgr.IOVDbSvc.Folders += [
    "/LAR/ElecCalib/BadChannels<tag>TestTag</tag><dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>"
]

svcMgr += CfgMgr.AthenaEventLoopMgr(OutputLevel=WARNING)

from AthenaCommon.AppMgr import theAuditorSvc
from AthenaCommon.ConfigurableDb import getConfigurable
## get a handle to the ApplicationManager, to the ServiceManager and to the ToolSvc
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr,ToolSvc)

BadChanTag=join(split(BadChanFolder, '/'),'') + TagPostfix
FEBTag=join(split(FEBFolder, '/'),'') + TagPostfix

DBConnection = "<dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>"
DBBadChanFolder = BadChanFolder + "<tag>" + BadChanTag + "</tag>" + DBConnection
DBFebFolder     = FEBFolder     + "<tag>" + FEBTag     + "</tag>" + DBConnection

svcMgr.IOVDbSvc.Folders+=[DBBadChanFolder]
svcMgr.IOVDbSvc.Folders+=[DBFebFolder]

#svcMgr.IOVDbSvc.Folders+=["/LAR/BadChannels/BadChannels<tag>LARBadChannelsBadChannels-M6-01</tag><dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>" ]
#svcMgr.IOVDbSvc.Folders+=["/LAR/BadChannels/MissingFEBs<tag>LARBadChannelsMissingFEBs-M6-01</tag><dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>" ]
#conddb.addFolder("LAR","/LAR/BadChannels/BadChannels")
svcMgr.IOVDbSvc.GlobalTag=GlobalTag

from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelToolTest
theLArBadChannels=LArBadChannelToolTest()
#theLArBadChannels.FileName="bc_out.txt"
topSequence+=theLArBadChannels

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool=LArBadChanTool()
theLArBadChannelTool.OutputLevel=DEBUG
theLArBadChannelTool.DumpCache = True
theLArBadChannelTool.CoolMissingFEBsFolder = "/LAR/BadChannels/MissingFEBs" # read missing FEBs folder
#theLArBadChannelTool.CoolMissingFEBsFolder = "" # deactivate missing FEBs folder
ToolSvc+=theLArBadChannelTool