fillBadChanDBTables.py
Go to the documentation of this file.
1 import sys
2 import os
3 import psycopg2
4 
5 det=sys.argv[1]
6 lastrunFile = "lastrun{}".format(det)
7 
8 if (det=='FarDet'):
9  try:
10  conn = psycopg2.connect("dbname=nova_prod host=ifdbrep.fnal.gov user=nova_reader port=5436")
11  except:
12  print "I am unable to connect to the database"
13  exit(0)
14 else:
15  try:
16  conn = psycopg2.connect("dbname=nova_prod host=ifdbrep.fnal.gov user=nova_reader port=5434")
17  except:
18  print "I am unable to connect to the database"
19  exit(0)
20 
21 cur = conn.cursor()
22 
23 f = open(lastrunFile,'r')
24 firstrun = int(f.readline())
25 f.close()
26 
27 exceptionsFile = "exceptions"+det+".txt"
28 f = open(exceptionsFile,'r')
29 exceptionRuns = []
30 for line in f:
31  exceptionRuns.append(int(line))
32 f.close()
33 
34 #SQL = "select run,tstart,tstop from {}.runs where partition=1 and run>{} and nsubruns>4 order by run asc".format(det,firstrun)
35 SQL = "select run,tstart,tstop from {}.runs where partition=1 and run>{} and nsubruns>4 and tstart < 'yesterday' order by run asc".format(det,firstrun)
36 if (det=='NearDet'):
37  SQL = "select run,tstart,tstop from {}.runs where run>{} and nsubruns>1 and tstart < 'yesterday' order by run asc".format(det,firstrun)
38 
39 cur.execute(SQL)
40 
41 rows = cur.fetchall()
42 
43 irow=0
44 nrows = len(rows)
45 
46 step=20
47 #if (det=='FarDet'):
48 # step=10
49 
50 for irow in range(0,nrows,step):
51 
52  rowList = rows[irow:irow+step]
53  runList = []
54 
55  nrun = len(rowList)
56  firstRun = rowList[0][0]
57  lastRun = rowList[nrun-1][0]
58 # cmd = "getBadChannels -phc {}_{}_{}.csv releases{}.txt {}".format(det,firstRun,lastRun,det,det)
59  cmd = "getBadChannels -pdh releases{}.txt {}".format(det,det)
60 
61  for row in rowList:
62  if row[0] in exceptionRuns:
63  errorMsg = "Run {} found in the exceptions file. Skipping.".format(row[0])
64  print errorMsg
65  continue
66  tstop = row[2]
67  if tstop is not None:
68  cmd += " {}".format(row[0])
69  else:
70  errorMsg = "No stop time found for {} run {}. Stopping now.".format(det,row[0])
71  print errorMsg
72  exit(9)
73 
74  print cmd
75  result = os.system(cmd)
76  if (result > 1) :
77  print "Exit status: {}. Aborting.".format(result)
78  exit(result)
79 
80 # exit(0)
81 
82  f = open(lastrunFile,'w')
83  f.write(str(lastRun))
84  f.close()
85 
86 
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
procfile open("FD_BRL_v0.txt")
exit(0)