ATLAS Offline Software
Classes | Functions | Variables
python.CaloCondTools Namespace Reference

Classes

class  CaloBlobReader
 
class  CaloBlobWriter
 

Functions

def getCaloPrefix ()
 
def getAthenaFolderDescr ()
 
def getAthenaFolderType (folderDescr)
 
def openDb (db, instance, mode="READONLY", schema="COOLOFL_CALO", sqlfn="caloSqlite.db")
 
def openDbConn (connStr, mode="READONLY")
 
def iovFromRunLumi (runNum, lbkNum)
 
def decodeTimeString (timeString)
 
def getCoolValidityKey (pointInTime, isSince=True)
 
def getCellHash (detectorId, part, module, sample, tower)
 

Variables

 g = cppyy.gbl
 
 log = getLogger("CaloCondTools")
 
int MINRUN = 0
 
int MINLBK = 0
 
 MAXRUN = cool.Int32Max
 
 MAXLBK = cool.UInt32Max
 
int UNIX2COOL = 1000000000
 
 UNIXTMAX = cool.Int32Max
 

Function Documentation

◆ decodeTimeString()

def python.CaloCondTools.decodeTimeString (   timeString)
Returns UNIX time stamp given an input time string

Definition at line 187 of file CaloCondTools.py.

187 def decodeTimeString(timeString):
188  """
189  Returns UNIX time stamp given an input time string
190  """
191  return int(time.mktime(time.strptime(timeString,"%Y-%m-%d %H:%M:%S")))
192 
193 #
194 #______________________________________________________________________

◆ getAthenaFolderDescr()

def python.CaloCondTools.getAthenaFolderDescr ( )
Returns the run-lumi type folder description needed to read back the folder content
as a CondAttrListCollection in Athena.

Definition at line 40 of file CaloCondTools.py.

41  """
42  Returns the run-lumi type folder description needed to read back the folder content
43  as a CondAttrListCollection in Athena.
44  """
45  desc ='<timeStamp>run-lumi</timeStamp>'
46  desc+='<addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader>'
47  desc+='<typeName>CondAttrListCollection</typeName>'
48  return desc
49 
50 #
51 #______________________________________________________________________

◆ getAthenaFolderType()

def python.CaloCondTools.getAthenaFolderType (   folderDescr)

Definition at line 52 of file CaloCondTools.py.

52 def getAthenaFolderType(folderDescr):
53  type = re.compile(".*<timeStamp>(.*)</timeStamp>.*").search(folderDescr)
54  if not type:
55  raise Exception("No folder type info found in \'%s\'" % folderDescr)
56  return type.groups()[0]
57 
58 #
59 #______________________________________________________________________

◆ getCaloPrefix()

def python.CaloCondTools.getCaloPrefix ( )
Returns the common Calo prefix used for all COOL folders

Definition at line 32 of file CaloCondTools.py.

32 def getCaloPrefix():
33  """
34  Returns the common Calo prefix used for all COOL folders
35  """
36  return "/CALO/"
37 
38 #
39 #______________________________________________________________________

◆ getCellHash()

def python.CaloCondTools.getCellHash (   detectorId,
  part,
  module,
  sample,
  tower 
)
Returns cell subHash given partition,module,sample, and tower (TILE only)

Definition at line 228 of file CaloCondTools.py.

