Author: omoreno Date: Mon Oct 27 11:12:41 2014 New Revision: 1308 Log: Abstract class providing basic setup information for an SVT sensor channel. Added: java/branches/hps_java_trunk_HPSJAVA-255/conditions/src/main/java/org/hps/conditions/svt/AbstractSvtChannel.java (with props) Added: java/branches/hps_java_trunk_HPSJAVA-255/conditions/src/main/java/org/hps/conditions/svt/AbstractSvtChannel.java ============================================================================= --- java/branches/hps_java_trunk_HPSJAVA-255/conditions/src/main/java/org/hps/conditions/svt/AbstractSvtChannel.java (added) +++ java/branches/hps_java_trunk_HPSJAVA-255/conditions/src/main/java/org/hps/conditions/svt/AbstractSvtChannel.java Mon Oct 27 11:12:41 2014 @@ -0,0 +1,103 @@ +package org.hps.conditions.svt; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.hps.conditions.AbstractConditionsObject; +import org.hps.conditions.ConditionsObjectCollection; +import org.hps.conditions.ConditionsObjectException; +import org.hps.util.Pair; + +/** + * This abstract class provides basic setup information for an SVT + * sensor channel. + * + * @author Omar Moreno <[log in to unmask]> + */ +public class AbstractSvtChannel extends AbstractConditionsObject { + + // TODO: Put constants into their own class + public static final int MAX_NUMBER_OF_SAMPLES = 6; + + public static abstract class AbstractSvtChannelCollection<T extends AbstractSvtChannel> + extends ConditionsObjectCollection<T> { + + Map<Integer, T> channelMap = new HashMap<Integer, T>(); + + /** + * Add a channel of type extending {@link AbstractSvtChannel} to the + * channel map + * + * @param A channel of a type extending {@link AbstractSvtChannel} + */ + public void add(T channel){ + + // If it doesn't exist, add the channel to the channel map + if(channelMap.containsKey(channel.getChannelID())){ + throw new IllegalArgumentException("[ " + this.getClass().getSimpleName() + " ]: Channel ID already exists: " + + channel.getChannelID()); + } + channelMap.put(channel.getChannelID(), channel); + + // Add to the collection + try { + super.add(channel); + } catch(ConditionsObjectException e){ + throw new RuntimeException(e); + } + } + + /** + * Find a channel of type extending {@link AbstractSvtChannel} using the + * channel ID + * + * @param channelID + * @return An SVT channel of type extending {@link AbstractSvtChannel} + */ + public T findChannel(int channelID){ + return channelMap.get(channelID); + } + + /** + * Find the collection of channels of type extending + * {@link AbstractSvtChannel} that match a DAQ pair. + * + * @param pair The DAQ pair. + * @return The channels matching the DAQ pair or null if not found. + */ + public abstract Collection<T> find(Pair<Integer, Integer> pair); + + /** + * Convert this object to a human readable string. + * + * @return This object converted to a string. + */ + public String toString() { + StringBuffer buff = new StringBuffer(); + for (T channel : this.getObjects()) { + buff.append(channel.toString() + '\n'); + } + return buff.toString(); + } + } + + /** + * Get the channel ID. + * + * @return The channel ID. + */ + public int getChannelID() { + return getFieldValue("channel_id"); + } + + /** + * Get the channel number. This is different from the ID. + * + * @return The channel number. + */ + public int getChannel() { + return getFieldValue("channel"); + } + +}