#!/usr/bin/python # # # 3/11/24 Justin Stevens # # # This script will modify a tt.db file to rotate the ST as it was cabled in August 2022 after the CPP run and before the final PrimEx run started (run number 1100000) 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 run range ID runrange_name = 'RunPeriod-2022-08-default' cur.execute("SELECT runrangeid FROM RunRange WHERE name='%s'" % runrange_name) rows = cur.fetchall() if len(rows) == 0: print 'Unable to find id for run range with name "%s"!' % runrange_name sys.exit(-1) runrangeid = rows[0][0] for old_sec in range(1,31): # Read in current channel ids cur.execute('SELECT adc_chanid,tdc_chanid,disc_chanid FROM ST WHERE sector="%d"' % (old_sec)) s_rows = cur.fetchall() sector = s_rows[0] # rotate by 8 paddles new_sec = old_sec + 8 if new_sec > 30: new_sec = new_sec - 30 print(old_sec, new_sec) print(sector) # Write in new channel ids cur.execute('INSERT INTO ST Values (%d,%d,%d,%d,%d)' % (new_sec, sector[0], sector[1], sector[2], runrangeid) ) print 'Done'