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