ATLAS Offline Software
AtlRunQueryTriggerUtils.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 #
5 # ----------------------------------------------------------------
6 # Script : AtlRunQueryTriggerUtils.py
7 # Project: AtlRunQuery
8 # Purpose: Trigger Utility functions for AtlRunQuery
9 # Authors: Andreas Hoecker (CERN), Joerg Stelzer (DESY)
10 # Created: Oct 27, 2010
11 # ----------------------------------------------------------------
12 
13 
14 from __future__ import print_function
15 from collections.abc import Iterable
16 
17 
18 __cursor_schema = {} # cache for cursor and schema by alias
19 
20 # returns True if run is RUN 2 (2015-2018)
21 def isTriggerRun2(run_number = None , smk = None , isRun2 = None ):
22  if run_number is None and smk is None and isRun2 is None:
23  raise RuntimeError("Cannot determine if trigger db is run 1 or 2")
24 
25  if smk is not None :
26  return smk >= 2000 and smk<3000
27  elif run_number is not None :
28  return run_number > 249000
29  else:
30  return isRun2
31 
32 
33 def triggerDBAlias(run_number = None , smk = None, lhcRun = None ):
34  if run_number is None and smk is None and lhcRun is None:
35  raise RuntimeError("Cannot determine the triggerDBAlias as no info is given")
36 
37  # lhcRun given
38  if lhcRun==1 or lhcRun==2:
39  return f"TRIGGERDB_RUN{lhcRun}"
40  if lhcRun==3:
41  return "TRIGGERDBDEV1_I8" if (smk is not None and smk<3000) else "TRIGGERDB_RUN3"
42 
43  # smk given
44  if smk is not None:
45  if smk<2000:
46  return "TRIGGERDB_RUN1"
47  elif smk<3000:
48  # note that this causes problems for the runs taken during the LS2 Pilot beam test
49  return "TRIGGERDB_RUN2"
50  else:
51  return "TRIGGERDB_RUN3"
52 
53  # run number given (should not be used, as the run should know the lhcRun)
54  # see AtlRunQueryRun.py
55  if run_number > 405800:
56  return "TRIGGERDB_RUN3"
57  if run_number > 378000:
58  return "TRIGGERDBDEV1_I8"
59  elif run_number > 249000:
60  return "TRIGGERDB_RUN2"
61  else:
62  return "TRIGGERDB_RUN1"
63 
64 
65 
66 from xml.dom import minidom
67 import os, re, logging
68 log = logging.getLogger( __name__ )
69 
71  def __init__(self, name, counter, lowername="", lowercounter=-1, forshow=False, forselect=False, level=0):
72  self.name = name
73  self.counter = counter
74  self.lowername = "" if lowername=="~" else lowername
75  self.lowercounter = lowercounter
76  self.forshow = forshow
77  self.forselect = forselect
78  self.multiseeded = (self.lowername=="") or (',' in self.lowername)
79  self.level = level
80  self.lower = None
81 
82  def __repr__(self):
83  return "TC:"+self.name
84 
85 
86 def FindFile( filename, pathlist, access ):
87  """Find <filename> with rights <access> through <pathlist>."""
88 
89  # special case for those filenames that already contain a path
90  if os.path.dirname( filename ):
91  if os.access( filename, access ):
92  return filename
93 
94  # test the file name in all possible paths until first found
95  for path in pathlist:
96  f = os.path.join( path, filename )
97  if os.access( f, access ):
98  return f
99 
100  # no such accessible file avalailable
101  return None
102 
103 
104 
105 def _getFileLocalOrPath(filename, pathenv):
106  """looks for filename in local directory and then in all paths specified in environment variable 'pathenv'
107  returns path/filename if existing, otherwise None
108  """
109  log = logging.getLogger( "TrigConfigSvcUtils.py" )
110  if os.path.exists(filename):
111  log.info( "Using local file %s", filename)
112  return filename
113 
114  pathlist = os.getenv(pathenv,'').split(os.pathsep)
115  resolvedfilename = FindFile(filename, pathlist, os.R_OK)
116  if resolvedfilename:
117  return resolvedfilename
118 
119  log.fatal("No file %s found locally nor in %s" % (filename, os.getenv('CORAL_DBLOOKUP_PATH')) )
120  return None
121 
122 
124  log = logging.getLogger( "TrigConfigSvcUtils.py" )
125 
126  connectionServices = None # list of services
127 
128  dblookupfilename = _getFileLocalOrPath('dblookup.xml','CORAL_DBLOOKUP_PATH')
129  if dblookupfilename is None:
130  return None
131 
132  doc = minidom.parse(dblookupfilename)
133  for ls in doc.getElementsByTagName('logicalservice'):
134  if ls.attributes['name'].value != alias:
135  continue
136  connectionServices = [str(s.attributes['name'].value) for s in ls.getElementsByTagName('service')]
137  doc.unlink()
138 
139  log.info( "For alias '%s' found list of connections %r", (alias,connectionServices) )
140  if connectionServices is None:
141  print("ERROR: Trigger connection alias '%s' is not defined in %s" % (alias,dblookupfilename))
142  return connectionServices
143 
144 
146  """ read authentication.xml, first from local directory, then from all paths specified in CORAL_AUTH_PATH
147  returns dictionary d with d[connection] -> (user,pw)
148  """
149 
150  authDict = {}
151  dbauthfilename = _getFileLocalOrPath('authentication.xml','CORAL_AUTH_PATH')
152  if dbauthfilename is None:
153  return authDict
154 
155  doc = minidom.parse(dbauthfilename)
156  for cn in doc.getElementsByTagName('connection'):
157  user = ""
158  pw = ""
159  svc = cn.attributes['name'].value
160  for p in cn.getElementsByTagName('parameter'):
161  if p.attributes['name'].value == 'user':
162  user = p.attributes['value'].value
163  elif p.attributes['name'].value == 'password':
164  pw = p.attributes['value'].value
165  authDict[svc] = (user,pw)
166  doc.unlink()
167  return authDict
168 
169 authDict = None
170 
171 def _getConnectionParameters(connection):
172  log = logging.getLogger( "TrigConfigSvcUtils.py" )
173  connection = str(connection)
174  connectionParameters = {}
175 
176  if connection.startswith("sqlite_file:"):
177  filename = connection[connection.find(':')+1:]
178  connectionParameters["techno"] = "sqlite"
179  connectionParameters["filename"] = filename if os.path.exists(filename) else None
180 
181  elif connection.startswith("oracle://"):
182  if connection.count(';') == 2:
183  pattern = "(.*)://(.*)/(.*);username=(.*);password=(.*)"
184  m = re.match(pattern,connection)
185  #print ('Groups ', m)
186  if not m:
187  log.fatal("connection string '%s' doesn't match the pattern '%s'?" % (connection,pattern))
188  (techno, server, schema, user, passwd) = m.groups()
189  #print ((techno, server, schema, user, passwd))
190  else:
191  global authDict
192  if not authDict:
193  authDict = _readAuthentication()
194  pattern = "oracle://(.*)/(.*)"
195  m = re.match(pattern,connection)
196  if not m:
197  log.fatal("connection string '%s' doesn't match the pattern '%s'?" % (connection,pattern))
198  (server, schema) = m.groups()
199  (user,passwd) = authDict[connection]
200  #info from auth file also unicode
201  connectionParameters["techno"] = 'oracle'
202  connectionParameters["server"] = str(server)
203  connectionParameters["schema"] = str(schema)
204  connectionParameters["user" ] = str(user)
205  connectionParameters["passwd"] = str(passwd)
206 
207  elif connection.startswith("mysql://"):
208  pattern = "mysql://(.*);dbname=(.*);user=(.*);passwd=(.*);"
209  m = re.match(pattern,connection)
210  if not m:
211  log.fatal("connection string '%s' doesn't match the pattern '%s'?" % (connection,pattern) )
212  (server, dbname, user, passwd) = m.groups()
213  connectionParameters["techno"] = 'mysql'
214  connectionParameters["server"] = server
215  connectionParameters["dbname"] = dbname
216  connectionParameters["user" ] = user
217  connectionParameters["passwd"] = passwd
218 
219  elif connection.startswith("frontier://"):
220  pattern = r"frontier://ATLF/\‍(\‍)/(.*)"
221  m = re.match(pattern,connection)
222  if not m:
223  log.fatal("connection string '%s' doesn't match the pattern '%s'?" % (connection,pattern) )
224  (schema, ) = m.groups()
225  connectionParameters["techno"] = 'frontier'
226  connectionParameters["schema"] = schema
227 
228  return connectionParameters
229 
230 def interpretConnection(connection, debug=False, resolveAlias=True):
231  # connection needs to be of the following format (this is also the order of checking)
232  # <ALIAS> -- any string without a colon ':' will be checked for in the dblookup.xml file
233  # sqlite_file:filename.db -- an sqlite file, no authentication needed, will be opened in read-only mode
234  # oracle://ATLR/ATLAS_CONF_TRIGGER_V2 -- a service description without user and password, requires lookup in authentication.xml
235  # oracle://ATLR/ATLAS_CONF_TRIGGER_V2;username=ATLAS_CONF_TRIGGER_V2_R;password=<...> -- a service description with user and password
236 
237  log.info("Specified connection string '%s'", connection)
238 
239  # not needed any longer
240  # connection = connection.lstrip("dblookup://")
241  # connection = connection.lstrip("dblookup:")
242  # connection = connection.rstrip(";")
243  #print (connection)
244 
245  # what to return
246  connectionParameters = {}
247  connection = str(connection)
248 
249  # connection explicitly specified (no DB alias)
250  if ':' in connection:
251  connectionParameters = _getConnectionParameters( connection )
252  return connectionParameters
253 
254  # connection is a DB alias
255  connectionParameters["alias"] = connection
256  if not resolveAlias:
257  return connectionParameters
258 
259  connectionServices = _getConnectionServicesForAlias( connection ) # alias resolution via dblookup
260  if connectionServices is None:
261  return connectionParameters
262 
263  # If ${TRIGGER_USE_FRONTIER} is True then we remove sqlite files
264  if os.getenv('TRIGGER_USE_FRONTIER',False):
265  connectionServices = filter(lambda conn: not conn.startswith("sqlite_file"), connectionServices)
266  if 'ATLAS_TRIGGERDB_FORCESQLITE' in os.environ:
267  log.fatal("Inconsistent setup: environment variable ATLAS_TRIGGERDB_FORCESQLITE is defined and use of Frontier is requested" )
268 
269  # SQLite
270  sqliteconnections = [conn for conn in connectionServices if conn.startswith("sqlite_file")]
271  if len(sqliteconnections)>0:
272  for conn in sqliteconnections:
273  connectionParameters = _getConnectionParameters( conn )
274  if connectionParameters["filename"] is not None:
275  break # stop at the first sqlite file that exists
276  if connectionParameters["filename"] is not None:
277  log.info("Using sqlite connection %s", connectionParameters)
278  return connectionParameters
279  else:
280  if 'ATLAS_TRIGGERDB_FORCESQLITE' in os.environ:
281  log.fatal("environment ATLAS_TRIGGERDB_FORCESQLITE is defined but non of the sqlite files defined in dblookup.xml exists" )
282  else:
283  if 'ATLAS_TRIGGERDB_FORCESQLITE' in os.environ:
284  log.fatal("environment ATLAS_TRIGGERDB_FORCESQLITE is defined but no sqlite connection defined in dblookup.xml" )
285 
286  from CoolConvUtilities.AtlCoolLib import replicaList
287  serverlist=['ATLAS_CONFIG' if s=='ATLAS_COOLPROD' else s for s in replicaList()] # replicaList is for COOL, I need ATLAS_CONFIG instead of ATLAS_COOLPROD
288  log.info("Trying these servers in order %r", serverlist)
289  for server in serverlist:
290  log.info("Trying server %s", server)
291 
292  if server=='ATLF':
293  if not os.getenv('TRIGGER_USE_FRONTIER',False):
294  continue
295  frontierconnections = [conn for conn in connectionServices if conn.startswith("frontier")]
296  if len(frontierconnections) == 0:
297  log.debug("FroNTier connection not defined for alias %s in dblookup", connection )
298  continue
299  log.info("Environment FRONTIER_SERVER: %s", os.getenv('FRONTIER_SERVER','not defined'))
300  frontierServer = os.getenv('FRONTIER_SERVER',None)
301  if not frontierServer:
302  log.debug("No environment variable FRONTIER_SERVER" )
303  continue
304  connectionParameters = _getConnectionParameters( frontierconnections[0] )
305  connectionParameters['url'] = frontierServer
306  log.info("Using frontier connection %s", frontierconnections[0])
307  #connstr='frontier://ATLF/%s;schema=%s;dbname=TRIGCONF' % (connectionParameters['url'],connectionParameters["schema"])
308  break
309  elif server=='atlas_dd':
310  continue
311  else:
312  oracleconnections = [conn for conn in connectionServices if conn.startswith("oracle://%s/" % server)]
313  if len(oracleconnections) == 0:
314  log.debug("Oracle connection not defined for server %s in dblookup", server )
315  continue
316  connectionParameters = _getConnectionParameters( oracleconnections[0] )
317  log.info("Using oracle connection %s", oracleconnections[0])
318  break
319 
320  return connectionParameters
321 
322 
323 def _get_sqlite_cursor (filename):
324  try:
325  import sqlite3
326  except ImportError:
327  raise RuntimeError ("ERROR: Can't import sqlite3?")
328  os.lstat(filename)
329  connection = sqlite3.connect(filename)
330  return connection.cursor()
331 
332 def _get_oracle_cursor (tns, user, passwd=""):
333  if passwd=="":
334  from getpass import getpass
335  passwd = getpass("[Oracle] database password for %s@%s: " % (user, tns))
336  try:
337  from cx_Oracle import connect
338  except ImportError:
339  raise RuntimeError ("ERROR: Can't import cx_Oracle?")
340  connection = connect (user, passwd, tns, threaded=True)
341  return connection.cursor()
342 
343 
344 def _get_mysql_cursor (host, db, user, passwd=""):
345  if passwd=="":
346  from getpass import getpass
347  passwd = getpass("[MySQL] `%s' database password for %s@%s: " % (db, user, host))
348  try:
349  from MySQLdb import connect
350  except ImportError:
351  raise RuntimeError ("ERROR: Can't import MySQLdb")
352  connection = connect(host=host, user=user, passwd=passwd, db=db, connect_timeout=10)
353  return connection.cursor()
354 
355 
357 
358  global __cursor_schema
359  if dbAlias in __cursor_schema:
360  return __cursor_schema[dbAlias] # return the correct cursor and schema name
361 
362  connectionParameters = interpretConnection(dbAlias)
363  technology = connectionParameters["techno"]
364 
365  if technology == 'sqlite':
366  cursor = _get_sqlite_cursor(connectionParameters["filename"])
367  schema = ''
368 
369  elif technology == 'oracle':
370  cursor = _get_oracle_cursor(connectionParameters["server"], connectionParameters["user"], connectionParameters["passwd"])
371  schema = connectionParameters["schema"].rstrip('.') + '.'
372 
373  elif technology == 'frontier':
374  from TrigConfigSvc.TrigConfFrontier import getFrontierCursor
375  cursor = getFrontierCursor(connectionParameters["url"], connectionParameters["schema"], logging.getLogger("TrigConfigSvcUtils.py").level)
376  schema = connectionParameters["schema"].rstrip('.') + '.'
377 
378  elif technology == 'mysql':
379  cursor = _get_mysql_cursor(connectionParameters["server"], connectionParameters["dbname"], connectionParameters["user"], connectionParameters["passwd"]),''
380  schema = ''
381 
382  __cursor_schema[dbAlias] = (cursor,schema)
383 
384  return __cursor_schema[dbAlias] # return the correct cursor and schema name
385 
386 
387 def getTriggerDBCursor(run_number = None, smk = None, lhcRun = None):
388 
389  dbAlias = triggerDBAlias(run_number = run_number, smk = smk, lhcRun = lhcRun)
390  return getTriggerDBCursorForAlias(dbAlias)
391 
392 
393 def getUsedTables(output, condition, schemaname, tables):
394  schemaname = schemaname.rstrip('.')+'.'
395  usedtables = set()
396  for o in output:
397  usedtables.add(o.split('.')[0])
398  for c in condition:
399  for p in c.split():
400  if '.' in p and '\'' not in p:
401  usedtables.add(p.split('.')[0])
402  return ["%s%s %s" % (schemaname,tables[t],t) for t in usedtables]
403 
404 
405 def executeQuery(cursor, output, condition, schemaname, tables, bindvars=()):
406  query = 'select distinct %s from %s where %s' % (
407  ', '.join(output),
408  ', '.join(getUsedTables(output, condition, schemaname, tables)),
409  ' and '.join(condition)
410  )
411  if len(bindvars)==0:
412  cursor.execute(str(query))
413  else:
414  cursor.execute(str(query),bindvars)
415 
416  return cursor.fetchall()
417 
418 
419 def getL1PskNames(psk, dbAlias = None, run_number = None , smk = None , lhcRun = None ):
420  if not isinstance(psk, Iterable):
421  psk = [psk]
422 
423  keyslist = ','.join([str(k) for k in psk if k])
424 
425  if keyslist=="":
426  return {}
427 
428  tables = { 'L' : 'L1_PRESCALE_SET' }
429  output = [ 'L.L1PS_ID', 'L.L1PS_NAME' ]
430  condition = [ "L.L1PS_ID in (%s)" % keyslist ]
431 
432  if dbAlias is not None:
433  cursor, schema = getTriggerDBCursorForAlias(dbAlias)
434  else:
435  cursor, schema = getTriggerDBCursor(run_number = run_number, smk = smk, lhcRun = lhcRun )
436 
437  res = executeQuery(cursor, output, condition, schema, tables)
438 
439  return dict(res)
440 
441 
442 
443 def getHLTPskNames(psk, dbAlias = None, run_number = None , smk = None , lhcRun = None ):
444  if not isinstance(psk, Iterable):
445  psk = [psk]
446 
447  keyslist = ','.join([str(k) for k in psk if k])
448  if keyslist=="":
449  return {}
450 
451  tables = { 'L' : 'HLT_PRESCALE_SET' }
452  output = ['L.HPS_ID', 'L.HPS_NAME']
453  condition = [ "L.HPS_ID in (%s)" % keyslist ]
454 
455  if dbAlias is not None:
456  cursor, schema = getTriggerDBCursorForAlias(dbAlias)
457  else:
458  cursor,schema = getTriggerDBCursor(run_number = run_number, smk = smk, lhcRun = lhcRun )
459 
460  res = executeQuery( cursor, output, condition, schema, tables)
461 
462  return dict(res)
463 
464 
465 def getSmkNames( smks, dbAlias ):
466  """
467  takes a single SMK or a list of SMKs
468  returns a map from SMK to (name,version,comment)
469  """
470  if not isinstance(smks, Iterable):
471  smks = [smks]
472 
473  keyslist = ','.join([str(k) for k in smks if k])
474  if keyslist=="":
475  return {}
476 
477  tables = { 'S' : 'SUPER_MASTER_TABLE' }
478  output = ['S.SMT_ID', 'S.SMT_NAME', 'S.SMT_VERSION', 'S.SMT_COMMENT']
479  condition = [ "S.SMT_ID in (%s)" % keyslist ]
480 
481  cursor, schema = getTriggerDBCursorForAlias(dbAlias)
482  res = executeQuery( cursor, output, condition, schema, tables)
483 
484  return dict([ (r[0],(r[1],r[2],r[3])) for r in res])
485 
486 
487 
488 
489 def getHLTMenu(smk):
490  if smk is None or smk==0:
491  return [],[]
492 
493  if isTriggerRun2(smk):
494  output = ['TC.HTC_NAME', 'TC.HTC_CHAIN_COUNTER', 'TC.HTC_LOWER_CHAIN_NAME' ]
495  else:
496  output = ['TC.HTC_NAME', 'TC.HTC_CHAIN_COUNTER', 'TC.HTC_LOWER_CHAIN_NAME', 'TC.HTC_L2_OR_EF' ]
497 
498  tables = {
499  'SM' : 'SUPER_MASTER_TABLE',
500  'HM' : 'HLT_MASTER_TABLE',
501  'M2C' : 'HLT_TM_TO_TC',
502  'TC' : 'HLT_TRIGGER_CHAIN'
503  }
504  condition = [
505  'SM.SMT_ID = :smk',
506  'SM.SMT_HLT_MASTER_TABLE_ID = HM.HMT_ID',
507  'HM.HMT_TRIGGER_MENU_ID = M2C.HTM2TC_TRIGGER_MENU_ID',
508  'M2C.HTM2TC_TRIGGER_CHAIN_ID = TC.HTC_ID'
509  ]
510  bindvars = { "smk": smk }
511 
512  cursor,schema = getTriggerDBCursor(smk)
513  res = executeQuery( cursor, output, condition, schema, tables, bindvars)
514 
515  l2chains = []
516  efchains = []
517 
518  for r in res:
519  if len(r)==4 and r[3]=='L2':
520  l2chains += [TriggerChain(r[0],r[1],r[2], level=2)]
521  else:
522  efchains += [TriggerChain(r[0],r[1],r[2], level=3)]
523 
524  return l2chains, efchains
525 
526 
527 
528 
529 def getL1Menu(smk):
530  if smk is None or smk==0:
531  return []
532  output = [
533  'TI.L1TI_NAME',
534  'TI.L1TI_CTP_ID'
535  ]
536  tables = {
537  'SM' : 'SUPER_MASTER_TABLE',
538  'M' : 'L1_MASTER_TABLE',
539  'M2I' : 'L1_TM_TO_TI',
540  'TI' : 'L1_TRIGGER_ITEM'
541  }
542  condition = [
543  "SM.SMT_ID = :smk",
544  'SM.SMT_L1_MASTER_TABLE_ID = M.L1MT_ID',
545  'M.L1MT_TRIGGER_MENU_ID = M2I.L1TM2TI_TRIGGER_MENU_ID',
546  'M2I.L1TM2TI_TRIGGER_ITEM_ID = TI.L1TI_ID'
547  ]
548  bindvars = { "smk": smk }
549 
550  cursor,schema = getTriggerDBCursor(smk = smk)
551  res = executeQuery( cursor, output, condition, schema, tables, bindvars)
552 
553  maxNumberItems = 512 if isTriggerRun2(smk=smk) else 256
554  items = maxNumberItems*[None]
555 
556  for r in res:
557  items[r[1]] = TriggerChain(r[0],r[1])
558  return items
559 
560 
561 
562 def getL1Prescales(l1prescalekey, run_number):
563 
564  maxNumberItems = 512 if isTriggerRun2( run_number = run_number ) else 256
565 
566  tables = { 'L' : 'L1_PRESCALE_SET' }
567  output = ['L.L1PS_VAL%i' % i for i in range( 1, maxNumberItems + 1)]
568  condition = [ "L.L1PS_ID = :psk" ]
569  bindvars = { "psk": l1prescalekey }
570 
571  cursor,schema = getTriggerDBCursor( run_number = run_number )
572  res = executeQuery(cursor, output, condition, schema, tables, bindvars)
573 
574  return res[0][0:maxNumberItems]
575 
576 
577 def getHLTPrescales(hltprescalekey, run_number):
578 
579  l2ps = {}
580  efps = {}
581 
582  if isTriggerRun2( run_number = run_number ):
583  return l2ps,efps
584 
585  tables = {
586  'H' : 'HLT_PRESCALE_SET',
587  'P' : 'HLT_PRESCALE'
588  }
589  output = [
590  'P.HPR_L2_OR_EF',
591  'P.HPR_CHAIN_COUNTER',
592  'P.HPR_PRESCALE',
593  'P.HPR_PASS_THROUGH_RATE'
594  ]
595  condition = [
596  "P.HPR_PRESCALE_SET_ID = :psk",
597  "P.HPR_L2_OR_EF not like 'express'"
598  ]
599  bindvars = { "psk": hltprescalekey }
600 
601  cursor,schema = getTriggerDBCursor(isRun2 = True)
602  res = executeQuery(cursor, output, condition, schema, tables, bindvars)
603 
604  for r in res:
605  if r[0]=='L2':
606  l2ps[r[1]] = ( float(r[2]), float(r[3]) )
607  elif (r[0]=='EF' or r[0]=='HLT' or r[0]=='HL'):
608  efps[r[1]] = ( float(r[2]), float(r[3]) )
609 
610  return l2ps, efps
611 
612 
613 def getRandom(smk, lhcRun):
614  # does not work for Run 3
615  if lhcRun >= 3:
616  return (1,1,1,1)
617 
618  if smk=='n.a.':
619  return ('n.a.','n.a.')
620 
621  tables = {
622  'S' : 'SUPER_MASTER_TABLE',
623  'M' : 'L1_MASTER_TABLE',
624  'R' : 'L1_RANDOM'
625  }
626  if lhcRun == 2:
627  output = [ 'R.L1R_CUT0', 'R.L1R_CUT1', 'R.L1R_CUT2', 'R.L1R_CUT3' ]
628  else:
629  output = [ 'R.L1R_RATE1', 'R.L1R_RATE2' ]
630 
631  condition = [ "S.SMT_ID=:smk", "S.SMT_L1_MASTER_TABLE_ID=M.L1MT_ID", "M.L1MT_RANDOM_ID=R.L1R_ID" ]
632 
633  bindvars = { "smk": smk }
634 
635  cursor,schema = getTriggerDBCursorForAlias(dbAlias = triggerDBAlias(lhcRun=lhcRun))
636  res = executeQuery(cursor, output, condition, schema, tables, bindvars)
637  if len(res) > 0:
638  return res[0]
639  else:
640  return [0,0,0,0]
641 
642 
643 if __name__=="__main__":
644  #print (getL1PskNames([2517, 2518, 2284, 2536]))
645 
646  #print (getHLTPskNames([2517, 2530, 2537, 2491]))
647 
648  #print (getSmkNames([931, 932, 933]))
649 
650  #print (getL1Menu(931))
651 
652  #print (getHLTMenu(931))
653 
654  #print (getL1Prescales(2517))
655 
656  #print (getHLTPrescales(2530))
657 
658  print (getRandom(1038))
python.utils.AtlRunQueryTriggerUtils.TriggerChain.name
name
Definition: AtlRunQueryTriggerUtils.py:72
python.utils.AtlRunQueryTriggerUtils.getL1Menu
def getL1Menu(smk)
Definition: AtlRunQueryTriggerUtils.py:529
python.AtlCoolLib.replicaList
def replicaList()
Definition: AtlCoolLib.py:189
python.utils.AtlRunQueryTriggerUtils.TriggerChain.__repr__
def __repr__(self)
Definition: AtlRunQueryTriggerUtils.py:82
python.utils.AtlRunQueryTriggerUtils.getTriggerDBCursor
def getTriggerDBCursor(run_number=None, smk=None, lhcRun=None)
Definition: AtlRunQueryTriggerUtils.py:387
python.utils.AtlRunQueryTriggerUtils.TriggerChain.lowername
lowername
Definition: AtlRunQueryTriggerUtils.py:74
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
python.utils.AtlRunQueryTriggerUtils.TriggerChain.lowercounter
lowercounter
Definition: AtlRunQueryTriggerUtils.py:75
python.TrigConfFrontier.getFrontierCursor
def getFrontierCursor(urls, schema, loglevel=logging.INFO)
Definition: TrigConfFrontier.py:33
python.utils.AtlRunQueryTriggerUtils.TriggerChain.level
level
Definition: AtlRunQueryTriggerUtils.py:79
python.utils.AtlRunQueryTriggerUtils.FindFile
def FindFile(filename, pathlist, access)
Definition: AtlRunQueryTriggerUtils.py:86
python.utils.AtlRunQueryTriggerUtils.getSmkNames
def getSmkNames(smks, dbAlias)
Definition: AtlRunQueryTriggerUtils.py:465
python.utils.AtlRunQueryTriggerUtils._getConnectionParameters
def _getConnectionParameters(connection)
Definition: AtlRunQueryTriggerUtils.py:171
python.utils.AtlRunQueryTriggerUtils.interpretConnection
def interpretConnection(connection, debug=False, resolveAlias=True)
Definition: AtlRunQueryTriggerUtils.py:230
python.utils.AtlRunQueryTriggerUtils.getHLTPskNames
def getHLTPskNames(psk, dbAlias=None, run_number=None, smk=None, lhcRun=None)
Definition: AtlRunQueryTriggerUtils.py:443
python.utils.AtlRunQueryTriggerUtils.TriggerChain
Definition: AtlRunQueryTriggerUtils.py:70
python.utils.AtlRunQueryTriggerUtils.TriggerChain.__init__
def __init__(self, name, counter, lowername="", lowercounter=-1, forshow=False, forselect=False, level=0)
Definition: AtlRunQueryTriggerUtils.py:71
python.utils.AtlRunQueryTriggerUtils.triggerDBAlias
def triggerDBAlias(run_number=None, smk=None, lhcRun=None)
Definition: AtlRunQueryTriggerUtils.py:33
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.utils.AtlRunQueryTriggerUtils.getHLTPrescales
def getHLTPrescales(hltprescalekey, run_number)
Definition: AtlRunQueryTriggerUtils.py:577
python.utils.AtlRunQueryTriggerUtils._getConnectionServicesForAlias
def _getConnectionServicesForAlias(alias)
Definition: AtlRunQueryTriggerUtils.py:123
python.utils.AtlRunQueryTriggerUtils.executeQuery
def executeQuery(cursor, output, condition, schemaname, tables, bindvars=())
Definition: AtlRunQueryTriggerUtils.py:405
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.utils.AtlRunQueryTriggerUtils.TriggerChain.lower
lower
Definition: AtlRunQueryTriggerUtils.py:80
python.utils.AtlRunQueryTriggerUtils._getFileLocalOrPath
def _getFileLocalOrPath(filename, pathenv)
Definition: AtlRunQueryTriggerUtils.py:105
python.utils.AtlRunQueryTriggerUtils.TriggerChain.forshow
forshow
Definition: AtlRunQueryTriggerUtils.py:76
python.utils.AtlRunQueryTriggerUtils._get_mysql_cursor
def _get_mysql_cursor(host, db, user, passwd="")
Definition: AtlRunQueryTriggerUtils.py:344
python.utils.AtlRunQueryTriggerUtils.TriggerChain.multiseeded
multiseeded
Definition: AtlRunQueryTriggerUtils.py:78
python.utils.AtlRunQueryTriggerUtils.getRandom
def getRandom(smk, lhcRun)
Definition: AtlRunQueryTriggerUtils.py:613
python.utils.AtlRunQueryTriggerUtils.getUsedTables
def getUsedTables(output, condition, schemaname, tables)
Definition: AtlRunQueryTriggerUtils.py:393
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.utils.AtlRunQueryTriggerUtils._get_sqlite_cursor
def _get_sqlite_cursor(filename)
Definition: AtlRunQueryTriggerUtils.py:323
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
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.AtlRunQueryTriggerUtils.TriggerChain.forselect
forselect
Definition: AtlRunQueryTriggerUtils.py:77
python.utils.AtlRunQueryTriggerUtils.getTriggerDBCursorForAlias
def getTriggerDBCursorForAlias(dbAlias)
Definition: AtlRunQueryTriggerUtils.py:356
python.utils.AtlRunQueryTriggerUtils._get_oracle_cursor
def _get_oracle_cursor(tns, user, passwd="")
Definition: AtlRunQueryTriggerUtils.py:332
python.utils.AtlRunQueryTriggerUtils.isTriggerRun2
def isTriggerRun2(run_number=None, smk=None, isRun2=None)
Definition: AtlRunQueryTriggerUtils.py:21
python.utils.AtlRunQueryTriggerUtils.TriggerChain.counter
counter
Definition: AtlRunQueryTriggerUtils.py:73
python.utils.AtlRunQueryTriggerUtils.getL1PskNames
def getL1PskNames(psk, dbAlias=None, run_number=None, smk=None, lhcRun=None)
Definition: AtlRunQueryTriggerUtils.py:419
python.utils.AtlRunQueryTriggerUtils.getL1Prescales
def getL1Prescales(l1prescalekey, run_number)
Definition: AtlRunQueryTriggerUtils.py:562
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.utils.AtlRunQueryTriggerUtils.getHLTMenu
def getHLTMenu(smk)
Definition: AtlRunQueryTriggerUtils.py:489
python.utils.AtlRunQueryTriggerUtils._readAuthentication
def _readAuthentication()
Definition: AtlRunQueryTriggerUtils.py:145