ATLAS Offline Software
Loading...
Searching...
No Matches
python.IOVDbSvcConfig Namespace Reference

Functions

 CondInputLoaderCfg (flags, **kwargs)
 DBReplicaSvcCfg (flags, vetoDBRelease=False, **kwargs)
 IOVDbSvcCfg (flags, **kwargs)
 addFolders (flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers='')
 addFolderList (flags, listOfFolderInfoTuple, extensible=False, db=None, modifiers='')
 addFoldersSplitOnline (flags, detDb, onlineFolders, offlineFolders, className=None, extensible=False, addMCString='_OFL', splitMC=False, tag=None, forceDb=None, modifiers='')
 addOverride (flags, folder, tag, tagType="tag", db=None)
 _extractFolder (folderString)
 getSqliteContent (sqliteInput, takeFolders, databaseInstance)
 getCrestDirContent (flags)
 blockFolder (ca, folder)

Variables

 msg = logging.getLogger('IOVDbSvcCfg')
dict _dblist
 flags = initConfigFlags()
 Files
 acc = IOVDbSvcCfg(flags)

Function Documentation

◆ _extractFolder()

_extractFolder ( folderString)
protected
Extract the folder name (non-XML text) from a IOVDbSvc.Folders entry

Definition at line 256 of file IOVDbSvcConfig.py.

256def _extractFolder(folderString):
257 """Extract the folder name (non-XML text) from a IOVDbSvc.Folders entry"""
258 folderName = ''
259 xmlTag = ''
260 ix = 0
261 while ix < len(folderString):
262 if (folderString[ix] == '<' and xmlTag == ''):
263 ix2 = folderString.find('>', ix)
264 if ix2 != -1:
265 xmlTag = folderString[ix + 1 : ix2].strip()
266 ix = ix2 + 1
267 elif folderString[ix:ix+2] == '</' and xmlTag != '':
268 ix2 = folderString.find('>', ix)
269 if ix2 != -1:
270 xmlTag = ''
271 ix = ix2 + 1
272 else:
273 ix2 = folderString.find('<', ix)
274 if ix2 == -1:
275 ix2 = len(folderString)
276 if xmlTag == '':
277 folderName = folderName + folderString[ix : ix2]
278 ix = ix2
279 return folderName.strip()
280
281
282@cache #Fill only once

◆ addFolderList()

addFolderList ( flags,
listOfFolderInfoTuple,
extensible = False,
db = None,
modifiers = '' )
Add access to the given set of folders, in the identified subdetector schema.
FolerInfoTuple consists of (foldername,detDB,classname)

If EXTENSIBLE is set, then if we access an open-ended IOV at the end of the list,
the end time for this range will be set to just past the current event.
Subsequent accesses will update this end time for subsequent events.
This allows the possibility of later adding a new IOV using IOVSvc::setRange.

Definition at line 106 of file IOVDbSvcConfig.py.

106def addFolderList(flags, listOfFolderInfoTuple, extensible=False, db=None, modifiers=''):
107 """Add access to the given set of folders, in the identified subdetector schema.
108 FolerInfoTuple consists of (foldername,detDB,classname)
109
110 If EXTENSIBLE is set, then if we access an open-ended IOV at the end of the list,
111 the end time for this range will be set to just past the current event.
112 Subsequent accesses will update this end time for subsequent events.
113 This allows the possibility of later adding a new IOV using IOVSvc::setRange."""
114 loadFolders = set()
115 folders = []
116 sqliteFolders = dict()
117
118 if flags.IOVDb.SqliteInput:
119 if flags.IOVDb.UseCREST:
120 sqliteFolders = getCrestDirContent(flags)
121 else:
122 sqliteFolders = getSqliteContent(flags.IOVDb.SqliteInput,
123 flags.IOVDb.SqliteFolders,
124 flags.IOVDb.DatabaseInstance)
125
126 for (fs, detDb, className) in listOfFolderInfoTuple:
127 fse= _extractFolder(fs)
128 # Add class-name to CondInputLoader (if reqired)
129 if className is not None:
130 loadFolders.add((className, fse))
131
132 if fse in sqliteFolders:
133 msg.warning(f'Reading folder {fs} from local storage, bypassing production database')
134 fs += sqliteFolders[fse]
135 elif detDb is not None and fs.find('<db>') == -1:
136
137 if db: # override database name if provided
138 dbName=db
139 else:
140 dbName = flags.IOVDb.DatabaseInstance
141 if detDb in _dblist.keys():
142 fs = f'<db>{_dblist[detDb]}/{dbName}</db> {fs}'
143 elif os.access(detDb, os.R_OK):
144 # Assume slqite file
145 fs = f'<db>sqlite://;schema={detDb};dbname={dbName}</db> {fs}'
146 elif detDb.startswith("crest_fs:"):
147 fs = f'<db>{detDb}</db> {fs}'
148 else:
149 raise ConfigurationError(f'Error, db shorthand {detDb} not known, nor found as sqlite file')
150 # Append database string to folder-name
151
152 if extensible:
153 fs = fs + '<extensible/>'
154
155 # Add explicitly given xml-modifiers (like channel-selection)
156 fs += modifiers
157
158 # Append (modified) folder-name string to IOVDbSvc Folders property
159 folders.append(fs)
160
161
162 result = IOVDbSvcCfg(flags)
163 result.getPrimary().Folders+=folders
164 if loadFolders:
165 result.getCondAlgo('CondInputLoader').Load |= loadFolders
166
167 if flags.IOVDb.CleanerRingSize > 0:
168 #HLT-jobs set IOVDb.CleanerRingSize to 0 to run without the cleaning-service,
169 cleanerSvc = CompFactory.Athena.DelayedConditionsCleanerSvc(RingSize=flags.IOVDb.CleanerRingSize)
170 result.addService(cleanerSvc)
171 result.addService(CompFactory.Athena.ConditionsCleanerSvc(CleanerSvc=cleanerSvc))
172
173
174 return result
175
176
STL class.

