dbjson.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 
5 import sys
6 import os
7 import psycopg2
8 import string
9 #import re
10 
11 if (len(sys.argv) != 2):
12  print ("Usage: dbjson.py [run number]")
13  exit(1)
14 
15 run=sys.argv[1]
16 
17 try:
18  conn = psycopg2.connect("dbname=lbne35t_prod host=ifdbrep.fnal.gov port=5440 user=lbne_reader password=dune35t")
19 except:
20  print ("I am unable to connect to the database")
21  exit(0)
22 
23 cur = conn.cursor()
24 
25 SQL = "select * from dune35t.run_summary where run="+run
26 
27 cur.execute(SQL)
28 row = cur.fetchone()
29 
30 run = row[0]
31 cfg = row[1]
32 runType = row[2]
33 comp = row[3]
34 
35 comp = "35t:"+comp.replace(",",":")
36 
37 # timestamp format from Qizhong's example.json: 2015-02-05T20:19:59
38 tstart = str(row[4]).replace(" ","T")[0:19]
39 tstop = str(row[5]).replace(" ","T")[0:19]
40 # sometimes we get None as the stop time -- put in the start time
41 tstop = str(tstop).replace("None",str(tstart))
42 
43 
44 print (" \"start_time\": \""+tstart+"\",")
45 print (" \"end_time\": \""+tstop+"\",")
46 print (" \"lbne_data.name\": \""+runType+"\",")
47 print (" \"lbne_data.detector_type\": \""+comp+"\",")
48 print (" \"lbne_data.run_mode\": \""+cfg+"\"")
49 print ("}")
50 
51 #print " "
52 #print "original debug output:"
53 #print "Run: ",run
54 #print "ConfigId: ",cfg
55 #print "Run Type: ",runType
56 #print "Components: ",comp
57 #print "Start time: ",tstart
58 #print "Stop time: ",tstop
static QCString str