ATLAS Offline Software
getCurrentFolderTag.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 
5 import sys
6 
7 from PyCool import cool
8 sys.path.append('/afs/cern.ch/user/a/atlcond/utils22')
9 from CondUtilsLib.AtlCoolBKLib import resolveAlias
10 
11 def getCurrentFolderTag(dbname,folderName,ES=False):
12  current=None
13  next=None
14 
15  #1. Get current and next global tags using resolver class in ~atlcond
16  resolver=resolveAlias()
17  if(ES):
18  currentGlobal=resolver.getCurrentES().replace("*","ST")
19  nextGlobal=resolver.getNextES().replace("*","ST")
20  else:
21  currentGlobal=resolver.getCurrent().replace("*","ST")
22  nextGlobal=resolver.getNext().replace("*","ST")
23 
24  print('currentGlobal: ',currentGlobal)
25  #2. Open the DB to resolve this gobal tag for the given folder
26  dbSvc = cool.DatabaseSvcFactory.databaseService()
27  db = dbSvc.openDatabase(dbname)
28  f=db.getFolder(folderName)
29  try:
30  current=f.resolveTag(currentGlobal)
31  except Exception:
32  print('Warning: could not resolve ',currentGlobal,' in db: ',dbname)
33  if "DBR2" in dbname:
34  print('resolving for the global CONDBR2-BLKPA-2022-10')
35  tmpGlobal='CONDBR2-BLKPA-2022-10'
36  else:
37  print('resolving for the global COMCOND-BLKPA-RUN1-06')
38  tmpGlobal='COMCOND-BLKPA-RUN1-06'
39 
40  try:
41  current=f.resolveTag(tmpGlobal)
42  except Exception:
43  print('Also not working, giving up')
44  pass
45  pass
46 
47  if len(nextGlobal)>2:
48  # NEXT exists, try to resolve it
49  try:
50  next=f.resolveTag(nextGlobal)
51  except Exception:
52  pass
53  pass
54 
55  db.closeDatabase()
56  return (current,next)
57 
58 
59 if __name__=="__main__":
60  if len(sys.argv)<3:
61  sys.stderr.write("Usage: %s dbname folder\n" % sys.argv[0].split("/")[-1])
62  sys.exit(-1)
63 
64  dn=sys.argv[1]
65  fn=sys.argv[2]
66  if len(sys.argv)>3:
67  estag=sys.argv[3]
68  else:
69  estag=False
70 
71  currTag=getCurrentFolderTag(dn,fn,estag)[0]
72 
73  if currTag is None:
74  sys.stderr.write("Failed to resolve current folder-level tag for folder %s in db %s\n" % (fn,dn))
75  sys.exit(-1)
76 
77  print(currTag)
78 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.getCurrentFolderTag.getCurrentFolderTag
def getCurrentFolderTag(dbname, folderName, ES=False)
Definition: getCurrentFolderTag.py:11
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
Trk::split
@ split
Definition: LayerMaterialProperties.h:38