◆ addFolders()

addFolders ( flags,
folderStrings,
detDb = None,
className = None,
extensible = False,
tag = None,
db = None,
modifiers = '' )

Definition at line 85 of file IOVDbSvcConfig.py.

85def addFolders(flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers=''):
86 tagString = ''
87 if tag is not None:
88 if flags.IOVDb.UseCREST:
89 tagString = '<ctag>%s</ctag>' % tag
90 else: #COOL variant
91 tagString = '<tag>%s</tag>' % tag
92
93 # Convenience hack: Allow a single string as parameter:
94 if isinstance(folderStrings, str):
95 return addFolderList(flags, ((folderStrings + tagString, detDb, className),), extensible, db, modifiers)
96
97 else: # Got a list of folders
98 folderDefinitions = []
99
100 for folderString in folderStrings:
101 folderDefinitions.append((folderString + tagString, detDb, className))
102
103 return addFolderList(flags, folderDefinitions, extensible, db, modifiers)
104
105

◆ addFoldersSplitOnline()

addFoldersSplitOnline ( flags,
detDb,
onlineFolders,
offlineFolders,
className = None,
extensible = False,
addMCString = '_OFL',
splitMC = False,
tag = None,
forceDb = None,
modifiers = '' )
Add access to given folder, using either online_folder  or offline_folder. For MC, add addMCString as a postfix (default is _OFL)

Definition at line 177 of file IOVDbSvcConfig.py.

177def addFoldersSplitOnline(flags, detDb, onlineFolders, offlineFolders, className=None, extensible=False, addMCString='_OFL', splitMC=False, tag=None, forceDb=None, modifiers=''):
178 """Add access to given folder, using either online_folder or offline_folder. For MC, add addMCString as a postfix (default is _OFL)"""
179
180 if flags.Common.isOnline and not flags.Input.isMC:
181 folders = onlineFolders
182 elif splitMC and not flags.Input.isMC:
183 folders = onlineFolders
184 else:
185 # MC, so add addMCString
186 detDb = detDb + addMCString
187 folders = offlineFolders
188
189 return addFolders(flags, folders, detDb, className, extensible, tag=tag, db=forceDb, modifiers=modifiers)
190
191

◆ addOverride()

addOverride ( flags,
folder,
tag,
tagType = "tag",
db = None )
Add xml override for the specified folder (folder-level tag, forceRunNumber, ...)

Definition at line 248 of file IOVDbSvcConfig.py.

248def addOverride(flags, folder, tag, tagType="tag", db=None):
249 """Add xml override for the specified folder (folder-level tag, forceRunNumber, ...)"""
250 suffix = ''
251 if db:
252 suffix = f' <db>{db}</db>'
253 return IOVDbSvcCfg(flags, overrideTags=(f'<prefix>{folder}</prefix> <{tagType}>{tag}</{tagType}>{suffix}',))
254
255

◆ blockFolder()

