00001 #ifndef MODULEELEMENT_H
00002 #define MODULEELEMENT_H
00003 #include "Sct/Exception.h"
00004 #include "Sct/SctParameters.h"
00005 #include "Sct/OutOfRangeError.h"
00006
00007 using namespace Sct;
00008
00009 namespace SctData {
00015 class ModuleElement{
00016 public:
00022 ModuleElement(const unsigned first, const unsigned last);
00024 ~ModuleElement() throw() {;}
00026 unsigned getFirst() const throw() {return first;}
00028 unsigned getLast() const throw() {return last;}
00030 unsigned getNChannels() const throw();
00032 bool isChannel() const throw();
00034 bool isChip() const throw();
00036 bool isLink() const throw();
00038 bool isModule() const throw();
00040 bool operator == (const ModuleElement&) const throw();
00042 bool isWithin(const ModuleElement&) const throw();
00044 bool contains(const ModuleElement&) const throw();
00046 bool overlaps(const ModuleElement&) const throw();
00047 private:
00048 unsigned first, last;
00049 ModuleElement() throw();
00050 };
00051
00052
00054
00055 public:
00057 Chip(const unsigned ichip) throw (LogicError);
00058 ~Chip() throw(){;}
00059 };
00060
00061
00063
00064 public:
00066 Link(const unsigned ilink) throw (LogicError);
00067 ~Link() throw(){;}
00068 };
00069
00070
00072
00073 public:
00075 Channel(const unsigned ichannel) throw (LogicError);
00076 ~Channel() throw(){;}
00077 };
00078
00080
00081 public:
00082 Module() throw (LogicError);
00083 ~Module() throw(){;}
00084 };
00085
00086
00087
00088 inline ModuleElement::ModuleElement(const unsigned lo, const unsigned hi) {
00089 #ifndef NDEBUG
00090 if (hi>nChannelModule ) {
00091 throw OutOfRangeError<unsigned>("ModuleElement last", __FILE__, __LINE__, hi, 0, nChannelModule);
00092 }
00093 if (lo>hi ){
00094 throw OutOfRangeError<unsigned>("ModuleElement first ", __FILE__, __LINE__, lo, 0, hi);
00095 }
00096 #endif
00097 last=hi;
00098 first=lo;
00099
00100 }
00101 inline unsigned int ModuleElement::getNChannels() const throw() {
00102 return getLast() - getFirst() + 1;
00103 }
00104 inline bool ModuleElement::isChannel() const throw(){
00105 return (getNChannels() == 1);
00106 }
00107 inline bool ModuleElement::isChip() const throw(){
00108 return (getFirst() % nChannelChip == 0 && getNChannels() == nChannelChip);
00109 }
00110 inline bool ModuleElement::isLink() const throw(){
00111 return (getFirst() % nChannelLink == 0 && getNChannels() == nChannelLink);
00112 }
00113 inline bool ModuleElement::isModule() const throw(){
00114 return (getFirst() % nChannelModule == 0 && getNChannels() == nChannelModule);
00115 }
00116
00117 inline bool ModuleElement::operator == (const ModuleElement& el) const throw(){
00118 return (getFirst()==el.getFirst() && getLast()==el.getLast() );
00119 }
00120
00121 inline bool ModuleElement::isWithin(const ModuleElement& el) const throw(){
00122 return (getFirst()>=el.getFirst() && getLast()<=el.getLast() );
00123 }
00124 inline bool ModuleElement::contains(const ModuleElement& el) const throw(){
00125 return (getFirst()<=el.getFirst() && getLast()>=el.getLast() );
00126 }
00127
00128 inline bool ModuleElement::overlaps(const ModuleElement& el) const throw(){
00129 return ( (getFirst()<=el.getLast() && getFirst()>=el.getFirst() )
00130 || ( getLast()<=el.getLast() && getLast()>=el.getFirst() ) );
00131 }
00132 inline Chip::Chip(const unsigned ichip) throw (LogicError) :
00133 ModuleElement(ichip*nChannelChip, (ichip+1)*nChannelChip-1) {
00134 }
00135
00136 inline Link::Link(const unsigned ilink) throw (LogicError) :
00137 ModuleElement(ilink*nChannelLink, (ilink+1)*nChannelLink-1) {
00138 }
00139 inline Channel::Channel(const unsigned ichannel) throw (LogicError) :
00140 ModuleElement(ichannel, ichannel){
00141 }
00142
00143 inline Module::Module() throw (LogicError) :
00144 ModuleElement(0, nChannelModule-1) {
00145 }
00146
00147 }
00148 #endif //#ifndef MODULEELEMENT_H