Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ModuleElement.java

00001 package SctData;
00002 
00003 import Sct.*;
00004 
00008 public class ModuleElement implements Streamable {
00016     public ModuleElement(int first, int last) throws IllegalArgumentException {
00017         if (last >= Parameters.nChannelModule || last < first) 
00018             throw new IllegalArgumentException("Unable to create ModuleElement with parameters first: " + first + " last: " + last);
00019            
00020         this.first = first;
00021         this.last = last;
00022     }    
00023     
00028     public static ModuleElement chip(int chip) {
00029         return new ModuleElement(chip*Parameters.nChannelChip, (chip+1)*Parameters.nChannelChip - 1);
00030     }
00031     
00036     public static ModuleElement channel(int channel) {
00037         return new ModuleElement(channel, channel);
00038     }
00039     
00044     public static ModuleElement link(int link) {
00045         return new ModuleElement(link*Parameters.nChannelLink, (link+1)*Parameters.nChannelLink - 1);
00046     }
00047     
00051     public static ModuleElement module() {
00052         return new ModuleElement(0, Parameters.nChannelModule-1);
00053     }
00054     
00056     public int getFirst() {
00057         return first;
00058     }
00059 
00061     public int getLast() {
00062         return last;
00063     }
00064 
00066     public int getNChannels() {
00067         return last-first + 1;
00068     }
00069 
00071     public boolean isChannel() {
00072         return getNChannels() == 1;
00073     }
00074 
00076     public boolean isChip() {
00077         return (getFirst() % Parameters.nChannelChip == 0 && getNChannels() == Parameters.nChannelChip);
00078     }
00079 
00081     public boolean isLink() {
00082         return (getFirst() % Parameters.nChannelLink == 0 && getNChannels() == Parameters.nChannelLink);
00083     }
00084 
00086     public boolean isModule() {
00087         return (getFirst() % Parameters.nChannelModule == 0 && getNChannels() == Parameters.nChannelModule);
00088     }
00089     
00091     public boolean equals(Object e2) {
00092         if (e2 instanceof ModuleElement) {
00093             ModuleElement me2 = (ModuleElement)e2;
00094             return (this.getFirst() == me2.getFirst() && this.getLast() == me2.getLast());
00095         }
00096         return false;
00097     }
00098     
00100     public boolean superset(ModuleElement e2) {
00101         return (this.getFirst() <= e2.getFirst() && this.getLast() >= e2.getLast());
00102     }
00103     
00105     public boolean subset(ModuleElement e2) {
00106         return (this.getFirst() >= e2.getFirst() && this.getLast() <= e2.getLast());
00107     }
00108 
00110     public boolean overlaps(ModuleElement e2) {
00111         return (this.getFirst()<=e2.getLast() && this.getFirst()>=e2.getFirst()) 
00112                 || (this.getLast()<=e2.getLast() && this.getLast()>=e2.getFirst());
00113     }
00114 
00115     public String getClassName() {
00116         return "SctData.ModuleElement";
00117     }
00118     
00119     public static ModuleElement read(IStream s, ObjectManager o) throws java.io.IOException {
00120         int first = s.readInt("FirstChannel");
00121         int last  = s.readInt("LastChannel");
00122         return new ModuleElement(first, last);
00123     }
00124     
00125     public void write(OStream s, ObjectManager o) throws java.io.IOException {
00126         s.writeInt("FirstChannel", first, false);
00127         s.writeInt("LastChannel", last, false);
00128     }
00129     
00130     private int first;
00131     private int last;
00132 }

Generated on Thu Jul 15 09:55:45 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5