blockFolder ( ca,
folder )

Definition at line 436 of file IOVDbSvcConfig.py.

436def blockFolder(ca,folder):
437 "Block use of specified conditions DB folder so data can be read from elsewhere"
438 msg.info("Trying to remove folder [%s] from IOVDbSvc.Folders",folder)
439 iovdbsvc=ca.getService("IOVDbSvc")
440 oldLen=len(iovdbsvc.Folders)
441 iovdbsvc.Folders=[x for x in iovdbsvc.Folders if x.find(folder)==-1]
442 newLen=len(iovdbsvc.Folders)
443 if (oldLen==newLen):
444 msg.warning("Folder [%s] not found in IOVDbSvc.Folder",folder)
445 return
446 elif (oldLen-newLen>1):
447 msg.warning("Folder string [%s] matched more than one folder, removed %i folders",folder,oldLen-newLen)
448
449
450 condInputLoader=ca.getCondAlgo("CondInputLoader")
451 condInputLoader.Load=set([x for x in condInputLoader.Load if x[1].find(folder)==-1])
452 return
453
454
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140

◆ CondInputLoaderCfg()

CondInputLoaderCfg ( flags,
** kwargs )

Definition at line 12 of file IOVDbSvcConfig.py.

12def CondInputLoaderCfg(flags, **kwargs):
13 result = ComponentAccumulator()
14 result.addCondAlgo(CompFactory.CondInputLoader(**kwargs))
15 return result
16
17

◆ DBReplicaSvcCfg()

DBReplicaSvcCfg ( flags,
vetoDBRelease = False,
** kwargs )

Definition at line 18 of file IOVDbSvcConfig.py.

18def DBReplicaSvcCfg(flags, vetoDBRelease=False, **kwargs):
19 if vetoDBRelease:
20 kwargs.setdefault('COOLSQLiteVetoPattern', '/DBRelease/')
21
22 result = ComponentAccumulator()
23 result.addService(CompFactory.DBReplicaSvc(**kwargs),create=True)
24 return result
25
26
27@AccumulatorCache

◆ getCrestDirContent()

getCrestDirContent ( flags)
The CREST version of getSqliteContent. 
Signficantly more complicated because CREST has no folder (only tags)
If there is a global tag table defined in the local crest directly, 
we'll try to use it. 
Otherwise, open the production DB and guess the tag based on the first part of 
the folder name. Works only if the tag-naming convention is respected:
Folder /LAR/ElecCalib/Ramps becomes LARElecCalibRamps-suffix 

Definition at line 320 of file IOVDbSvcConfig.py.

