#!/usr/bin/python # # # 12/02/2019 Justin Stevens # # # This script moves the TAC tdc and disc counters # 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 TAC WHERE tdc_chanid=43254") rf_rows = cur.fetchall() if len(rf_rows) != 0: print 'TAC tdc channel already moved!' sys.exit(-1) runrange_name = 'RunPeriod-2019-11-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] cur.execute("SELECT MAX(chanid) FROM Channel") row = cur.fetchone() chanid = row[0]+1 tdc_chanid = chanid disc_chanid = chanid+1 name = 'TAC-T' cratename = 'D2-1-MID' rocid = 78 slot = 8 channel = 26 cur.execute("SELECT moduleid from Module,Crate where rocid==%d and slot==%d and module.crateid==crate.crateid" % (rocid,slot)) row = cur.fetchone() moduleid = row['moduleid'] cur.execute("INSERT INTO Channel Values (%d, %d, '%s', %d, 'TAC', 'tdc_chanid', 1, %d)" % (tdc_chanid, moduleid, name, channel, runrangeid)) name = 'TAC-T' cratename = 'D2-1-BOT' rocid = 79 slot = 15 channel = 15 cur.execute("SELECT moduleid from Module,Crate where rocid==%d and slot==%d and module.crateid==crate.crateid" % (rocid,slot)) row = cur.fetchone() moduleid = row['moduleid'] cur.execute("INSERT INTO Channel Values (%d, %d, '%s', %d, 'TAC', 'disc_chanid', 1, %d)" % (disc_chanid, moduleid, name, channel, runrangeid)) adc_chanid = 27172 cur.execute("INSERT INTO TAC VALUES (%d, %d, %d, %d)" % (adc_chanid, tdc_chanid, disc_chanid, runrangeid)) print 'Done'