3 from AthenaCommon
import Logging
26 Logging.log.verbose(
"-> close DB connection")
32 svc = coral.ConnectionService()
33 svcconfig = svc.configuration()
34 svcconfig.disablePoolAutomaticCleanUp()
35 svcconfig.setConnectionTimeOut(0)
38 if not (
'FRONTIER_SERVER' in os.environ
and os.environ[
'FRONTIER_SERVER']):
39 svcconfig.setConnectionRetrialPeriod(1)
40 svcconfig.setConnectionRetrialTimeOut(1)
42 svcconfig.setConnectionRetrialPeriod(300)
43 svcconfig.setConnectionRetrialTimeOut(3600)
45 self.
dbSession = svc.connect(
'ATLASDD', accessMode = coral.access_ReadOnly )
46 transaction = self.
dbSession.transaction()
49 transaction.start(
True)
59 """ Read the geometry Id corresponding to the geometry tag name in order to collect the child node Id's """
61 query = self.
dbSchema.tableHandle(
"HVS_TAG2NODE").newQuery()
63 query.addToOutputList(
'TAG_NAME')
64 query.addToOutputList(
'TAG_ID')
66 bindstag2node = coral.AttributeList()
67 bindstag2node.extend(
'tagN',
'string')
68 bindstag2node[0].setData(self.
dbGeoTag)
69 condString=
'TAG_NAME=:tagN'
71 query.setCondition(condString,bindstag2node)
73 for currentRow
in iter(query.execute()):
74 for i
in range(0,currentRow.size()):
75 if currentRow[i].specification().
name()==
"TAG_ID":
76 Logging.log.verbose(
"*** GeoTagId ******** "+
str(currentRow))
85 """ Analyze request output -> return a list of dictionaries and a list of parameter types """
92 for row
in iter(request.execute()):
95 for j
in range(0,row.size()):
96 name=row[j].specification().
name()
97 paramType=row[j].specification().
typeName()
101 if iCmpt==0: typeList.append((name,paramType))
103 dataList.append(dictLoc)
107 return dataList,typeList
113 v=[d[paramName]
for paramName,tmp
in typeList
if paramName!=keyName]
116 return dataDict,typeList
120 """ Read tag and node versions defined for the geometry tag """
129 Logging.log.error(
"The geometry tag %s could not be found in the database.", self.
dbGeoTag)
130 Logging.log.error(
"Its name might be misspelled and/or the script might access a local DB that is not up to date.")
138 while not bStopLoop :
142 query0.addToOutputList(
'C.NODE_NAME',
"nodename")
143 query0.addToOutputList(
'A.TAG_NAME',
"tagname")
144 query0.addToOutputList(
'A.TAG_ID',
"tagid")
146 query0.addToTableList(
"HVS_TAG2NODE",
"A" )
147 query0.addToTableList(
"HVS_LTAG2LTAG",
"B")
148 query0.addToTableList(
"HVS_NODE",
"C" )
150 bindstag2node = coral.AttributeList()
151 condString=
"C.NODE_ID=A.NODE_ID AND A.TAG_ID=B.CHILD_TAG and B.PARENT_TAG IN (%s)" %
str(tagIdList)[1:-1]
152 Logging.log.verbose(
"----------------------------\n"+condString)
153 query0.setCondition(condString,bindstag2node)
157 tagDictGbl.update(dictRes)
160 if len(dictRes.keys())==0:
165 tagIdList=[
int(dictRes[k][1])
for k
in dictRes.keys()]
172 """ Read a DB table content and return 3 lists :
173 - dbId : the data_id list corresponding to each entry in the table
174 - dbContent : the table values as a dictionary with keys corresponding to the dbId list
175 - paramName : the name of the table parameters """
177 upLeafName=leafName.upper()
184 return dbId,dbContent,paramName
190 query = self.
dbSchema.tableHandle(upLeafName+
"_DATA2TAG").newQuery()
191 query.addToOutputList(upLeafName+
'_DATA_ID')
193 bindstag2node = coral.AttributeList()
194 condString=upLeafName+
'_TAG_ID='+
str(leafTagId)
195 query.setCondition(condString,bindstag2node)
198 dataIdList=[
int(s[upLeafName+
'_DATA_ID'])
for s
in dictRes]
203 query = self.
dbSchema.tableHandle(upLeafName+
"_DATA").newQuery()
205 condString=upLeafName+
'_DATA_ID IN ('+
str(dataIdList)[1:-1]+
") ORDER BY "+upLeafName+
"_DATA_ID"
206 query.setCondition(condString,bindstag2node)
216 paramName=[s[0]
for s
in typeList]
218 paramKey=typeList[0][0]
224 v=[s[k[0]]
for k
in typeList]
227 return dbId,dbContent,paramName
237 def __init__(self,geoTag,sqliteDBFullPath,verbose=False):
245 from AthenaCommon.Utils.unixtools
import find_datafile
246 pathlist = os.getenv(
'CALIBPATH').
split(os.pathsep)
252 self.
db=sqlite3.connect(self.
dbFile)
253 except Exception
as e:
254 Logging.log.fatal(f
'Failed to open SQLite database {self.dbFile}. {e}')
255 Logging.log.debug(f
'Connected to SQLite database {self.dbFile}')
261 querystring =
"SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name='"+tableName+
"'"
262 cur.execute(querystring)
263 checkTable = cur.fetchall()
264 if len(checkTable)==0:
265 Logging.log.info(f
'Table {tableName} not found in the SQLite DB. Falling back on the default config')
270 querystring =
"SELECT * FROM "+tableName+
" order by "+tableName+
"_data_id"
271 cur.execute(querystring)
272 rows = cur.fetchall()
274 ncols=len(cur.description)
278 for i
in range(1,ncols):
279 dbDataRow[cur.description[i][0]]=row[i]
280 Logging.log.debug(f
'Fetched Data Row for {tableName}')
281 Logging.log.debug(f
'{dbDataRow}')
282 dbData.append(dbDataRow)