1 from ConDB
import ConDB
2 from datetime
import datetime, timedelta
3 from timelib
import text2datetime, epoch
5 import psycopg2, psycopg2.extras
8 python getGoodRuns4SAM.py [options] 18 dbcon.append(
"host=ifdbrep.fnal.gov port=5433 dbname=nova_prod ")
19 t0 = text2datetime(
"0")
20 t1 = text2datetime(
"100000000")
22 username =
"nova_reader" 24 opts, args = getopt.getopt(sys.argv[1:],
'U:w:T:')
32 if opt ==
'-U': username = val.strip()
33 elif opt ==
'-w': dbcon.append(
"password=%s " % (val,))
34 elif opt ==
'-T': tag = val
36 print "Unknown argument." 41 print "Tag is required!" 44 dbcon.append(
"user=%s" % (username,))
46 dbcon =
' '.join(dbcon)
47 tname =
"fardet.dq_subrun_info" 48 columns = [
"dbmask",
"flag"]
50 table = db.table(tname, columns)
55 sampwdFile = os.environ[
"SAM4NOVAPWDFILE"]
57 print "Please set the SAM4NOVAPWDFILE environment variable to point to the password file for access to the SAM database" 60 with
open(sampwdFile,
"r") as fin: 61 sampwd = fin.readline().strip() 64 """ Establish connection to SAM database 67 conn = psycopg2.connect(
"dbname=samdev host=cspgsdev.fnal.gov "\
70 cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
72 print "Unable to connect to the SAM database" 76 data = table.getDataIntervalIter(t0, t1, data_type=data_type, tag=tag,
77 channel_range = channel_range)
83 fout =
open(
"/tmp/goodRuns4SAM.csv",
"w")
85 prev_diblock_mask = -1
87 for c, tv, values
in data:
89 run =
int(epoch(tv))/100
90 subrun =
int(epoch(tv))%100
94 diblock_mask =
int(values[0])
98 if ((prev_diblock_mask != diblock_mask)
or (prev_isGood != isGood)):
99 line =
'{0},{1},{2},{3},{4},{5}\n'.
format(run,subrun,tag,diblock_mask,isGood,detname)
102 prev_diblock_mask = diblock_mask
108 print "read %d rows from the NOvA good runs database" % (n,)
110 csvFile =
open(
"/tmp/goodRuns4SAM.csv",
"r") 112 cur.copy_from(csvFile,'nova.good_runs',columns=(
'run_number',
'subrun_number',
'tag',
'diblock_mask',
'good',
'detector'),sep=
',')
118 print "wrote %d rows to the SAM good runs database table" % (nwrote,)
std::string format(const int32_t &value, const int &ndigits=8)
procfile open("FD_BRL_v0.txt")