#!/usr/bin/python # # # 4/8/2022 Justin Stevens # # This script sets the correct mapping in Triplet Polarimeter signal channels to 4 FADC boards # Note: this was implemented in the CCDB in 2020 but not updated in SVN # 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] # TPOL (chanid|moduleid|name|channel|system|col_name|enable) # Move 8 TPOL channels to existing 2nd FADC board cur.execute("INSERT INTO TPOL Values (25, 0, 27123, %d)" % runrangeid) cur.execute("INSERT INTO TPOL Values (24, 0, 27124, %d)" % runrangeid) cur.execute("INSERT INTO TPOL Values (23, 0, 27125, %d)" % runrangeid) cur.execute("INSERT INTO TPOL Values (22, 0, 27126, %d)" % runrangeid) cur.execute("INSERT INTO TPOL Values (21, 0, 27127, %d)" % runrangeid) cur.execute("INSERT INTO TPOL Values (20, 0, 27128, %d)" % runrangeid) cur.execute("INSERT INTO TPOL Values (19, 0, 27129, %d)" % runrangeid) cur.execute("INSERT INTO TPOL Values (18, 0, 27130, %d)" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=17 WHERE ADC_CHANID=27139 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=16 WHERE ADC_CHANID=27140 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=15 WHERE ADC_CHANID=27141 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=14 WHERE ADC_CHANID=27142 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=13 WHERE ADC_CHANID=27143 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=12 WHERE ADC_CHANID=27144 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=11 WHERE ADC_CHANID=27145 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=10 WHERE ADC_CHANID=27146 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=6 WHERE ADC_CHANID=27154 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=8 WHERE ADC_CHANID=27155 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=7 WHERE ADC_CHANID=27156 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=9 WHERE ADC_CHANID=27157 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=5 WHERE ADC_CHANID=27158 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=4 WHERE ADC_CHANID=27159 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=3 WHERE ADC_CHANID=27160 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=2 WHERE ADC_CHANID=27161 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=1 WHERE ADC_CHANID=27162 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=32 WHERE ADC_CHANID=27163 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=31 WHERE ADC_CHANID=27164 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=30 WHERE ADC_CHANID=27165 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=29 WHERE ADC_CHANID=27166 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=28 WHERE ADC_CHANID=27167 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=27 WHERE ADC_CHANID=27168 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE TPOL SET SECTOR=26 WHERE ADC_CHANID=27169 and RUNRANGEID=%d" % runrangeid) cur.execute("INSERT INTO Channel Values (27123, 1022, 'TPOL-S25', 0, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27124, 1022, 'TPOL-S24', 1, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27125, 1022, 'TPOL-S23', 2, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27126, 1022, 'TPOL-S22', 3, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27127, 1022, 'TPOL-S21', 4, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27128, 1022, 'TPOL-S20', 5, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27129, 1022, 'TPOL-S19', 6, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) cur.execute("INSERT INTO Channel Values (27130, 1022, 'TPOL-S18', 7, 'TPOL', 'adc_chanid', 1, %d)" % runrangeid) # update those that were already changed in RunPeriod-2019-11+ cur.execute("UPDATE Channel SET NAME='TPOL-S17' WHERE CHANID=27139 and MODULEID=1023 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S16' WHERE CHANID=27140 and MODULEID=1023 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S15' WHERE CHANID=27141 and MODULEID=1023 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S14' WHERE CHANID=27142 and MODULEID=1023 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S13' WHERE CHANID=27143 and MODULEID=1023 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S12' WHERE CHANID=27144 and MODULEID=1023 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S11' WHERE CHANID=27145 and MODULEID=1023 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S10' WHERE CHANID=27146 and MODULEID=1023 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S6' WHERE CHANID=27154 and MODULEID=1059 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S8' WHERE CHANID=27155 and MODULEID=1059 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S7' WHERE CHANID=27156 and MODULEID=1059 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S9' WHERE CHANID=27157 and MODULEID=1059 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S5' WHERE CHANID=27158 and MODULEID=1059 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S4' WHERE CHANID=27159 and MODULEID=1059 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S3' WHERE CHANID=27160 and MODULEID=1059 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S2' WHERE CHANID=27161 and MODULEID=1059 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S1' WHERE CHANID=27162 and MODULEID=1060 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S32' WHERE CHANID=27163 and MODULEID=1060 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S31' WHERE CHANID=27164 and MODULEID=1060 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S30' WHERE CHANID=27165 and MODULEID=1060 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S29' WHERE CHANID=27166 and MODULEID=1060 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S28' WHERE CHANID=27167 and MODULEID=1060 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S27' WHERE CHANID=27168 and MODULEID=1060 and RUNRANGEID=%d" % runrangeid) cur.execute("UPDATE Channel SET NAME='TPOL-S26' WHERE CHANID=27169 and MODULEID=1060 and RUNRANGEID=%d" % runrangeid)