ATLAS Offline Software
LArCalorimeter/LArExample/LArCalibProcessing/python/utils.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 from PyCool import cool
4 from AthenaCommon.Logging import logging
5 
6 
8 
9  _globalTag=""
10 
11  _defaultSuffix="-RUN2-UPD3-00"
12 
13  def __init__(self,dbname="COOLOFL_LAR/CONDBR2"):
14  dbSvc = cool.DatabaseSvcFactory.databaseService()
15  self._db = dbSvc.openDatabase(dbname)
16  self._msg=logging.getLogger('FolderTagResolver')
17  return
18 
19  def __del__(self):
20  self._db.closeDatabase()
21  return
22 
23  def getFolderTag(self,foldername,globalTag=None):
24  if globalTag is None:
25  globalTag=self.__class__._globalTag
26 
27  self._msg.info("Looking up folder level tags in %s",foldername) #using globalTag %s",foldername,globalTag)
28  foldertag= ''.join(foldername.split('/')) + self.__class__._defaultSuffix #default in case of failure
29 
30 
31  try:
32  folder=self._db.getFolder(foldername)
33  except cool.FolderNotFound:
34  self._msg.warning("\tCould not find folder %s in database %s",foldername,self._db.databaseId())
35  self._msg.warning("\tFalling back to default tag %s",foldertag)
36  return foldertag
37 
38 
39  taglist=folder.listTags()
40  if len(taglist)==1:
41  foldertag=taglist[0]
42  self._msg.info("\tFound single tag %s",foldertag)
43  return foldertag
44  else:
45  self._msg.info("\tTrying to resolve gobal tag %s",globalTag)
46  try:
47  foldertag=folder.resolveTag(globalTag)
48  self._msg.info("\tResolved tag %s",foldertag)
49  return foldertag
50  except cool.TagNotFound:
51  self._msg.warning("\tCould not resolve global tag %s",globalTag)
52  self._msg.warning("\tFalling back to default tag %s",foldertag)
53  pass
54  except cool.TagRelationNotFound:
55  self._msg.warning("\tCould not find tag relation to %s",globalTag)
56  self._msg.warning("\tFalling back to default tag %s",foldertag)
57  pass
58  return foldertag
59 
60 
61  def getFolderTagSuffix(self,foldername,globalTag=None):
62  ft=self.getFolderTag(foldername,globalTag)
63  if '_mu' in ft:
64  p=ft.find("_mu")
65  else:
66  p=ft.find("-")
67  if p==-1:
68  return "-Default"
69  else:
70  return ft[p:]
grepfile.info
info
Definition: grepfile.py:38
python.utils.FolderTagResolver.getFolderTagSuffix
def getFolderTagSuffix(self, foldername, globalTag=None)
Definition: LArCalorimeter/LArExample/LArCalibProcessing/python/utils.py:61
python.utils.FolderTagResolver.__init__
def __init__(self, dbname="COOLOFL_LAR/CONDBR2")
Definition: LArCalorimeter/LArExample/LArCalibProcessing/python/utils.py:13
python.utils.FolderTagResolver.__del__
def __del__(self)
Definition: LArCalorimeter/LArExample/LArCalibProcessing/python/utils.py:19
python.utils.FolderTagResolver.getFolderTag
def getFolderTag(self, foldername, globalTag=None)
Definition: LArCalorimeter/LArExample/LArCalibProcessing/python/utils.py:23
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.utils.FolderTagResolver
Definition: LArCalorimeter/LArExample/LArCalibProcessing/python/utils.py:7
python.utils.FolderTagResolver._msg
_msg
Definition: LArCalorimeter/LArExample/LArCalibProcessing/python/utils.py:16
python.utils.FolderTagResolver._db
_db
Definition: LArCalorimeter/LArExample/LArCalibProcessing/python/utils.py:15