#!/usr/bin/python ''' Created on Aug 19, 2016 @author: Hovanes Egiyan ''' from subsystem import subsystem as subsystem from mpod import MPODCrate as MPODCrate, MPV_8008Board as MPV_8008Board, MPV_8030Board as MPV_8030Board from caen import CaenCrate as CaenCrate, A7236SNBoard as A7236SNBoard def initCrates(): retDict = dict() crateInst = MPODCrate( "D2", "5", "MID", "D2-5-MID", "d2-5-mid", "701" ) crateInst.AddBoard( MPV_8008Board, 0, 612 ) crateInst.AddBoard( MPV_8030Board, 1, 612 ) crateInst.rocid = 9166 retDict["D2-5-MID"] = crateInst crateInst = CaenCrate( "D2", "8", "MID", "D2-8-MID", "d2-8-MID", "805" ) crateInst.AddBoard( A7236SNBoard, 14, 1515 ) crateInst.rocid = 9104 retDict["D2-8-MID"] = crateInst return retDict def openSQLFile( fileName="pulsers.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( "pulsers.sql" ) crates = initCrates() # print len(beamCrate.boardDict) print "Initializing detector" print "Making SQL" # Make the COMCAL detector entry detName = "COMCAL" comcal = subsystem( None, "Detector", detName ) comcal.makeSQL(outFile) # Make the COMCAL-PULSER-LV subsystem entry comcal_LV = subsystem( comcal, "Voltage type", "lv" ) comcal_LV.makeSQL(outFile) # +5V voltage for LED comcalSlot = 0 comcalChannel = 5 comcalCrate = crates["D2-5-MID"] channid = comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].chanid comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].system = detName comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].name = str(comcalChannel) comcal_LV_chan = subsystem( comcal_LV, "LV Channel", "pulser", channid ) comcal_LV_chan.makeSQL(outFile) # Make the COMCAL-PULSER-BIAS subsystem entry comcal_BIAS = subsystem( comcal, "Voltage type", "bias" ) comcal_BIAS.makeSQL(outFile) # bias voltage channel comcalSlot = 1 comcalChannel = 6 comcalCrate = crates["D2-5-MID"] channid = comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].chanid comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].system = detName comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].name = str(comcalChannel) comcal_BIAS_chan = subsystem( comcal_BIAS, "Bias Channel", "pulser", channid ) comcal_BIAS_chan.makeSQL(outFile) # Make the COMCAL-PULSER-HV subsystem entry comcal_HV = subsystem( comcal, "Voltage type", "hv" ) comcal_HV.makeSQL(outFile) comcal_HV_pulser = subsystem( comcal_HV, "Component", "pulser" ) comcal_HV_pulser.makeSQL(outFile) comcalCrate = crates["D2-8-MID"] comcalSlot = 14 comcalChannel = 22 channid = comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].chanid comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].system = detName comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].name = str(comcalChannel) comcal_HV_chan = subsystem( comcal_HV_pulser, "HV Channel", "1", channid ) comcal_HV_chan.makeSQL(outFile) comcalChannel = 23 channid = comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].chanid comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].system = detName comcalCrate.boardDict[comcalSlot].channelMap[comcalChannel].name = str(comcalChannel) comcal_HV_chan = subsystem( comcal_HV_pulser, "HV Channel", "2", channid ) comcal_HV_chan.makeSQL(outFile) detName = "DIRC" dirc = subsystem( None, "Detector", detName ) dirc.makeSQL(outFile) # Make the DIRC-PULSER-LV subsystem entry dirc_LV = subsystem( dirc, "Voltage type", "lv" ) dirc_LV.makeSQL(outFile) dirc_LV_pulser = subsystem( dirc_LV, "Subsystem", "pulser" ) dirc_LV_pulser.makeSQL(outFile) # +5V voltage for LED dircSlot = 0 dircChannel = 4 dircCrate = crates["D2-5-MID"] channid = dircCrate.boardDict[dircSlot].channelMap[dircChannel].chanid dircCrate.boardDict[dircSlot].channelMap[dircChannel].system = detName dircCrate.boardDict[dircSlot].channelMap[dircChannel].name = str(dircChannel) dirc_LV_chan_5V = subsystem( dirc_LV_pulser, "LV Channel", "5V", channid ) dirc_LV_chan_5V.makeSQL(outFile) # +12V voltage for readout dircSlot = 1 dircChannel = 5 dircCrate = crates["D2-5-MID"] channid = dircCrate.boardDict[dircSlot].channelMap[dircChannel].chanid dircCrate.boardDict[dircSlot].channelMap[dircChannel].system = detName dircCrate.boardDict[dircSlot].channelMap[dircChannel].name = str(dircChannel) dirc_LV_chan_12V = subsystem( dirc_LV_pulser, "LV Channel", "12V", channid ) dirc_LV_chan_12V.makeSQL(outFile) # Make the DIRC-PULSER-BIAS subsystem entry dirc_BIAS = subsystem( dirc, "Voltage type", "bias" ) dirc_BIAS.makeSQL(outFile) # bias voltage channel dircSlot = 1 dircChannel = 4 dircCrate = crates["D2-5-MID"] channid = dircCrate.boardDict[dircSlot].channelMap[dircChannel].chanid dircCrate.boardDict[dircSlot].channelMap[dircChannel].system = detName dircCrate.boardDict[dircSlot].channelMap[dircChannel].name = str(dircChannel) dirc_BIAS_chan = subsystem( dirc_BIAS, "Bias Channel", "pulser", channid ) dirc_BIAS_chan.makeSQL(outFile) # Make SQL entries for the crates themselves for crateName in crates.keys(): crates[crateName].makeSQL(outFile)