320def getCrestDirContent(flags):
321 """The CREST version of getSqliteContent.
322 Signficantly more complicated because CREST has no folder (only tags)
323 If there is a global tag table defined in the local crest directly,
324 we'll try to use it.
325 Otherwise, open the production DB and guess the tag based on the first part of
326 the folder name. Works only if the tag-naming convention is respected:
327 Folder /LAR/ElecCalib/Ramps becomes LARElecCalibRamps-suffix
328 """
329
330 crestDir=flags.IOVDb.SqliteInput
331 if crestDir == "": return dict()
332 requestedTags=flags.IOVDb.SqliteFolders
333 localCrestFolders=dict()
334
335 if len(crestDir.split(":"))==1:
336 crestDir="crest_fs:"+crestDir
337
338 missedTags=set(requestedTags) #copy of the tags
339
340 try:
341 import chai
342 except ImportError as e:
343 msg.error("Cannot import chai, can not inspect local crest directory %s",crestDir)
344 raise e
345
346 try:
347 localdb = chai.Database(crestDir)
348 except Exception as e:
349 msg.error("Failed to connect to crest directoy %s",crestDir)
350 raise e
351
352 #see if there is a global-tag defined in the local CREST dir:
353 localGTs=[]
354 localGT=None
355 try:
356 localGTs=localdb.find_global_tags()
357 except RuntimeError:
358 pass
359
360 if len(localGTs)==1:
361 localGT=localGTs[0]
362 msg.info("Found exactly one global tag in local crest directory: [%s] Try to use it.",localGT)
363 elif len(localGTs)>1:
364 if flags.IOVDb.GlobalTag in localGTs:
365 localGT=flags.IOVDb.GlobalTag
366 msg.info("Global tag %s also defined in local crest directory. Try to use it.",flags.IOVDb.GlobalTag)
367 else:
368 msg.warning("More than one global tag found in crest directory [%s], none matches the global conditions tag %s",
369 crestDir,flags.IOVDb.GlobalTag)
370 if localGT:
371 gt=localdb.get_global_tag(localGT)
372 resolvedTags= gt.resolve_all_tags()
373 for gt2ft in resolvedTags.items():
374 f=gt2ft[0][0]
375 lt=gt2ft[1]
376 if len(requestedTags)>0 and lt not in requestedTags: continue
377 localCrestFolders[f]="<db>"+crestDir+"</db><ctag>"+lt+"</ctag>"
378 missedTags.discard(lt)
379 else:
380 #No local tag hierachy defined. Try to make guesses based on tag hierary in the production db:
381 msg.warning("No (usable) global tag found in local crest directory %s. Open production db, try to guess folder-tag relation")
382 localtags=set(localdb.find_tags())
383
384 try:
385 proddb=chai.Database("crest:"+flags.IOVDb.DBConnection)
386 except Exception as e:
387 msg.error("Failed to connect to crest server %s",flags.IOVDb.CrestServer)
388 raise e
389
390 gt=proddb.get_global_tag(flags.IOVDb.GlobalTag)
391
392 resolvedTags=gt.resolve_all_tags()
393 folderstubToFolderMap={}
394 tbl=str.maketrans(".","-")
395 for gt2ft in resolvedTags.items():
396 f=gt2ft[0][0]
397 ft=gt2ft[1]
398 if ft.startswith("UPGRADE_"): ft=ft[8:] #No idea why we prepend this string ...
399 folderstub="".join(f.split("/")).lower()
400 tagstub=ft.translate(tbl).split("-")[0].lower()
401 if (tagstub != folderstub):
402 msg.warning("Folder-tag %s of folder %s in the production DB does not follow tag naming convention",ft, f)
403
404 folderstubToFolderMap[folderstub]=f
405
406 for lt in localtags:
407 if len(requestedTags)>0 and lt not in requestedTags: continue
408 tagstub=lt.translate(tbl).split("-")[0].lower()
409 if tagstub in folderstubToFolderMap:
410 f=folderstubToFolderMap[tagstub]
411 localCrestFolders[f]="<db>"+crestDir+"</db><ctag>"+lt+"</ctag>"
412 missedTags.discard(lt)
413 else:
414 msg.warning("Cannot guess the folder of the tag %s in the local CREST directory %s",lt,crestDir)
415 msg.warning("Ignoring this tag")
416
417
418 msg.info("The following folders/tags are read from local crest directory:")
419 for v in localCrestFolders.items():
420 msg.info("\t"+str(v))
421 if len(missedTags):
422 msg.error("The following local Crest tags have been explicitly requested via the flag IOVSvc.sqliteFolder but not found in the local crest directory %s",(crestDir))
423 for mt in missedTags:
424 msg.error("\t%s",mt)
425
426 return localCrestFolders
427
428
429
430
431
432
433
434#post-exec-style helper method to remove a folder from IOVDbSvc.Folders and CondInputLoader.Load
435#To be used in calibration-processing jobs that read the condions from anohter source or produce it in the same job
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ getSqliteContent()

getSqliteContent ( sqliteInput,
takeFolders,
databaseInstance )

Definition at line 283 of file IOVDbSvcConfig.py.

283def getSqliteContent(sqliteInput,takeFolders,databaseInstance):
284 if sqliteInput == "": return dict()
285 sqliteFolders=dict()
286 if isinstance(takeFolders, str):
287 takeFolders=[takeFolders,]
288 dbStr="sqlite://;schema="+ sqliteInput+";dbname="+databaseInstance
289 from PyCool import cool
290 dbSvc = cool.DatabaseSvcFactory.databaseService()
291 db = dbSvc.openDatabase(dbStr)
292 nodelist=db.listAllNodes()
293 for node in nodelist:
294 if db.existsFolder(node):
295 if (len(takeFolders)>0 and str(node) not in takeFolders): continue
296 connStr="<db>"+dbStr+"</db>"
297 f=db.getFolder(node)
298 if f.versioningMode is not cool.FolderVersioning.SINGLE_VERSION:
299 tags=f.listTags()
300 if len(tags)==1:
301 connStr+="<tag>"+tags[0]+"</tag>"
302 sqliteFolders[str(node)]=connStr
303 db.closeDatabase()
304
305 if len(takeFolders)>0:
306 missedFolders=set(takeFolders)-set(sqliteFolders.keys())
307 if len(missedFolders):
308 msg.error("The following folders were requested via the flag IOVSvc.sqliteFolder but not found in the sqlite file %s",(sqliteInput))
309 for f in missedFolders:
310 msg.error(f)
311
312 msg.info("The following folders/tags are read from sqlite:")
313 for v in sqliteFolders.items():
314 msg.info("\t"+str(v))
315 return sqliteFolders
316
317
318
319@AccumulatorCache #Fill only once

