#!/usr/bin/python # # # 8/3/2014 David Lawrence # # # This script will modify a tt.db file to correct a mistake in the original # TT due to a bug in the tt_csv2db.py script that multiplied the connector # number by 48 instead of 24. This caused all of the TDC channel numbers # for the second connector to be shifted by 24. (i.e. in the range from # 48-71 instead of 24-47) # import sqlite3 as lite import sys import os import re import datetime if len(sys.argv) != 2: print "You must supply a SQLite DB file to modify!" sys.exit(0); # Connect to SQLite DB file db_filename = sys.argv[1] print "" print "opening SQLite DB file: %s" % db_filename print "---------------------------------------------" con = lite.connect(db_filename) with con: # Specify that next cursor should be "dictionary" # (i.e. python's hash map) so columns can be indexed # by name con.row_factory = lite.Row # Create Cursor cur = con.cursor() # Check that this TT file has not already been updated sql = 'SELECT tdc_chanid FROM Channel,FDC_Wires WHERE chanid=tdc_chanid AND channel>47' cur.execute(sql) s_rows = cur.fetchall() if len(s_rows) != 1152: print 'This file may have already been updated. Expected 1152 rows from the following' print 'query, but got %d' % len(s_rows) print '\n%s\n' % sql sys.exit(-1) # Correct all channels print 'updating ...' subselect = 'SELECT tdc_chanid FROM Channel,FDC_Wires WHERE chanid=tdc_chanid AND channel>47' sql = 'UPDATE Channel SET channel=(channel-24) WHERE chanid IN (%s)' % subselect cur.execute(sql) print 'Done'