#!/usr/bin/python # # # 4/8/2022 Justin Stevens # # This script fixes TAGM row=21 col=0 in tt.db for RunPeriod-2019-11+ # 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 to add reference counters runrange_name = 'RunPeriod-2021-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] # Insert correct channel to TAGM and CHANNEL table cur.execute("INSERT INTO TAGM VALUES (21, 0, 24, 520, 392, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (520, 42, 'TAGM-T-21', 23, 'TAGM', 'tdc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (392, 34, 'TAGM-T-21', 8, 'TAGM', 'disc_chanid', 1, %d)" % runrangeid) # Revert old channel back to SPARE cur.execute("INSERT INTO Channel Values (619, 45, 'SPARE', 26, '', 'tdc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (491, 40, 'SPARE', 11, '', 'disc_chanid', 1, %d)" % runrangeid) print 'Done'