228 def getCellHash(detectorId,part,module,sample,tower):
229  """
230  Returns cell subHash given partition,module,sample, and tower (TILE only)
231  """
232  if detectorId != 48:
233  raise Exception('getCellHash only available for TileCells.')
234  section = 0 # 1=LB* 2=EB* 3=ITC
235  side = 0 # 1=A-side -1=C-side
236  if part == 1 or part == 2:
237  section = 1
238  elif part == 3 or part == 4:
239  if sample == 3 or (sample==1 and tower==9) or (sample==2 and tower==8): # Gap and ITC
240  section = 3
241  else:
242  section = 2
243  if part%2 ==0:
244  side = -1
245  else:
246  side = 1
247  if section==0 or side==0 or module>63 or sample>3 or tower>15:
248  raise Exception('Non-physical cell specification')
249 
250  # hash array for mod0 of entire TileCal. Use to determine cell hash for any cell
251  hash = [0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, -1, -1, 14, 15, 16, -1, 17, 18, -1, -1, 19, 20, 4416, -1, 21, 4417, -1, -1, -1, 2880, 2881, 4418, 2882, 2883, -1, 4419, 2884, 2885, 2886, -1, 2887, 2888, -1, 4420, 2889, 2890, -1, -1, 2891, -1, -1, 4421, 1408, 1409, 1410, -1, 1411, 1412, -1, -1, 1413, 1414, 1415, -1, 1416, 1417, -1, -1, 1418, 1419, 1420, -1, 1421, 1422, -1, -1, 1423, 1424, 1425, -1, 1426, 1427, -1, -1, 1428, 1429, 4800, -1, 1430, 4801, -1, -1, -1, 3648, 3649, 4802, 3650, 3651, -1, 4803, 3652, 3653, 3654, -1, 3655, 3656, -1, 4804, 3657, 3658, -1, -1, 3659, -1, -1, 4805]
252 
253  # Section specific offset to be added to cell hash for module different from 0
254  # [LBC,LBA,EBC,EBA,ITC-C,ITC-A]
255  modOffset = [22,23,12,12,6,6]
256  if side==1:
257  sideOffset=1
258  else:
259  sideOffset=0
260 
261  return hash[sideOffset*16*4+tower*4+sample]+modOffset[sideOffset+2*(section-1)]*module
262 
263 #======================================================================
264 #===
265 #=== CaloBlobReader
266 #===
267 #======================================================================
268 
269 #
270 #______________________________________________________________________

◆ getCoolValidityKey()

def python.CaloCondTools.getCoolValidityKey (   pointInTime,
  isSince = True 
)
The interpretation of pointInTime depends on their type:
- tuple(int,int) : run and lbk number 
- integer        : Values are interpreted as unix time stamps
- string         : time stamp of format 'yyyy-mm-dd hh:mm:ss'

Definition at line 195 of file CaloCondTools.py.

195 def getCoolValidityKey(pointInTime, isSince=True):
196  """
197  The interpretation of pointInTime depends on their type:
198  - tuple(int,int) : run and lbk number
199  - integer : Values are interpreted as unix time stamps
200  - string : time stamp of format 'yyyy-mm-dd hh:mm:ss'
201  """
202 
203  validityKey = None
204 
205  #=== string: convert to unix time and treat as latter
206  if isinstance(pointInTime, str):
207  pointInTime = decodeTimeString(pointInTime)
208 
209  #=== integer: unix time stamp
210  if isinstance(pointInTime, int):
211  if pointInTime >=0:
212  validityKey = pointInTime * UNIX2COOL
213  else:
214  if isSince:
215  validityKey = int(time.time()) * UNIX2COOL
216  else :
217  validityKey = cool.ValidityKeyMax
218  #=== run-lumi tuple
219  elif isinstance(pointInTime, tuple):
220  validityKey = iovFromRunLumi(pointInTime[0],pointInTime[1])
221  #=== catch other types
222  else:
223  raise Exception("Unrecognized pointInTime type=%s" % type(pointInTime))
224  return cool.ValidityKey(validityKey)
225 
226 #
227 #______________________________________________________________________

◆ iovFromRunLumi()

def python.CaloCondTools.iovFromRunLumi (   runNum,
  lbkNum 
)
Returns COOL timeStamp build from run and lumi block numbers

Definition at line 179 of file CaloCondTools.py.

179 def iovFromRunLumi(runNum, lbkNum):
180  """
181  Returns COOL timeStamp build from run and lumi block numbers
182  """
183  return (int(runNum)<<32) + int(lbkNum)
184 
185 #
186 #______________________________________________________________________

◆ openDb()

def python.CaloCondTools.openDb (   db,
  instance,
  mode = "READONLY",
  schema = "COOLOFL_CALO",
  sqlfn = "caloSqlite.db" 
)
Opens a COOL db connection.
- db:       The DB type. The following names are recognized:
                * SQLITE: Opens file mentioned in sqlfn parameter
                * ORACLE or FRONTIER: Opens ORACLE DB, forces READONLY
- instance: One of valid instances - CONDBR2 OFLP200 COMP200 CMCP200
- mode:     Can be READONLY (default), RECREATE or UPDATE
- schema:   One of valid schemas - COOLONL_CALO COOLOFL_CALO COOLONL_LAR COOLOFL_LAR COOLONL_TILE COOLOFL_TILE
- sqlfn:    Name of sqlite file if db is SQLITE

