#!/usr/bin/python # # # 11/25/2014 David Lawrence # # # This fixes a probelm in the TT with an extra channel that # was defined for row=60, col=31 (or row=31, col=2 in Fernando's # numbering). This is a non-existant block in the FCAL, but the # fADC250 channel is defined. (see https://logbooks.jlab.org/entry/3309107 ) # # This does 2 things: # 1.) Remove the entry from the FCAL table # 2.) Update the name of the channel in the Channel table to be # 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() # Get existing chanid of the offending channel cur.execute('SELECT adc_chanid FROM FCAL WHERE row=60 AND col=31') rows = cur.fetchall() if len(rows) != 1 : print 'There is not exactly one row in FCAL table with row=60, col=31' print 'This file my already have been updated. Stopping now and leaving' print 'file untouched.' sys.exit(0) adc_chanid = rows[0]['adc_chanid'] query = 'DELETE FROM FCAL WHERE adc_chanid=%s' % adc_chanid print query cur.execute(query) query = 'UPDATE Channel SET name="FCAL-unused",system="",col_name="" WHERE chanid=%s' % adc_chanid print query cur.execute(query) cur.execute('SELECT * FROM FCAL') rows = cur.fetchall() print 'Number of rows left in FCAL: %d' % len(rows) print 'Done'