ATLAS Offline Software
LB_GetNEvents.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 # Script : GetNEventsLB.py
6 # Purpose: Utility to retrieve number of events per LB from SFO DB
7 # Authors: Andreas Hoecker (CERN)
8 # Created: Aug 17, 2011
9 # ----------------------------------------------------------------
10 
11 from __future__ import print_function
12 
13 import sys, getopt
14 
15 def GetSFO_LBNEvents( cursor, runno, streamname ):
16  """returns nfiles, fsize, nevents"""
17  stype, sep, sname = streamname.partition('_')
18  cursor.execute( "SELECT SUM(NREVENTS),LUMIBLOCKNR,COUNT(FILESIZE),SUM(FILESIZE) FROM SFO_TZ_File WHERE RUNNR=:arg_1 and STREAMTYPE=:arg_2 and STREAM=:arg_3 GROUP BY LUMIBLOCKNR ORDER BY LUMIBLOCKNR",
19  arg_1=runno, arg_2=stype, arg_3=sname )
20  return cursor.fetchall()
21 
22 def GetSFO_LBs( cursor, runno ):
23  cursor.execute( "SELECT MIN(LUMIBLOCKNR), MAX(LUMIBLOCKNR) FROM SFO_TZ_Lumiblock WHERE RUNNR=:arg_1", arg_1=runno )
24  return cursor.fetchone()[0:2]
25 
27  import cx_Oracle
28  return cx_Oracle.connect("ATLAS_SFO_T0_R/readmesfotz2008@atlr")
29 
30 def usage():
31  print(' ')
32  print('Usage: %s [options]' % sys.argv[0])
33  print(' -r | --run : run number (REQUIRED)')
34  print(' -s | --stream : full stream name (REQUIRED)')
35  print(' -h | --help : print this usage message')
36  print(' ')
37  exit(1)
38 
39 def main():
40 
41  try:
42  shortopts = "r:s:h?"
43  longopts = ["run=", "stream=", "help", "usage"]
44  opts, args = getopt.getopt( sys.argv[1:], shortopts, longopts )
45 
46  except getopt.GetoptError:
47  # print help information and exit:
48  print('ERROR: unknown options in argument %s' % sys.argv[1:], file=sys.stderr)
49  usage()
50 
51  runno = None
52  stream = None
53  for o, a in opts:
54  if o in ("-?", "-h", "--help", "--usage"):
55  usage()
56  elif o in ("-r", "--run"):
57  runno = a
58  elif o in ("-s", "--stream"):
59  stream = a
60 
61  if not runno or not stream: usage()
62  runno = int(runno)
63 
64  connection = OpenSFOConnection()
65  cursor = connection.cursor()
66 
67  print('Results for run: %i, stream: "%s"' % (runno, stream))
68 
69  # min/max LB number for given run/stream
70  # --> this command is slow... don't know why
71  # minLB, maxLB = GetSFO_LBs( cursor, runno )
72  # print 'LB range: %i -- %i' % (minLB, maxLB)
73 
74  # list with
75  lblist = GetSFO_LBNEvents( cursor, runno, stream )
76  print('First non-zero LB: ' + str(lblist[0][1]))
77  print('Last non-zero LB: ' + str(lblist[-1][1]))
78 
79  # access to all LBs
80  sumnev = 0
81  sumnfiles = 0
82  sumfsize = 0
83  for (nev,lb,nfiles,fsize) in lblist:
84  fsize /= 1.e6
85  print(' ... Run %i, LB %i has %i events, %i RAW files and %f MB' % (runno,lb,nev,nfiles,fsize))
86  sumnev += nev
87  sumnfiles += nfiles
88  sumfsize += fsize
89  print('--------------------------------------------------')
90  print('Total #events : ', sumnev)
91  print('Total #files : ', sumnfiles)
92  print('Total RAW size: ', sumfsize/1000.0, ' GB')
93 
94  cursor.close()
95  connection.close()
96 
97 if __name__ == '__main__':
98  main()
LB_GetNEvents.GetSFO_LBNEvents
def GetSFO_LBNEvents(cursor, runno, streamname)
Definition: LB_GetNEvents.py:15
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LB_GetNEvents.usage
def usage()
Definition: LB_GetNEvents.py:30
calibdata.exit
exit
Definition: calibdata.py:236
LB_GetNEvents.main
def main()
Definition: LB_GetNEvents.py:39
LB_GetNEvents.OpenSFOConnection
def OpenSFOConnection()
Definition: LB_GetNEvents.py:26
LB_GetNEvents.GetSFO_LBs
def GetSFO_LBs(cursor, runno)
Definition: LB_GetNEvents.py:22
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70