Commit in hps-java/src/main/java/org/lcsim/hps/conditions/svt on MAIN | |||
ChannelData.java | +38 | added 1.1 | |
ChannelLoader.java | +69 | added 1.1 | |
ChannelMap.java | +30 | added 1.1 | |
+137 |
preliminary set of utility classes for representing SVT conditions from db; work in progress
diff -N ChannelData.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ChannelData.java 19 Sep 2013 01:27:15 -0000 1.1 @@ -0,0 +1,38 @@
+package org.lcsim.hps.conditions.svt; + +public class ChannelData { + + int fpga, hybrid, channel; + + ChannelData(int fpga, int hybrid, int channel) { + this.fpga = fpga; + this.hybrid = hybrid; + this.channel = channel; + } + + public int getFpga() { + return fpga; + } + + public int getHybrid() { + return hybrid; + } + + public int getChannel() { + return channel; + } + + /** + * Implementation of equals. + */ + public boolean equals(Object obj) { + if (obj == null) + return false; + if (obj == this) + return true; + if (!(obj instanceof ChannelData)) + return false; + ChannelData c = (ChannelData)obj; + return c.getFpga() == fpga && c.getHybrid() == hybrid && c.getChannel() == channel; + } +}
diff -N ChannelLoader.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ChannelLoader.java 19 Sep 2013 01:27:15 -0000 1.1 @@ -0,0 +1,69 @@
+package org.lcsim.hps.conditions.svt; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.lcsim.hps.conditions.ConnectionManager; + +class ChannelLoader { + + private String channelTable = "svt_channels"; + ChannelMap channelMap = new ChannelMap(); + + ChannelLoader() { + } + + ChannelLoader(String channelTable) { + this.channelTable = channelTable; + } + + void loadChannels() { + Connection connection = ConnectionManager.createConnection(); + + Statement statement = null; + + try { + + statement = connection.createStatement(); + + String db = ConnectionManager.getConnectionParameters().getDatabase(); + + final String query = "SELECT id, fpga, hybrid, channel FROM " + + db + "." + channelTable; + + statement.executeQuery(query); + + ResultSet resultSet = statement.getResultSet(); + + while (resultSet.next()) { + int id = resultSet.getInt(1); + int fpga = resultSet.getInt(2); + int hybrid = resultSet.getInt(3); + int channel = resultSet.getInt(4); + ChannelData channelData = new ChannelData(fpga, hybrid, channel); + channelMap.addChannel(id, channelData); + } + } catch(SQLException x) { + throw new RuntimeException("Error querying database.", x); + } finally { + if (statement != null) { + try { + statement.close(); + } catch (SQLException x) { + throw new RuntimeException("Failed to close statement.", x); + } + } + try { + connection.close(); + } catch (SQLException x) { + throw new RuntimeException("Failed to close database.", x); + } + } + } + + ChannelMap getChannelMap() { + return channelMap; + } +}
\ No newline at end of file
diff -N ChannelMap.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ChannelMap.java 19 Sep 2013 01:27:15 -0000 1.1 @@ -0,0 +1,30 @@
+package org.lcsim.hps.conditions.svt; + +import java.util.HashMap; +import java.util.Map; + +public class ChannelMap { + + Map<Integer,ChannelData> channels = new HashMap<Integer,ChannelData>(); + + void addChannel(int id, ChannelData data) { + if (channels.get(id) != null) { + throw new IllegalArgumentException("ChannelData already exists with ID: " + id); + } + channels.put(id, data); + } + + ChannelData getChannelData(int id) { + return channels.get(id); + } + + ChannelData findChannelData(int fpga, int hybrid, int channel) { + ChannelData channelFind = new ChannelData(fpga, hybrid, channel); + for (ChannelData data : channels.values()) { + if (data.equals(channelFind)) { + return data; + } + } + return null; + } +}
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1