#!/usr/bin/python # # # 11/18/2019 Justin Stevens # # # This script will modify a tt.db file to add the # DIRC LED reference 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() ######################## ## Reference counters ## ######################## # get run range ID to add reference counters runrange_name = 'RunPeriod-2023-01-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 cur.execute("SELECT MAX(moduleid) FROM Module") row = cur.fetchone() moduleid = row[0]+1 # get channel and module ID to start counting from cratename = 'D2-1-TOP' rocid = 77 slot = 16 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() cur.execute("INSERT INTO Channel Values (41140, 1048, 'DIRC_LED_REF_A', 15, 'DIRC_REF', 'adc_chanid', 0, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (43766, 1058, 'DIRC_REF-unused', 15, '', '', 0, %d)" % runrangeid) # finally insert into channel table adc_chanid = 41140 tdc_chanid = 41141 cur.execute("INSERT INTO DIRC_REF VALUES (%d, %d, %d)" % (adc_chanid, tdc_chanid, runrangeid)) print 'Done'