3 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator, ConfigurationError
5 from AthenaConfiguration.ComponentFactory
import CompFactory
6 from AthenaConfiguration.AccumulatorCache
import AccumulatorCache
7 from AthenaCommon.Logging
import logging
8 from functools
import cache
10 msg = logging.getLogger(
'IOVDbSvcCfg')
14 result.addCondAlgo(CompFactory.CondInputLoader(**kwargs))
20 kwargs.setdefault(
'COOLSQLiteVetoPattern',
'/DBRelease/')
23 result.addService(CompFactory.DBReplicaSvc(**kwargs))
32 kwargs.setdefault(
'OnlineMode', flags.Common.isOnline)
33 kwargs.setdefault(
'dbConnection', flags.IOVDb.DBConnection)
34 kwargs.setdefault(
'crestServer', flags.IOVDb.CrestServer)
36 kwargs.setdefault(
'DBInstance', flags.IOVDb.DatabaseInstance)
38 if 'FRONTIER_SERVER' in os.environ.keys()
and os.environ[
'FRONTIER_SERVER'] !=
'':
39 kwargs.setdefault(
'CacheAlign', 3)
42 if flags.Common.isOnline
and flags.Trigger.Online.isPartition:
43 kwargs[
'CacheAlign'] = 0
44 kwargs[
'CacheRun'] = 0
45 kwargs[
'CacheTime'] = 0
47 kwargs.setdefault(
'GlobalTag', flags.IOVDb.GlobalTag)
48 if 'Folders' in kwargs:
49 kwargs[
'Folders'] = [
'/TagInfo<metaOnly/>'] + kwargs[
'Folders']
51 kwargs.setdefault(
'Folders', [
'/TagInfo<metaOnly/>'])
54 if flags.IOVDb.GlobalTag
and flags.IOVDb.GlobalTag.startswith(
'CREST-'):
55 kwargs.setdefault(
'Source',
'CREST')
57 result.addService(CompFactory.IOVDbSvc(**kwargs), primary=
True)
60 from AthenaPoolCnvSvc.PoolCommonConfig
import PoolSvcCfg, AthenaPoolCnvSvcCfg
61 result.merge(
PoolSvcCfg(flags, withCatalogs=
True))
63 result.addService(CompFactory.CondSvc())
64 result.addService(CompFactory.ProxyProviderSvc(ProviderNames=[
'IOVDbSvc']))
66 if not flags.Input.isMC:
70 from EventInfoMgt.TagInfoMgrConfig
import TagInfoMgrCfg
74 from AthenaServices.MetaDataSvcConfig
import MetaDataSvcCfg
81 def addFolders(flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers=''):
84 tagString =
'<tag>%s</tag>' % tag
87 if isinstance(folderStrings, str):
88 return addFolderList(flags, ((folderStrings + tagString, detDb, className),), extensible, db, modifiers)
91 folderDefinitions = []
93 for folderString
in folderStrings:
94 folderDefinitions.append((folderString + tagString, detDb, className))
96 return addFolderList(flags, folderDefinitions, extensible, db, modifiers)
99 def addFolderList(flags, listOfFolderInfoTuple, extensible=False, db=None, modifiers=''):
100 """Add access to the given set of folders, in the identified subdetector schema.
101 FolerInfoTuple consists of (foldername,detDB,classname)
103 If EXTENSIBLE is set, then if we access an open-ended IOV at the end of the list,
104 the end time for this range will be set to just past the current event.
105 Subsequent accesses will update this end time for subsequent events.
106 This allows the possibility of later adding a new IOV using IOVSvc::setRange."""
110 flags.IOVDb.SqliteFolders,
111 flags.IOVDb.DatabaseInstance)
113 for (fs, detDb, className)
in listOfFolderInfoTuple:
116 if className
is not None:
117 loadFolders.add((className, fse))
119 if fse
in sqliteFolders:
120 msg.warning(f
'Reading folder {fs} from sqlite, bypassing production database')
121 fs+=sqliteFolders[fse]
122 elif detDb
is not None and fs.find(
'<db>') == -1:
127 dbName = flags.IOVDb.DatabaseInstance
128 if detDb
in _dblist.keys():
129 fs = f
'<db>{_dblist[detDb]}/{dbName}</db> {fs}'
130 elif os.access(detDb, os.R_OK):
132 fs = f
'<db>sqlite://;schema={detDb};dbname={dbName}</db> {fs}'
134 raise ConfigurationError(f
'Error, db shorthand {detDb} not known, nor found as sqlite file')
138 fs = fs +
'<extensible/>'
148 result.getPrimary().Folders+=folders
150 result.getCondAlgo(
'CondInputLoader').Load |= loadFolders
152 if flags.IOVDb.CleanerRingSize > 0:
154 cleanerSvc = CompFactory.Athena.DelayedConditionsCleanerSvc(RingSize=flags.IOVDb.CleanerRingSize)
155 result.addService(cleanerSvc)
156 result.addService(CompFactory.Athena.ConditionsCleanerSvc(CleanerSvc=cleanerSvc))
162 def addFoldersSplitOnline(flags, detDb, onlineFolders, offlineFolders, className=None, extensible=False, addMCString='_OFL', splitMC=False, tag=None, forceDb=None, modifiers=''):
163 """Add access to given folder, using either online_folder or offline_folder. For MC, add addMCString as a postfix (default is _OFL)"""
165 if flags.Common.isOnline
and not flags.Input.isMC:
166 folders = onlineFolders
167 elif splitMC
and not flags.Input.isMC:
168 folders = onlineFolders
171 detDb = detDb + addMCString
172 folders = offlineFolders
174 return addFolders(flags, folders, detDb, className, extensible, tag=tag, db=forceDb, modifiers=modifiers)
178 'INDET':
'COOLONL_INDET',
179 'INDET_ONL':
'COOLONL_INDET',
180 'PIXEL':
'COOLONL_PIXEL',
181 'PIXEL_ONL':
'COOLONL_PIXEL',
183 'SCT_ONL':
'COOLONL_SCT',
185 'TRT_ONL':
'COOLONL_TRT',
187 'LAR_ONL':
'COOLONL_LAR',
188 'TILE':
'COOLONL_TILE',
189 'TILE_ONL':
'COOLONL_TILE',
190 'MUON':
'COOLONL_MUON',
191 'MUON_ONL':
'COOLONL_MUON',
192 'MUONALIGN':
'COOLONL_MUONALIGN',
193 'MUONALIGN_ONL':
'COOLONL_MUONALIGN',
195 'MDT_ONL':
'COOLONL_MDT',
197 'RPC_ONL':
'COOLONL_RPC',
199 'TGC_ONL':
'COOLONL_TGC',
201 'CSC_ONL':
'COOLONL_CSC',
202 'TDAQ':
'COOLONL_TDAQ',
203 'TDAQ_ONL':
'COOLONL_TDAQ',
204 'GLOBAL':
'COOLONL_GLOBAL',
205 'GLOBAL_ONL':
'COOLONL_GLOBAL',
206 'TRIGGER':
'COOLONL_TRIGGER',
207 'TRIGGER_ONL':
'COOLONL_TRIGGER',
208 'CALO':
'COOLONL_CALO',
209 'CALO_ONL':
'COOLONL_CALO',
211 'FWD_ONL':
'COOLONL_FWD',
212 'INDET_OFL':
'COOLOFL_INDET',
213 'PIXEL_OFL':
'COOLOFL_PIXEL',
214 'SCT_OFL':
'COOLOFL_SCT',
215 'TRT_OFL':
'COOLOFL_TRT',
216 'LAR_OFL':
'COOLOFL_LAR',
217 'TILE_OFL':
'COOLOFL_TILE',
218 'MUON_OFL':
'COOLOFL_MUON',
219 'MUONALIGN_OFL':
'COOLOFL_MUONALIGN',
220 'MDT_OFL':
'COOLOFL_MDT',
221 'RPC_OFL':
'COOLOFL_RPC',
222 'TGC_OFL':
'COOLOFL_TGC',
223 'CSC_OFL':
'COOLOFL_CSC',
224 'TDAQ_OFL':
'COOLOFL_TDAQ',
225 'DCS_OFL':
'COOLOFL_DCS',
226 'GLOBAL_OFL':
'COOLOFL_GLOBAL',
227 'TRIGGER_OFL':
'COOLOFL_TRIGGER',
228 'CALO_OFL':
'COOLOFL_CALO',
229 'FWD_OFL':
'COOLOFL_FWD'
234 """Add a tag override for the specified folder"""
237 suffix = f
' <db>{db}</db>'
238 return IOVDbSvcCfg(flags, overrideTags=(f
'<prefix>{folder}</prefix> <tag>{tag}</tag>{suffix}',))
242 """Extract the folder name (non-XML text) from a IOVDbSvc.Folders entry"""
246 while ix < len(folderString):
247 if (folderString[ix] ==
'<' and xmlTag ==
''):
248 ix2 = folderString.find(
'>', ix)
250 xmlTag = folderString[ix + 1 : ix2].strip()
252 elif folderString[ix:ix+2] ==
'</' and xmlTag !=
'':
253 ix2 = folderString.find(
'>', ix)
258 ix2 = folderString.find(
'<', ix)
260 ix2 = len(folderString)
262 folderName = folderName + folderString[ix : ix2]
264 return folderName.strip()
269 if sqliteInput ==
"":
return []
271 if isinstance(takeFolders, str):
272 takeFolders=[takeFolders,]
273 dbStr=
"sqlite://;schema="+ sqliteInput+
";dbname="+databaseInstance
274 from PyCool
import cool
275 dbSvc = cool.DatabaseSvcFactory.databaseService()
276 db = dbSvc.openDatabase(dbStr)
277 nodelist=db.listAllNodes()
278 for node
in nodelist:
279 if db.existsFolder(node):
280 if (len(takeFolders)>0
and str(node)
not in takeFolders):
continue
281 connStr=
"<db>"+dbStr+
"</db>"
283 if f.versioningMode
is not cool.FolderVersioning.SINGLE_VERSION:
286 connStr+=
"<tag>"+tags[0]+
"</tag>"
287 sqliteFolders[
str(node)]=connStr
290 if len(takeFolders)>0:
291 missedFolders=
set(takeFolders)-
set(sqliteFolders.keys())
292 if len(missedFolders):
293 msg.error(
"The following folders were requested via the flag IOVSvc.sqliteFolder but not found in the sqlite file %s",(sqliteInput))
294 for f
in missedFolders:
297 msg.info(
"The following folders/tags are read from sqlite:")
298 for v
in sqliteFolders.items():
299 msg.info(
"\t"+
str(v))
303 if __name__ ==
'__main__':
304 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
305 from AthenaConfiguration.TestDefaults
import defaultTestFiles
307 flags.Input.Files = defaultTestFiles.RAW_RUN2
312 with open(
'test.pkl',
'wb')
as f: