#!/usr/bin/python # # # 12/8/2015 Paul Mattione # # # This script adds the Halo counters, TAC, and active-target to the translation table. # 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 sqlite_master WHERE type = 'table' AND name = 'HALO'") rf_rows = cur.fetchall() if len(rf_rows) != 0: print 'HALO table was already created' sys.exit(-1) # Add crates (crateid|name|area|rack|location|SN|Function|rocid|host|IP) cur.execute("INSERT INTO Crate Values (79, 'D2-5-TOP', 'D2', 5, 'TOP', '', 'DISC', 375, 'iocpulser1', '129.57.26.119')") #iocpulser1 #rocid = 256 + 119 cur.execute("INSERT INTO Crate Values (80, 'U1-1-TOP', 'U1', 1, 'TOP', '', 'DISC', 393, 'iocpulser2', '129.57.26.137')") #iocpulser2 #rocid = 256 + 137 cur.execute("INSERT INTO Crate Values (81, 'T1-6', 'T1', 6, '', '', 'DISC', 451, 'ioctagctrl', '129.57.26.195')") #ioctagctrl #rocid = 256 + 195 ################################################################### HALO ################################################################### # make HALO table cur.execute("CREATE TABLE HALO(beam TEXT, location TEXT, side TEXT, disc_chanid INT)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'tag', 'left', 27155)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'tag', 'top', 27156)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'tag', 'right', 27157)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'tag', 'bottom', 27158)") cur.execute("INSERT INTO HALO VALUES ('electron', 'tag', 'left', 27159)") cur.execute("INSERT INTO HALO VALUES ('electron', 'tag', 'top', 27160)") cur.execute("INSERT INTO HALO VALUES ('electron', 'tag', 'bottom', 27161)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'col', 'left', 27162)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'col', 'top', 27163)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'col', 'right', 27164)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'col', 'bottom', 27165)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'tgt', 'left', 27166)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'tgt', 'top', 27167)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'tgt', 'right', 27168)") cur.execute("INSERT INTO HALO VALUES ('gamma', 'tgt', 'bottom', 27169)") # Add modules for HALO (moduleid|crateid|slot|type|SN) cur.execute("INSERT INTO Module Values (1025, 81, 3, 'DISC', '')") #ioctagctrl cur.execute("INSERT INTO Module Values (1026, 80, 5, 'DISC', '')") #iocpulser2 # Add channels for HALO (chanid|moduleid|name|channel|system|col_name|enable) cur.execute("INSERT INTO Channel Values (27155, 1025, 'HALO-T-gamma-tag-left', 1, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27156, 1025, 'HALO-T-gamma-tag-top', 2, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27157, 1025, 'HALO-T-gamma-tag-right', 3, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27158, 1025, 'HALO-T-gamma-tag-bottom', 4, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27159, 1025, 'HALO-T-electron-tag-left', 5, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27160, 1025, 'HALO-T-electron-tag-top', 6, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27161, 1025, 'HALO-T-electron-tag-bottom', 7, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27162, 1026, 'HALO-T-gamma-col-left', 1, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27163, 1026, 'HALO-T-gamma-col-top', 2, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27164, 1026, 'HALO-T-gamma-col-right', 3, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27165, 1026, 'HALO-T-gamma-col-bottom', 4, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27166, 1026, 'HALO-T-gamma-tgt-left', 5, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27167, 1026, 'HALO-T-gamma-tgt-top', 6, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27168, 1026, 'HALO-T-gamma-tgt-right', 7, 'HALO', 'disc_chanid', 1)") cur.execute("INSERT INTO Channel Values (27169, 1026, 'HALO-T-gamma-tgt-bottom', 8, 'HALO', 'disc_chanid', 1)") ############################################################### Active_Target ############################################################## #make Active_Target table cur.execute("CREATE TABLE Active_Target(disc_chanid INT)") cur.execute("INSERT INTO Active_Target VALUES (27170)") # Add module for Active_Target (moduleid|crateid|slot|type|SN) cur.execute("INSERT INTO Module Values (1027, 79, 15, 'DISC', '')") #iocpulser1 # Add channel for Active_Target (chanid|moduleid|name|channel|system|col_name|enable) cur.execute("INSERT INTO Channel Values (27170, 1027, 'Active_Target-T', 1, 'Active_Target', 'disc_chanid', 1)") ################################################################### TAC #################################################################### #make TAC table cur.execute("CREATE TABLE TAC(adc_chanid INT, tdc_chanid INT, disc_chanid INT)") cur.execute("INSERT INTO TAC VALUES (24342, 23912, 27171)") # Add module for TAC (moduleid|crateid|slot|type|SN) cur.execute("INSERT INTO Module Values (1028, 63, 15, 'DISC', '')") # Add channels for TAC (chanid|moduleid|name|channel|system|col_name|enable) cur.execute("INSERT INTO Channel Values (27171, 1028, 'TAC-T', 1, 'TAC', 'disc_chanid', 1)") # Update channels for TAC (were SPARE and FCAL-unused) cur.execute("UPDATE Channel SET name='TAC-T', system='TAC', col_name='tdc_chanid' WHERE chanid='23912'") cur.execute("UPDATE Channel SET name='TAC-A', system='TAC', col_name='adc_chanid' WHERE chanid='24342'") print 'Done'