◆ IOVDbSvcCfg()

IOVDbSvcCfg ( flags,
** kwargs )

Definition at line 28 of file IOVDbSvcConfig.py.

28def IOVDbSvcCfg(flags, **kwargs):
29 # Add the conditions loader, must be the first in the sequence
30 result = CondInputLoaderCfg(flags)
31
32 kwargs.setdefault('OnlineMode', flags.Common.isOnline)
33 kwargs.setdefault('dbConnection', flags.IOVDb.DBConnection)
34 # setup knowledge of dbinstance in IOVDbSvc, for global tag x-check
35 kwargs.setdefault('DBInstance', flags.IOVDb.DatabaseInstance)
36
37 if 'FRONTIER_SERVER' in os.environ.keys() and os.environ['FRONTIER_SERVER'] != '':
38 kwargs.setdefault('CacheAlign', 3)
39
40 # Very important cache settings for use of CoralProxy at P1 (ATR-4646)
41 if flags.Common.isOnline and flags.Trigger.Online.isPartition:
42 kwargs['CacheAlign'] = 0
43 kwargs['CacheRun'] = 0
44 kwargs['CacheTime'] = 0
45
46 kwargs.setdefault('GlobalTag', flags.IOVDb.GlobalTag)
47 if 'Folders' in kwargs:
48 kwargs['Folders'] = ['/TagInfo<metaOnly/>'] + kwargs['Folders']
49 else:
50 kwargs.setdefault('Folders', ['/TagInfo<metaOnly/>'])
51
52 # Select CREST backend if needed
53 if flags.IOVDb.UseCREST:
54 kwargs.setdefault('Source', 'CREST')
55
56 result.addService(CompFactory.IOVDbSvc(**kwargs), primary=True)
57
58 # Set up POOLSvc with appropriate catalogs
59 from AthenaPoolCnvSvc.PoolCommonConfig import PoolSvcCfg
60 result.merge(PoolSvcCfg(flags, withCatalogs=True))
61 if flags.MP.UseSharedReader or flags.MP.UseSharedWriter:
62 from AthenaPoolCnvSvc.PoolCommonConfig import AthenaPoolSharedIOCnvSvcCfg
63 result.merge(AthenaPoolSharedIOCnvSvcCfg(flags))
64 else:
65 from AthenaPoolCnvSvc.PoolCommonConfig import AthenaPoolCnvSvcCfg
66 result.merge(AthenaPoolCnvSvcCfg(flags))
67 result.addService(CompFactory.CondSvc())
68 result.addService(CompFactory.ProxyProviderSvc(ProviderNames=['IOVDbSvc']))
69
70 if not flags.IOVDb.UseCREST:
71 result.merge(DBReplicaSvcCfg(flags, vetoDBRelease=not flags.Input.isMC))
72
73 # Get TagInfoMgr
74 from EventInfoMgt.TagInfoMgrConfig import TagInfoMgrCfg
75 result.merge(TagInfoMgrCfg(flags))
76
77 # Set up MetaDataSvc
78 from AthenaServices.MetaDataSvcConfig import MetaDataSvcCfg
79 result.merge(MetaDataSvcCfg(flags, ['IOVDbMetaDataTool']))
80
81 return result
82
83
84# Convenience method to add folders:

Variable Documentation

◆ _dblist

dict python.IOVDbSvcConfig._dblist
protected

Definition at line 192 of file IOVDbSvcConfig.py.

◆ acc

python.IOVDbSvcConfig.acc = IOVDbSvcCfg(flags)

Definition at line 462 of file IOVDbSvcConfig.py.

◆ Files

python.IOVDbSvcConfig.Files

Definition at line 459 of file IOVDbSvcConfig.py.

◆ flags

python.IOVDbSvcConfig.flags = initConfigFlags()

Definition at line 458 of file IOVDbSvcConfig.py.

◆ msg

python.IOVDbSvcConfig.msg = logging.getLogger('IOVDbSvcCfg')

Definition at line 10 of file IOVDbSvcConfig.py.