#!/usr/bin/python # # # 02/13/2015 David Lawrence # # # This script will modify a tt.db file to fix a problem with # two cable swaps in the ST for the fall 2014 commissioning # run. Note that they have since been swapped back so this # fix should only apply to the Fall 2014 commissioning data. # Specifically, runs 660-2460 # # Here is Eric's e-mail sent at 2:55pm on 2/11/2015 # # Hi David, # # As is turns out there was a cable swap effecting four channels of the Start Counter # for the Fall commissioning run. Channel 1 & 2 were swapped and Channel 22 & 23 were # swapped as well. This swap was purely a result of cabling errors on the ST2 enclosure. # # As a result we will need to change the Translation Table portion of the CCDB to map # Channel 1 <-> Channel 2 and similarly Channel 22 <-> Channel 23 for all runs during the # fall commissioning run. # # As far as future running is concerned, we should leave the Translation Table in its # original state for any run that is taken after today (02/11/2015). # # If you have any further questions please do not hesitate to contact me.# # # Kind regards, # -Eric # 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 if this has already been updated sql = 'SELECT channel FROM ST,Channel WHERE system="ST" AND Channel.chanid=ST.adc_chanid AND sector="1"' cur.execute(sql) s_rows = cur.fetchall() if len(s_rows) != 1: print 'Expected exactly one entry for the following query but got %d :' % len(s_rows) print '\n%s' % sql print '\nQuitting now without modifying anything' sys.exit(0); if s_rows[0][0] != 0 : print 'Channel for ST sector one is not "0". This DB may already have been updated.' print '\nQuitting now without modifying anything' sys.exit(0); # Read in all current channel ids cur.execute('SELECT adc_chanid,tdc_chanid,disc_chanid FROM ST WHERE sector="1" OR sector="2" OR sector="22" OR sector="23" ORDER BY sector') s_rows = cur.fetchall() sector1 = s_rows[0] sector2 = s_rows[1] sector22 = s_rows[2] sector23 = s_rows[3] # Set sector 1 cur.execute('UPDATE ST SET adc_chanid=%d,tdc_chanid=%d,disc_chanid=%d WHERE sector=1' % (sector2[0], sector2[1], sector2[2]) ) cur.execute('UPDATE ST SET adc_chanid=%d,tdc_chanid=%d,disc_chanid=%d WHERE sector=2' % (sector1[0], sector1[1], sector1[2]) ) cur.execute('UPDATE ST SET adc_chanid=%d,tdc_chanid=%d,disc_chanid=%d WHERE sector=22' % (sector23[0], sector23[1], sector23[2]) ) cur.execute('UPDATE ST SET adc_chanid=%d,tdc_chanid=%d,disc_chanid=%d WHERE sector=23' % (sector22[0], sector22[1], sector22[2]) ) sql = 'SELECT sector,channel FROM ST,Channel WHERE system="ST" AND Channel.chanid=ST.adc_chanid AND (sector="1" OR sector="2" OR sector="22" OR sector="23") ORDER BY sector' cur.execute(sql) s_rows = cur.fetchall() print s_rows print 'Done'