Definition at line 60 of file CaloCondTools.py.

60 def openDb(db, instance, mode="READONLY", schema="COOLOFL_CALO", sqlfn="caloSqlite.db"):
61  """
62  Opens a COOL db connection.
63  - db: The DB type. The following names are recognized:
64  * SQLITE: Opens file mentioned in sqlfn parameter
65  * ORACLE or FRONTIER: Opens ORACLE DB, forces READONLY
66  - instance: One of valid instances - CONDBR2 OFLP200 COMP200 CMCP200
67  - mode: Can be READONLY (default), RECREATE or UPDATE
68  - schema: One of valid schemas - COOLONL_CALO COOLOFL_CALO COOLONL_LAR COOLOFL_LAR COOLONL_TILE COOLOFL_TILE
69  - sqlfn: Name of sqlite file if db is SQLITE
70  """
71  #=== check for valid db names
72  if db is not None:
73  validDb = ["SQLITE", "ORACLE", "FRONTIER"]
74  if db not in validDb:
75  raise Exception( "DB not valid: %s, valid DBs are: %s" % (db,validDb) )
76  elif db == "ORACLE" or db == "FRONTIER":
77  mode = "READONLY"
78 
79  #=== check for valid instance names
80  validInstance = ["COMP200", "CONDBR2", "CMCP200", "OFLP200"]
81  if instance not in validInstance:
82  raise Exception( "Instance not valid: %s, valid instance are: %s" % (instance,validInstance) )
83 
84  #=== check for valid schema names
85  validSchema = ["COOLONL_CALO","COOLOFL_CALO","COOLONL_LAR","COOLOFL_LAR","COOLONL_TILE","COOLOFL_TILE"]
86  if schema not in validSchema:
87  raise Exception( "Schema not valid: %s, valid schemas are: %s" % (schema,validSchema) )
88 
89  #=== construct connection string
90  connStr = ""
91  if db=='SQLITE':
92  if mode=="READONLY" and not os.path.exists(sqlfn):
93  raise Exception( "Sqlite file %s does not exist" % (sqlfn) )
94  if (mode=="RECREATE" or mode=="UPDATE") and not os.path.exists(os.path.dirname(sqlfn)):
95  dirn=os.path.dirname(sqlfn)
96  if dirn:
97  os.makedirs(dirn)
98  connStr="sqlite://X;schema=%s;dbname=%s" % (sqlfn,instance)
99  elif db=='FRONTIER':
100  connStr='frontier://ATLF/()/;schema=ATLAS_%s;dbname=%s' % (schema,instance)
101  elif db=='ORACLE':
102  connStr='oracle://%s;schema=ATLAS_%s;dbname=%s' % ('ATLAS_COOLPROD',schema,instance)
103  else:
104  connStr=schema+'/'+instance
105 
106  return openDbConn(connStr, mode)
107 
108 #
109 #______________________________________________________________________

◆ openDbConn()

def python.CaloCondTools.openDbConn (   connStr,
  mode = "READONLY" 
)
Opens a COOL db connection.
- connStr: The DB connection string
- mode:    Can be READONLY (default), RECREATE or UPDATE
           or ORACLE or FRONTIER if connStr is only short name of the database

Definition at line 110 of file CaloCondTools.py.

