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