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)
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
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
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:]
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
435
std::vector< std::string > split(const std::string &s, const std::string &t=":")