110 def openDbConn(connStr, mode="READONLY"):
111  """
112  Opens a COOL db connection.
113  - connStr: The DB connection string
114  - mode: Can be READONLY (default), RECREATE or UPDATE
115  or ORACLE or FRONTIER if connStr is only short name of the database
116  """
117 
118  #=== split the name into schema and dbinstance
119  splitname=connStr.split('/')
120  if (len(splitname)!=2): # string connection ready to be used as it is
121  connStr_new=connStr
122  else: # construct connection string
123  schema=splitname[0]
124  instance=splitname[1]
125  if mode=="ORACLE":
126  connStr_new='oracle://%s;schema=ATLAS_%s;dbname=%s' % ('ATLAS_COOLPROD',schema,instance)
127  else:
128  connStr_new='frontier://ATLF/()/;schema=ATLAS_%s;dbname=%s' % (schema,instance)
129 
130  #=== get dbSvc and print header info
131  dbSvc = cool.DatabaseSvcFactory.databaseService()
132  log.info( "---------------------------------------------------------------------------------" )
133  log.info( "-------------------------- CaloCondTools.openDbConn -----------------------------" )
134  log.info( "- using COOL version %s", dbSvc.serviceVersion() )
135  log.info( "- opening CaloDb: %s",connStr_new )
136  log.info( "- mode: %s", mode )
137  log.info( "---------------------------------------------------------------------------------" )
138 
139  #=== action depends on mode
140  if mode in ["READONLY","ORACLE","FRONTIER","",None]:
141  #=== open read only
142  try:
143  db=dbSvc.openDatabase(connStr_new,True)
144  except Exception as e:
145  log.debug( e )
146  log.critical("Could not connect to %s" % connStr_new )
147  return None
148  return db
149  elif mode=="RECREATE":
150  #=== recreating database
151  dbSvc.dropDatabase(connStr_new)
152  try:
153  db = dbSvc.createDatabase(connStr_new)
154  except Exception as e:
155  log.debug( e )
156  log.critical( "Could not create database, giving up..." )
157  return None
158  return db
159  elif mode=="UPDATE":
160  #=== update database
161  try:
162  db=dbSvc.openDatabase(connStr_new,False)
163  except Exception as e:
164  log.debug( e )
165  log.warning( "Could not connect to \'%s\', trying to create it....", connStr_new )
166  try:
167  db=dbSvc.createDatabase(connStr_new)
168  except Exception as e:
169  log.debug( e )
170  log.critical( "Could not create database, giving up..." )
171  return None
172  return db
173  else:
174  log.error("Mode \"%s\" not recognized", mode )
175  return None
176 
177 #
178 #______________________________________________________________________

Variable Documentation

◆ g

python.CaloCondTools.g = cppyy.gbl

Definition at line 15 of file CaloCondTools.py.

◆ log

python.CaloCondTools.log = getLogger("CaloCondTools")

Definition at line 20 of file CaloCondTools.py.

◆ MAXLBK

python.CaloCondTools.MAXLBK = cool.UInt32Max

Definition at line 26 of file CaloCondTools.py.

◆ MAXRUN

python.CaloCondTools.MAXRUN = cool.Int32Max

Definition at line 25 of file CaloCondTools.py.

◆ MINLBK

int python.CaloCondTools.MINLBK = 0

Definition at line 24 of file CaloCondTools.py.

◆ MINRUN

int python.CaloCondTools.MINRUN = 0

Definition at line 23 of file CaloCondTools.py.

◆ UNIX2COOL

int python.CaloCondTools.UNIX2COOL = 1000000000

Definition at line 27 of file CaloCondTools.py.

◆ UNIXTMAX

python.CaloCondTools.UNIXTMAX = cool.Int32Max

Definition at line 28 of file CaloCondTools.py.

python.CaloCondTools.getCellHash
def getCellHash(detectorId, part, module, sample, tower)
Definition: CaloCondTools.py:228
python.CaloCondTools.getAthenaFolderType
def getAthenaFolderType(folderDescr)
Definition: CaloCondTools.py:52
python.CaloCondTools.decodeTimeString
def decodeTimeString(timeString)
Definition: CaloCondTools.py:187
python.CaloCondTools.getCoolValidityKey
def getCoolValidityKey(pointInTime, isSince=True)
Definition: CaloCondTools.py:195
python.CaloCondTools.getAthenaFolderDescr
def getAthenaFolderDescr()
Definition: CaloCondTools.py:40
search
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Definition: hcg.cxx:738
python.CaloCondTools.openDbConn
def openDbConn(connStr, mode="READONLY")
Definition: CaloCondTools.py:110
readCCLHist.int
int
Definition: readCCLHist.py:84
python.CaloCondTools.openDb
def openDb(db, instance, mode="READONLY", schema="COOLOFL_CALO", sqlfn="caloSqlite.db")
Definition: CaloCondTools.py:60
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.CaloCondTools.getCaloPrefix
def getCaloPrefix()
Definition: CaloCondTools.py:32
python.CaloCondTools.iovFromRunLumi
def iovFromRunLumi(runNum, lbkNum)
Definition: CaloCondTools.py:179