#!/usr/bin/python # # # 1/10/2020 Justin Stevens # # This script splits the Triplet Polarimeter signal channels to 4 FADC boards # 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-2019-11+' 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 #rocid 84, crateid 13 # Add modules for TPOL (moduleid|crateid|slot|type|SN) #others already exist cur.execute("INSERT INTO Module Values (%d, 13, 15, 'FADC250', '')" % moduleid) #rocps2 moduleid += 1 cur.execute("INSERT INTO Module Values (%d, 13, 16, 'FADC250', '')" % moduleid) #rocps2 # Make previously used TPOL channels "unused" so they don't appear in tt.xml for chanid in range(27131, 27139): cur.execute("INSERT INTO Channel Values (27139, 1023, 'TPOL-S9', 0, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) # "UPDATE Channel SET name='TPOL-unused', system='', col_name='', enable=0 WHERE chanid='%d'" % chanid) for chanid in range(27147, 27155): cur.execute("UPDATE Channel SET name='TPOL-unused', system='', col_name='', enable=0 WHERE chanid='%d'" % chanid) # TPOL (chanid|moduleid|name|channel|system|col_name|enable) # Move 8 TPOL channels to existing 2nd FADC board cur.execute("INSERT INTO TPOL VALUES (9, 0, 27139, %d)" % runrangeid) cur.execute("INSERT INTO TPOL VALUES (10, 0, 27140, %d)" % runrangeid) cur.execute("INSERT INTO TPOL VALUES (11, 0, 27141, %d)" % runrangeid) cur.execute("INSERT INTO TPOL VALUES (12, 0, 27142, %d)" % runrangeid) cur.execute("INSERT INTO TPOL VALUES (13, 0, 27143, %d)" % runrangeid) cur.execute("INSERT INTO TPOL VALUES (14, 0, 27144, %d)" % runrangeid) cur.execute("INSERT INTO TPOL VALUES (15, 0, 27145, %d)" % runrangeid) cur.execute("INSERT INTO TPOL VALUES (16, 0, 27146, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27139, 1023, 'TPOL-S9', 0, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27140, 1023, 'TPOL-S10', 1, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27141, 1023, 'TPOL-S11', 2, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27142, 1023, 'TPOL-S12', 3, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27143, 1023, 'TPOL-S13', 4, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27144, 1023, 'TPOL-S14', 5, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27145, 1023, 'TPOL-S15', 6, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27146, 1023, 'TPOL-S16', 7, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) # Move 16 TPOL channels to two new FADC boards not previously in TT moduleid -= 1 channel = 0 for sector in range(17, 33): if sector == 25: moduleid += 1 channel -= 8 print(sector, moduleid, channel) cur.execute("INSERT INTO TPOL VALUES (%d, 0, %d, %d)" % (sector, chanid, runrangeid)) cur.execute("INSERT INTO Channel Values (%d, %d, 'TPOL-S%d', %d, 'TPOL', 'adc_chanid', 1, %d)" % (chanid, moduleid, sector, channel, runrangeid)) chanid += 1 channel += 1 print 'Done' ''' cur.execute("INSERT INTO TPOL VALUES (17, 0, 27139)") cur.execute("INSERT INTO TPOL VALUES (18, 0, 27140)") cur.execute("INSERT INTO TPOL VALUES (19, 0, 27141)") cur.execute("INSERT INTO TPOL VALUES (20, 0, 27142)") cur.execute("INSERT INTO TPOL VALUES (21, 0, 27143)") cur.execute("INSERT INTO TPOL VALUES (22, 0, 27144)") cur.execute("INSERT INTO TPOL VALUES (23, 0, 27145)") cur.execute("INSERT INTO TPOL VALUES (24, 0, 27146)") cur.execute("INSERT INTO TPOL VALUES (25, 0, 27147)") cur.execute("INSERT INTO TPOL VALUES (26, 0, 27148)") cur.execute("INSERT INTO TPOL VALUES (27, 0, 27149)") cur.execute("INSERT INTO TPOL VALUES (28, 0, 27150)") cur.execute("INSERT INTO TPOL VALUES (29, 0, 27151)") cur.execute("INSERT INTO TPOL VALUES (30, 0, 27152)") cur.execute("INSERT INTO TPOL VALUES (31, 0, 27153)") cur.execute("INSERT INTO TPOL VALUES (32, 0, 27154)") cur.execute("INSERT INTO Channel Values (43766, 1058, 'TPOL-S17', 0, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43767, 1058, 'TPOL-S18', 1, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43768, 1058, 'TPOL-S19', 2, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43769, 1058, 'TPOL-S20', 3, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43770, 1058, 'TPOL-S21', 4, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43771, 1058, 'TPOL-S22', 5, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43772, 1058, 'TPOL-S23', 6, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43773, 1058, 'TPOL-S24', 7, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43774, 1059, 'TPOL-S25', 8, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43775, 1059, 'TPOL-S26', 9, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43776, 1059, 'TPOL-S27', 10, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43777, 1059, 'TPOL-S28', 11, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43778, 1059, 'TPOL-S29', 12, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43779, 1059, 'TPOL-S30', 13, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43780, 1059, 'TPOL-S31', 14, 'TPOL', 'adc_chanid', 31)") cur.execute("INSERT INTO Channel Values (43781, 1059, 'TPOL-S32', 15, 'TPOL', 'adc_chanid', 31)") '''