#!/usr/bin/python3 # # # 3/24/25 Justin Stevens # # # This script will modify a tt.db file to move the # fADC channels for decoding the electron beam helicity # # 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 runrange_name = "RunPeriod-2025-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] #names = ['pattern','settle','helicity','pairsync'] crateid = 1 rocid = 71 moduleid = 9 slot = 10 chanid = 44655 names = ['helicity','pairsync','pattern','settle'] myids = [0,1,2,3] channels = [12,13,14,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'] for name,myid,channel in zip(names, myids, channels): cur.execute("INSERT INTO Channel Values (%d, %d, '%s', %d, 'HELI', 'adc_chanid', 1, %d)" % (chanid, moduleid, name, channel, runrangeid)) adc_chanid = chanid # finally insert into channel table cur.execute("INSERT INTO HELI VALUES (%d, %d, '%s', %d)" % (adc_chanid, myid, name, runrangeid)) chanid = chanid+1 print('Done')