28 from AthenaCommon.AppMgr
import ServiceMgr
as svcMgr
29 from IOVSvc.IOVSvcConf
import CondSvc
30 from IOVSvc.IOVSvcConf
import CondInputLoader
31 from AthenaServices.AthenaServicesConf
import Athena__ConditionsCleanerSvc
32 from AthenaServices.AthenaServicesConf
import Athena__DelayedConditionsCleanerSvc
33 from AthenaCommon.AlgSequence
import AthSequencer
34 from AthenaCommon.ConcurrencyFlags
import jobproperties
as jp
40 if not hasattr(condSeq,
"CondInputLoader"):
41 condInputLoader = CondInputLoader(
"CondInputLoader")
44 condSeq.insert(0, condInputLoader)
46 condInputLoader = condSeq.CondInputLoader
49 nConcurrentEvents =
max(1,jp.ConcurrencyFlags.NumConcurrentEvents())
50 cleaner = Athena__DelayedConditionsCleanerSvc(RingSize = 2*nConcurrentEvents)
52 svcMgr += Athena__ConditionsCleanerSvc (CleanerSvc = cleaner)
55 "Class to hold configuration information for Athena conditions DB access"
57 "Setup conditions DB - IOVDbSvc and connections according to GlobalFlags"
58 from AthenaCommon.AppMgr
import ServiceMgr
as svcMgr
59 from AthenaCommon.Logging
import logging
60 self.
msg = logging.getLogger(
'IOVDbSvc.CondDB' )
61 self.
msg.
debug(
"Loading basic services for CondDBSetup...")
64 from AthenaPoolCnvSvc
import AthenaPool
65 from IOVDbSvc
import IOVDb
81 from AthenaCommon.GlobalFlags
import globalflags
82 from AthenaCommon.AthenaCommonFlags
import athenaCommonFlags
84 self.
isMC=
not globalflags.DataSource()==
'data'
85 if (globalflags.DetGeo()
in [
'atlas',
'commis']):
88 self.
dbdata=globalflags.DatabaseInstance()
97 if athenaCommonFlags.FilesInput():
98 from PyUtils.MetaReader
import read_metadata
100 project_name = metadata[athenaCommonFlags.FilesInput()[0]][
'project_name']
103 self.
msg.
info(
"Configuring database instance '%s' based on project tag '%s'", self.
dbdata, project_name)
106 elif (globalflags.DetGeo()
in [
'ctbh8',
'ctbh6']):
118 raise RuntimeError(
"Unknown globalflags.DetGeo: %s" % globalflags.DetGeo())
120 self.
msg.
info(
'Setting up conditions DB access to instance %s', self.
dbname)
122 self.
_SetAcc(
'INDET',
'COOLONL_INDET')
123 self.
_SetAcc(
'INDET_ONL',
'COOLONL_INDET')
124 self.
_SetAcc(
'PIXEL',
'COOLONL_PIXEL')
125 self.
_SetAcc(
'PIXEL_ONL',
'COOLONL_PIXEL')
126 self.
_SetAcc(
'SCT',
'COOLONL_SCT')
127 self.
_SetAcc(
'SCT_ONL',
'COOLONL_SCT')
128 self.
_SetAcc(
'TRT',
'COOLONL_TRT')
129 self.
_SetAcc(
'TRT_ONL',
'COOLONL_TRT')
130 self.
_SetAcc(
'LAR',
'COOLONL_LAR')
131 self.
_SetAcc(
'LAR_ONL',
'COOLONL_LAR')
132 self.
_SetAcc(
'TILE',
'COOLONL_TILE')
133 self.
_SetAcc(
'TILE_ONL',
'COOLONL_TILE')
134 self.
_SetAcc(
'MUON',
'COOLONL_MUON')
135 self.
_SetAcc(
'MUON_ONL',
'COOLONL_MUON')
136 self.
_SetAcc(
'MUONALIGN',
'COOLONL_MUONALIGN')
137 self.
_SetAcc(
'MUONALIGN_ONL',
'COOLONL_MUONALIGN')
138 self.
_SetAcc(
'MDT',
'COOLONL_MDT')
139 self.
_SetAcc(
'MDT_ONL',
'COOLONL_MDT')
140 self.
_SetAcc(
'RPC',
'COOLONL_RPC')
141 self.
_SetAcc(
'RPC_ONL',
'COOLONL_RPC')
142 self.
_SetAcc(
'TGC',
'COOLONL_TGC')
143 self.
_SetAcc(
'TGC_ONL',
'COOLONL_TGC')
144 self.
_SetAcc(
'CSC',
'COOLONL_CSC')
145 self.
_SetAcc(
'CSC_ONL',
'COOLONL_CSC')
146 self.
_SetAcc(
'TDAQ',
'COOLONL_TDAQ')
147 self.
_SetAcc(
'TDAQ_ONL',
'COOLONL_TDAQ')
148 self.
_SetAcc(
'GLOBAL',
'COOLONL_GLOBAL')
149 self.
_SetAcc(
'GLOBAL_ONL',
'COOLONL_GLOBAL')
150 self.
_SetAcc(
'TRIGGER',
'COOLONL_TRIGGER')
151 self.
_SetAcc(
'TRIGGER_ONL',
'COOLONL_TRIGGER')
152 self.
_SetAcc(
'CALO',
'COOLONL_CALO')
153 self.
_SetAcc(
'CALO_ONL',
'COOLONL_CALO')
154 self.
_SetAcc(
'FWD',
'COOLONL_FWD')
155 self.
_SetAcc(
'FWD_ONL',
'COOLONL_FWD')
160 self.
_SetAcc(
'INDET_OFL',
'COOLOFL_INDET')
161 self.
_SetAcc(
'PIXEL_OFL',
'COOLOFL_PIXEL')
162 self.
_SetAcc(
'SCT_OFL',
'COOLOFL_SCT')
163 self.
_SetAcc(
'TRT_OFL',
'COOLOFL_TRT')
164 self.
_SetAcc(
'LAR_OFL',
'COOLOFL_LAR')
165 self.
_SetAcc(
'TILE_OFL',
'COOLOFL_TILE')
166 self.
_SetAcc(
'MUON_OFL',
'COOLOFL_MUON')
167 self.
_SetAcc(
'MUONALIGN_OFL',
'COOLOFL_MUONALIGN')
168 self.
_SetAcc(
'MDT_OFL',
'COOLOFL_MDT')
169 self.
_SetAcc(
'RPC_OFL',
'COOLOFL_RPC')
170 self.
_SetAcc(
'TGC_OFL',
'COOLOFL_TGC')
171 self.
_SetAcc(
'CSC_OFL',
'COOLOFL_CSC')
172 self.
_SetAcc(
'TDAQ_OFL',
'COOLOFL_TDAQ')
173 self.
_SetAcc(
'DCS_OFL',
'COOLOFL_DCS')
174 self.
_SetAcc(
'GLOBAL_OFL',
'COOLOFL_GLOBAL')
175 self.
_SetAcc(
'TRIGGER_OFL',
'COOLOFL_TRIGGER')
176 self.
_SetAcc(
'CALO_OFL',
'COOLOFL_CALO')
177 self.
_SetAcc(
'FWD_OFL',
'COOLOFL_FWD')
179 self.
msg.
info(
'Running in online mode - no access to COOLOFL schemas')
183 localfile=
"sqlite://;schema=mycool.db;dbname="
184 self.
dblist[
'LOCAL']=localfile
193 from DBReplicaSvc.DBReplicaSvcConf
import DBReplicaSvc
194 svcMgr+=
DBReplicaSvc(COOLSQLiteVetoPattern=
"/DBRelease/")
199 if 'FRONTIER_SERVER' in os.environ.keys()
and os.environ[
'FRONTIER_SERVER']!=
"" and not self.
isOnline:
203 from PoolSvc.PoolSvcConf
import PoolSvc
204 if not hasattr (svcMgr,
'PoolSvc'):
210 svcMgr.PoolSvc.ReadCatalog+=[
"apcfile:poolcond/PoolCat_%s.xml" % i]
211 svcMgr.PoolSvc.ReadCatalog+=[
"apcfile:poolcond/PoolFileCatalog.xml"]
213 raise RuntimeError(
'Not enough configuration information to setup ConditionsDB access (are GlobalFlags being used?)')
214 self.
msg.
debug(
"Loading basic services for CondDBSetup... [DONE]")
216 def addFolder(self,ident,folder,force=False,forceMC=False,forceData=False,
217 className=None,extensible=False):
218 """Add access to the given folder, in the identified subdetector schema.
219 If EXTENSIBLE is set, then if we access an open-ended IOV at the end of the list,
220 the end time for this range will be set to just past the current event.
221 Subsequent accesses will update this end time for subsequent events.
222 This allows the possibility of later adding a new IOV using IOVSvc::setRange."""
225 if (folder.find(block)>=0
and not force):
return
229 folderadd=
"<db>%s%s</db> %s" % (self.
dblist[ident],self.
_GetName(forceMC,forceData),folder)
232 elif (ident.find(
'.')>0):
234 folderadd=
'<db>sqlite://;schema=%s;dbname=%s</db> %s' % (ident,self.
_GetName(forceMC,forceData),folder)
236 raise RuntimeError(
"Conditions database identifier %s is not defined" % ident)
238 folderadd = folderadd +
'<extensible/>'
244 if key
not in condInputLoader.Load:
245 condInputLoader.Load.add(key)
247 def addFolderWithTag(self,ident,folder,tag,force=False,forceMC=False,forceData=False,className=None):
248 "Add access to the given folder/schema, using a specified tag"
249 self.
addFolder(ident,folder+
" <tag>%s</tag>" % tag,force,forceMC,forceData,className=className)
252 className=None,extensible=False):
253 "Add access to given folder, using folder1 online, folder2 offline"
255 self.
addFolder(ident,folder1,force=force,forceMC=forceMC,forceData=forceData,
256 className=className,extensible=extensible)
259 self.
addFolder(ident+
'_OFL',folder2,force=force,forceMC=forceMC,forceData=forceData,
260 className=className,extensible=extensible)
263 def addFolderSplitMC(self,ident,folder1,folder2,force=False,forceMC=False,forceData=False,className=None):
264 "Add access to given folder, using folder1 (online) for real data, folde2 (offline) for MC"
266 self.
addFolder(ident+
'_OFL',folder2,force=force,forceMC=forceMC,forceData=forceData,className=className)
268 self.
addFolder(ident,folder1,force=force,forceMC=forceMC,forceData=forceData,className=className)
271 "Add a tag override for the specified folder"
272 overrideDirective =
'<prefix>%s</prefix> <tag>%s</tag>' % (folder,tag)
273 if overrideDirective
not in self.
iovdbsvc.overrideTags:
274 self.
iovdbsvc.overrideTags+=[overrideDirective]
277 "Block use of specified conditions DB folder so data can be read from elsewhere"
286 for f
in condInputLoader.Load:
287 if (f[-1] == folderName):
288 condInputLoader.Load.remove(f)
292 "Return true if the given folder has already been requested"
294 if (i.find(folder)>=0):
return True
298 "Add given XML markup to folder string for given folder"
305 raise RuntimeError(
"conddb.addMarkup: Folder %s is not known to IOVDbSvc" % folder)
309 "Set the GlobalTag value used as the key for hierarhical conditions"
314 "Set the flag indicating global tags will be required to be locked"
318 "Set option to write data to file"
319 self.
iovdbsvc.OutputToFile=writeData
322 "Set option to write CREST data to file"
327 "Extract the folder name (non-XML text) from a IOVDbSvc.Folders entry"
331 while ix<len(folderstr):
332 if (folderstr[ix]==
'<' and xmltag==
""):
333 ix2=folderstr.find(
'>',ix)
335 xmltag=(folderstr[ix+1:ix2]).strip()
337 if xmltag[-1] ==
'/':
340 elif (folderstr[ix:ix+2]==
'</' and xmltag!=
""):
341 ix2=folderstr.find(
'>',ix)
346 ix2=folderstr.find(
'<',ix)
347 if ix2==-1: ix2=len(folderstr)
348 if (xmltag==
""): fname=fname+folderstr[ix:ix2]
354 "Write out folder-specific tag names to file, for use with AtlCoolCopy tools"
355 ofile=
open(outfile,
'w')
356 for folderstr
in self.
iovdbsvc.Folders:
365 if '<db>' in folderstr:
366 idx1=folderstr.find(
'<db>')+4
367 idx2=folderstr.find(
'</db>')
369 dbname=folderstr[idx1:idx2].strip()
372 elif 'OFL' in dbname:
374 ofile.write(
'--folder %s%s\n' % (fname,dbtype))
375 if '<tag>' in folderstr:
376 idx1=folderstr.find(
'<tag>')+5
377 idx2=folderstr.find(
'</tag>')
379 tag=folderstr[idx1:idx2].strip()
382 if ((tag.find(
'TagInfo')!=0
and tag!=
'HEAD')
or folderOrigin):
383 ofile.write(
'--tag %s\n' % tag)
385 for folderstr
in self.
iovdbsvc.overrideTags:
387 if '<tag>' in folderstr:
388 idx1=folderstr.find(
'<tag>')+5
389 idx2=folderstr.find(
'</tag>')
391 tag=folderstr[idx1:idx2].strip()
393 if (tag.find(
'TagInfo')!=0
and tag!=
'HEAD'):
394 ofile.write(
'--tag %s\n' % tag)
398 "Dump configuration information for use in ReadReal in AthenaDBTestRec"
399 ofile=
open(outfile,
'w')
400 ofile.write(
'FolderList=%s\n' % self.
iovdbsvc.Folders.__repr__())
404 "Get the name of the DB instance in use (e.g. OFLP200)"
405 return self.
_GetName(forceMC,forceData)
409 "Internal helper function to setup database access string"
410 self.
dblist[ident]=
"%s/" % schema
413 "Internal get db instance name, taking into account forceData/MC flags"
424 year=
int(projectName[4:6])
426 self.
msg.warning(f
"Failed to extract year from project tag '{projectName}', using CONDBR2.")