#!/usr/bin/python ''' Created on Aug 19, 2016 @author: Hovanes Egiyan ''' from subsystem import subsystem as subsystem from mpod import MPODCrate as MPODCrate def initCrates(): retDict = dict() crateInst = MPODCrate( "U1", "10", "MID", "U1-10-MID", "halldmpod3", "501" ) crateInst.AddMPV_8016Board( 0, 602 ) crateInst.AddEHS_205PBoard( 1, 603 ) crateInst.rocid = 911 retDict["U1-10-MID"] = crateInst return retDict def openSQLFile( fileName="tpol.sql" ): try : outFile = open( fileName, "w") except IOError as err: raise err sql_string = 'CREATE TABLE Crate(crateid INTEGER PRIMARY KEY, name TEXT, area TEXT, rack INT, location TEXT, SN TEXT, Function TEXT, rocid INT, host TEXT, IP TEXT);\n' outFile.write(sql_string) sql_string = 'CREATE TABLE Module(moduleid INTEGER PRIMARY KEY, crateid INTEGER, slot INT, type TEXT, SN TEXT);\n' outFile.write(sql_string) sql_string = 'CREATE TABLE Channel(chanid INTEGER PRIMARY KEY, moduleid INTEGER, name TEXT, channel INT, system TEXT, col_name TEXT, enable INTEGER DEFAULT 1);\n' outFile.write(sql_string) sql_string = 'CREATE TABLE Detector_Hierarchy( id INTEGER PRIMARY KEY, parent_id INTEGER, name TEXT, type TEXT, chanid INTEGER, mtime DATETIME DEFAULT CURRENT_TIMESTAMP);\n' outFile.write(sql_string) outFile.write("\n\n\n") return outFile if __name__ == '__main__': print "Opening file" outFile = openSQLFile( "tpol.sql" ) crates = initCrates() # print len(beamCrate.boardDict) print "Initializing detector" print "Making SQL" # Make the TPOL detector entry detName = "TPOL" tpol = subsystem( None, "Detector", detName ) tpol.makeSQL(outFile) # Make the TPOL-LV subsystem entry tpol_LV = subsystem( tpol, "Voltage type", "lv" ) tpol_LV.makeSQL(outFile) # Amplifiers tpol_LV_amps = subsystem( tpol_LV, "Detector Component", "amps" ) tpol_LV_amps.makeSQL(outFile) # +12V voltage for amps tpolSlot = 0 tpolChannel = 0 tpolCrate = crates["U1-10-MID"] channid = tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].chanid tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].system = detName tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].name = str(tpolChannel) tpol_LV_chan = subsystem( tpol_LV_amps, "LV Channel", "12Vp", channid ) tpol_LV_chan.makeSQL(outFile) # -12V voltage for amps tpolSlot = 0 tpolChannel = 1 tpolCrate = crates["U1-10-MID"] channid = tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].chanid tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].system = detName tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].name = str(tpolChannel) tpol_LV_chan = subsystem( tpol_LV_amps, "LV Channel", "12Vn", channid ) tpol_LV_chan.makeSQL(outFile) # Fans tpol_LV_filt = subsystem( tpol_LV, "Detector Component", "filt" ) tpol_LV_filt.makeSQL(outFile) # +5V voltage for filt tpolSlot = 0 tpolChannel = 2 tpolCrate = crates["U1-10-MID"] channid = tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].chanid tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].system = detName tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].name = str(tpolChannel) tpol_LV_chan = subsystem( tpol_LV_filt, "LV Channel", "5Vp", channid ) tpol_LV_chan.makeSQL(outFile) # -8V voltage for filt tpolSlot = 0 tpolChannel = 3 tpolCrate = crates["U1-10-MID"] channid = tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].chanid tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].system = detName tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].name = str(tpolChannel) tpol_LV_chan = subsystem( tpol_LV_filt, "LV Channel", "5Vn", channid ) tpol_LV_chan.makeSQL(outFile) # Make the TPOL-BIAS subsystem entry tpol_BIAS = subsystem( tpol, "Voltage type", "bias" ) tpol_BIAS.makeSQL(outFile) # bias voltage channel tpolSlot = 1 tpolChannel = 0 tpolCrate = crates["U1-10-MID"] channid = tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].chanid tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].system = detName tpolCrate.boardDict[tpolSlot].channelMap[tpolChannel].name = str(tpolChannel) tpol_BIAS_chan = subsystem( tpol_BIAS, "Bias Channel", "0", channid ) tpol_BIAS_chan.makeSQL(outFile) # Make SQL entries for the crates themselves for crateName in crates.keys(): crates[crateName].makeSQL(outFile)