parsePQSLOutput.py
Go to the documentation of this file.
1 #!/bin/env python
2 print "run : --- parsePSQL output"
3 # This is output got from the database, an example query would be:
4 # psql -U nova_reader -d nova_prod -h ifdbprod.fnal.gov -p 5433 -c "SELECT * FROM fardet.runs WHERE run > 13800 AND partition = 1;" -o log.txt
5 ########################### Option parser
6 from optparse import OptionParser
7 parser = OptionParser()
8 parser.add_option("-i", "--input", help="input log file", action="store", type=str, dest="input", default=False)
9 parser.add_option("-v", "--verbose", help="turn on verbose mode", action="store_true", dest="verbose", default=False)
10 (options, args) = parser.parse_args()
11 if options.verbose:
12  print "run : --- Options"
13  print "run : input: ",options.input
14  print "run : verbose mode: ",options.verbose
15 assert (options.input), "No input file provided, specify one with -i MYFILE"
16 ########################### Analyse
17 lines = open(options.input, "rb").readlines()
18 print "run : Got %i lines"%len(lines)
19 good_lines = 0
20 good_events = 0
21 good_subruns = 0
22 for line in lines:
23  tokens = line.split("|")
24  if len(tokens) != 19: continue
25  if "run" in tokens[0]: continue
26  if tokens[0].isspace(): continue
27  bad_run = False
28  for i in range(4):
29  if tokens[i].isspace(): bad_run = True
30  if bad_run: continue
31  #print tokens[:4]
32  run = int(tokens[0])
33  nsubruns = int(tokens[1])
34  n_events = int(tokens[2])
35  partition = int(tokens[3])
36  assert(partition == 1)
37  #print tokens[:4]
38  good_lines+=1
39  good_events+=n_events
40  good_subruns+=nsubruns
41 print "run : Got %i good lines"%good_lines
42 print "run : Got %i good events"%good_events
43 print "run : Got %i good subruns"%good_subruns
44 ########################### Done
45 print "run : --- Done\n"
procfile open("FD_BRL_v0.txt")
assert(nhit_max >=nhit_nbins)