Skip to content
Snippets Groups Projects
Commit c1c13f15 authored by Brian Petersen's avatar Brian Petersen
Browse files

Merge branch '21.1_add_new_trigdb_py_methods' into '21.1'

Add new TriggerDB python access methods and fix some which were broken in the move to Run 2

See merge request !3665
parents 2aac01ef d9091eb4
No related merge requests found
...@@ -83,7 +83,10 @@ class Session: ...@@ -83,7 +83,10 @@ class Session:
self.__fieldNames += [self.__session.assignString()] self.__fieldNames += [self.__session.assignString()]
self.__fieldTypeStr += [self.__session.assignString()] self.__fieldTypeStr += [self.__session.assignString()]
if self.__fieldTypeStr[-1].startswith("NUMBER"): if self.__fieldTypeStr[-1].startswith("NUMBER"):
self.__fieldType += [int] if ",0" in .__fieldTypeStr[-1]:
self.__fieldType += [int]
else:
self.__fieldType += [float]
elif self.__fieldTypeStr[-1].startswith("VARCHAR"): elif self.__fieldTypeStr[-1].startswith("VARCHAR"):
self.__fieldType += [str] self.__fieldType += [str]
else: else:
......
...@@ -50,7 +50,10 @@ class FrontierCursor2: ...@@ -50,7 +50,10 @@ class FrontierCursor2:
for var,val in bindvars.items(): for var,val in bindvars.items():
if query.find(":%s" % var)<0: if query.find(":%s" % var)<0:
raise NameError("variable '%s' is not a bound variable in this query: %s" % (var, query) ) raise NameError("variable '%s' is not a bound variable in this query: %s" % (var, query) )
query = query.replace(":%s" % var,"%r" % val) if type(val) == long:
query = query.replace(":%s" % var,"%s" % val)
else:
query = query.replace(":%s" % var,"%r" % val)
log.debug("Resolving bound variable '%s' with %r" % (var,val)) log.debug("Resolving bound variable '%s' with %r" % (var,val))
log.debug("Resolved query: %s" % query) log.debug("Resolved query: %s" % query)
return query return query
...@@ -218,7 +221,17 @@ Refresh cache: %s""" % (self.url, self.refreshFlag) ...@@ -218,7 +221,17 @@ Refresh cache: %s""" % (self.url, self.refreshFlag)
fields = [x for i,x in enumerate(firstRow.split()) if i%2==0] fields = [x for i,x in enumerate(firstRow.split()) if i%2==0]
types = [x for i,x in enumerate(firstRow.split()) if i%2==1] types = [x for i,x in enumerate(firstRow.split()) if i%2==1]
Nfields = len(fields) Nfields = len(fields)
ptypes = [int if t.startswith("NUMBER") else str for t in types] ptypes = []
for t in types:
if t.startswith("NUMBER"):
if ",0" in t:
ptypes.append(int)
else:
ptypes.append(float)
else:
ptypes.append(str)
log.debug("Fields : %r" % fields) log.debug("Fields : %r" % fields)
log.debug("DB Types : %r" % types) log.debug("DB Types : %r" % types)
log.debug("Python Types: %r" % ptypes) log.debug("Python Types: %r" % ptypes)
......
...@@ -610,9 +610,15 @@ def getChainsAndStreams(connection, smk): ...@@ -610,9 +610,15 @@ def getChainsAndStreams(connection, smk):
def getChains(connection, smk): def getChains(connection, smk):
cursor,schemaname = getTriggerDBCursor(connection) cursor,schemaname = getTriggerDBCursor(connection)
output = ['TC.HTC_ID', 'TC.HTC_CHAIN_COUNTER', 'TC.HTC_NAME', 'TC.HTC_L2_OR_EF'] isrun2 = isRun2(cursor,schemaname)
output = []
if isrun2:
output = ['TC.HTC_ID', 'TC.HTC_CHAIN_COUNTER', 'TC.HTC_NAME']
else:
output = ['TC.HTC_ID', 'TC.HTC_CHAIN_COUNTER', 'TC.HTC_NAME', 'TC.HTC_L2_OR_EF']
tables = {} tables = {}
tables['SM'] = 'SUPER_MASTER_TABLE' tables['SM'] = 'SUPER_MASTER_TABLE'
tables['M2C'] = 'HLT_TM_TO_TC' tables['M2C'] = 'HLT_TM_TO_TC'
...@@ -631,8 +637,11 @@ def getChains(connection, smk): ...@@ -631,8 +637,11 @@ def getChains(connection, smk):
chainsl2 = {} chainsl2 = {}
chainsef = {} chainsef = {}
for x in res: for x in res:
if x[3]=='L2': chainsl2[x[1]] = x[2] if isrun2:
else: chainsef[x[1]] = x[2] chainsef[x[1]] = x[2]
else:
if x[3]=='L2': chainsl2[x[1]] = x[2]
else: chainsef[x[1]] = x[2]
return chainsl2, chainsef return chainsl2, chainsef
...@@ -802,6 +811,72 @@ def getExpressStreamPrescales(connection,psk): ...@@ -802,6 +811,72 @@ def getExpressStreamPrescales(connection,psk):
return name, [(r[1],r[3]) for r in res if r[0]=='express'] return name, [(r[1],r[3]) for r in res if r[0]=='express']
def getHLTPrescalesRun2(connection,psk):
"""returns set name, prescale and passthrough
values for a given HLT prescale key
@connection - connection string, e.g. TRIGGERDB
@psk - HLT prescale key
@return (ps name, [('L2/EF',chainId,prescale,pass-through),...])
"""
res = queryHLTPrescaleTableRun2(connection,psk)
return [(r) for r in res if r[3]!='express']
def getExpressStreamPrescalesRun2(connection,psk):
"""returns the express stream prescales for a given HLT prescale key
@connection - connection string, e.g. TRIGGERDB
@psk - HLT prescale key
@return (ps name, [chainId,prescale),...])
"""
res = queryHLTPrescaleTableRun2(connection,psk)
return [(r) for r in res if r[3]=='express']
def queryHLTPrescaleTableRun2(connection,psk):
cursor,schemaname = getTriggerDBCursor(connection)
output = [ "HTC.HTC_NAME", "PS.HPR_CHAIN_COUNTER", "PS.HPR_TYPE", "PS.HPR_CONDITION" , "PS.HPR_VALUE"]
tables = {}
tables['PS'] = 'HLT_PRESCALE'
tables['HTC'] = 'HLT_TRIGGER_CHAIN'
condition = [ "PS.HPR_PRESCALE_SET_ID = :psk",
"HTC.HTC_CHAIN_COUNTER = PS.HPR_CHAIN_COUNTER"
]
bindvars = { "psk": psk }
res = executeQuery(cursor, output, condition, schemaname, tables, bindvars)
return res
def getHLTPrescalesFromSMK(connection, smk):
cursor,schemaname = getTriggerDBCursor(connection)
tables = {}
tables['HPS'] = 'HLT_PRESCALE_SET'
tables['TM2PS'] = 'HLT_TM_TO_PS'
tables['HTM'] = 'HLT_TRIGGER_MENU'
tables['HMT'] = 'HLT_MASTER_TABLE'
tables['SM'] = 'SUPER_MASTER_TABLE'
output = ['TM2PS.HTM2PS_PRESCALE_SET_ID']
condition = [ "TM2PS.HTM2PS_TRIGGER_MENU_ID = HTM.HTM_ID",
"HTM.HTM_ID = HMT.HMT_TRIGGER_MENU_ID",
"HMT.HMT_ID = SM.SMT_HLT_MASTER_TABLE_ID",
"SM.SMT_ID = %s" % smk ]
hltpsk = executeQuery(cursor, output, condition, schemaname, tables)
return hltpsk
def test(): def test():
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment