#!/usr/bin/python # # # 1/31/2023 Justin Stevens # # This script fixes TAGM row=85-90 and 100-102 in tt.db for RunPeriod-2021-08+ # 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+' 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] # col 85 -> 90 cur.execute("UPDATE Channel SET name='TAGM-A-90' WHERE chanid=102") cur.execute("UPDATE Channel SET name='TAGM-T-90' WHERE chanid=598") cur.execute("UPDATE Channel SET name='TAGM-T-90' WHERE chanid=470") cur.execute("UPDATE TAGM SET adc_chanid=102 WHERE col=90") cur.execute("UPDATE TAGM SET tdc_chanid=598 WHERE col=90") cur.execute("UPDATE TAGM SET disc_chanid=470 WHERE col=90") # col 86 -> 89 cur.execute("UPDATE Channel SET name='TAGM-A-89' WHERE chanid=101") cur.execute("UPDATE Channel SET name='TAGM-T-89' WHERE chanid=597") cur.execute("UPDATE Channel SET name='TAGM-T-89' WHERE chanid=469") cur.execute("UPDATE TAGM SET adc_chanid=101 WHERE col=89") cur.execute("UPDATE TAGM SET tdc_chanid=597 WHERE col=89") cur.execute("UPDATE TAGM SET disc_chanid=469 WHERE col=89") # col 87 -> 88 cur.execute("UPDATE Channel SET name='TAGM-A-88' WHERE chanid=100") cur.execute("UPDATE Channel SET name='TAGM-T-88' WHERE chanid=596") cur.execute("UPDATE Channel SET name='TAGM-T-88' WHERE chanid=468") cur.execute("UPDATE TAGM SET adc_chanid=100 WHERE col=88") cur.execute("UPDATE TAGM SET tdc_chanid=596 WHERE col=88") cur.execute("UPDATE TAGM SET disc_chanid=468 WHERE col=88") # col 90 -> 85 cur.execute("UPDATE Channel SET name='TAGM-A-85' WHERE chanid=103") cur.execute("UPDATE Channel SET name='TAGM-T-85' WHERE chanid=599") cur.execute("UPDATE Channel SET name='TAGM-T-85' WHERE chanid=471") cur.execute("UPDATE TAGM SET adc_chanid=103 WHERE col=85") cur.execute("UPDATE TAGM SET tdc_chanid=599 WHERE col=85") cur.execute("UPDATE TAGM SET disc_chanid=471 WHERE col=85") # col 89 -> 86 cur.execute("UPDATE Channel SET name='TAGM-A-86' WHERE chanid=104") cur.execute("UPDATE Channel SET name='TAGM-T-86' WHERE chanid=600") cur.execute("UPDATE Channel SET name='TAGM-T-86' WHERE chanid=472") cur.execute("UPDATE TAGM SET adc_chanid=104 WHERE col=86") cur.execute("UPDATE TAGM SET tdc_chanid=600 WHERE col=86") cur.execute("UPDATE TAGM SET disc_chanid=472 WHERE col=86") # col 88 -> 87 cur.execute("UPDATE Channel SET name='TAGM-A-87' WHERE chanid=105") cur.execute("UPDATE Channel SET name='TAGM-T-87' WHERE chanid=601") cur.execute("UPDATE Channel SET name='TAGM-T-87' WHERE chanid=473") cur.execute("UPDATE TAGM SET adc_chanid=105 WHERE col=87") cur.execute("UPDATE TAGM SET tdc_chanid=601 WHERE col=87") cur.execute("UPDATE TAGM SET disc_chanid=473 WHERE col=87") # col 100 -> 102 cur.execute("UPDATE Channel SET name='TAGM-A-102' WHERE chanid=120") cur.execute("UPDATE Channel SET name='TAGM-T-102' WHERE chanid=616") cur.execute("UPDATE Channel SET name='TAGM-T-102' WHERE chanid=488") cur.execute("UPDATE TAGM SET adc_chanid=120 WHERE col=102") cur.execute("UPDATE TAGM SET tdc_chanid=616 WHERE col=102") cur.execute("UPDATE TAGM SET disc_chanid=488 WHERE col=102") # col 102 -> 100 cur.execute("UPDATE Channel SET name='TAGM-A-100' WHERE chanid=122") cur.execute("UPDATE Channel SET name='TAGM-T-100' WHERE chanid=618") cur.execute("UPDATE Channel SET name='TAGM-T-100' WHERE chanid=490") cur.execute("UPDATE TAGM SET adc_chanid=122 WHERE col=100") cur.execute("UPDATE TAGM SET tdc_chanid=618 WHERE col=100") cur.execute("UPDATE TAGM SET disc_chanid=490 WHERE col=100") print 'Done'