#!/usr/bin/python # # # 8/9/2014 David Lawrence # # # This script will modify a tt.db file to use the correct fADC channel numbers # for the FDC cathode strips in connectors attached to strip type "B" strips. # This corrects a mistake built into the tt_fix_fdc_strip_no.py script. This should # be run after that is run. The issue is that the connector for "B" type strips # actually has them attached in reverse order since it is on the opposite side # of the plane and therefore rotated 180 degrees wrt the other connectors. Oddly # enough, the original tt.db had these strips in the correct order, but they were # changed along with all of the other strips in tt_fix_fdc_strip_no.py. The correct # final mapping for "B" type strip should be: # # 48 <= channel <= 71 85 >= strip >= 108 # # All "A" type and "full" type strips should have the strip number increasing as # the channel number decreases. # 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 strip,channel FROM Channel,FDC_Cathodes WHERE chanid=adc_chanid AND strip_type="B" AND strip=85 AND channel=71' cur.execute(sql) s_rows = cur.fetchall() if len(s_rows) != 48: print 'This file may have already been updated. Expected 48 rows from the following' print 'query, but got %d' % len(s_rows) print '\n%s\n' % sql sys.exit(-1) # Correct channels 0-23 print 'updating channels for "B" type strips ...' subselect = 'SELECT adc_chanid FROM Channel,FDC_Cathodes WHERE chanid=adc_chanid AND strip_type="B" AND (channel BETWEEN 48 AND 71)' sql = 'UPDATE Channel SET channel=(71-channel+48) WHERE chanid IN (%s)' % subselect cur.execute(sql) print 'Done'