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