#!/usr/bin/python # # # 8/10/2015 Paul Mattione # # ##### Fixes the TOF discriminator HV and discriminator channels # # Before this fix, the channels with system="TOF" and col_name="disc_chanid" were actually HV channels: Change the col_name to "hv_chanid" # # Crateid 63 (D2-1-BOT) contains the TOF discriminators. Set its rocid=79. # # For all of the discriminator channels on this crate (moduleid's 775 through 785): set system="TOF and col_name="disc_chanid" # # Put the correct channel IDs for the discriminator in the TOF table # 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 cur.execute("SELECT * FROM TOF WHERE disc_chanid=26911") Nrows = len( cur.fetchall() ) if Nrows == 0: print 'Fix has already been applied, exiting' sys.exit(-1) # SWITCH "disc_chanid" to "hv_chanid" for TOF: query = "UPDATE Channel SET col_name='hv_chanid' WHERE system='TOF' AND col_name='disc_chanid'" cur.execute(query) # SET the rocid for the TOF discriminator crate query = "UPDATE Crate SET rocid=79 WHERE crateid=63" cur.execute(query) # For all chanids with moduleids 775 through 785: set system="TOF" set col_name="disc_chanid" for moduleid in range(775, 786): query = "UPDATE Channel SET system='TOF' WHERE moduleid=%d" % (moduleid) cur.execute(query) query = "UPDATE Channel SET col_name='disc_chanid' WHERE moduleid=%d" % (moduleid) cur.execute(query) # Put the correct channel IDs for the discriminator in the TOF table # HV: 26911 - 27086: N/S/UP/DW # DISC: 23926 - 24101: N/S/UP/DW for hv_chanid in range(26911, 27087): disc_chanid = hv_chanid - 2985 query = "UPDATE TOF SET disc_chanid=%d WHERE disc_chanid=%d" % (disc_chanid, hv_chanid) cur.execute(query) print 'Done'