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()

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

Definition at line 254 of file IOVDbSvcConfig.py.

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

◆ addFolderList()

python.IOVDbSvcConfig.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 107 of file IOVDbSvcConfig.py.

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

◆ addFolders()

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

Definition at line 86 of file IOVDbSvcConfig.py.

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

◆ addFoldersSplitOnline()

python.IOVDbSvcConfig.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 175 of file IOVDbSvcConfig.py.

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

◆ addOverride()

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

Definition at line 246 of file IOVDbSvcConfig.py.

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

◆ blockFolder()

python.IOVDbSvcConfig.blockFolder ( ca,
folder )

Definition at line 429 of file IOVDbSvcConfig.py.

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

◆ CondInputLoaderCfg()

python.IOVDbSvcConfig.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()

python.IOVDbSvcConfig.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))
24 return result
25
26
27@AccumulatorCache

◆ getCrestDirContent()

python.IOVDbSvcConfig.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 318 of file IOVDbSvcConfig.py.

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

python.IOVDbSvcConfig.getSqliteContent ( sqliteInput,
takeFolders,
databaseInstance )

Definition at line 281 of file IOVDbSvcConfig.py.

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

◆ IOVDbSvcCfg()

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

Variable Documentation

◆ _dblist

dict python.IOVDbSvcConfig._dblist
protected

Definition at line 190 of file IOVDbSvcConfig.py.

◆ acc

python.IOVDbSvcConfig.acc = IOVDbSvcCfg(flags)

Definition at line 456 of file IOVDbSvcConfig.py.

◆ Files

python.IOVDbSvcConfig.Files

Definition at line 453 of file IOVDbSvcConfig.py.

◆ flags

python.IOVDbSvcConfig.flags = initConfigFlags()

Definition at line 452 of file IOVDbSvcConfig.py.

◆ msg

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

Definition at line 10 of file IOVDbSvcConfig.py.