ModuleElement.h

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:
00018 
00021     static ModuleElement Module() throw();  
00022     
00027     static ModuleElement Link(unsigned int link);
00028     
00033     static ModuleElement Chip(unsigned int chip);
00034     
00039     static ModuleElement Channel(unsigned int channel); 
00041     
00042     
00048     ModuleElement(const unsigned first, const unsigned last);
00050     ~ModuleElement() throw() {;}
00052     unsigned getFirst() const throw() {return first;}
00054     unsigned getLast() const throw() {return last;}
00056     unsigned getNChannels() const throw();
00058     bool isChannel() const throw();
00060     bool isChip() const throw();
00062     bool isLink() const throw();
00064     bool isModule() const throw();
00066     bool operator == (const ModuleElement&) const throw();
00068     bool isWithin(const ModuleElement&) const throw();
00070     bool contains(const ModuleElement&) const throw();
00072     bool overlaps(const ModuleElement&) const throw();
00076     bool adjacentTo(const ModuleElement&) const throw();
00077     private:
00078     unsigned first, last;
00079     ModuleElement() throw(); 
00080     };
00081 
00082 //==========================================================================
00083 // inlines
00084 //==========================================================================
00085     inline ModuleElement::ModuleElement(const unsigned lo, const unsigned hi) {
00086 #ifndef NDEBUG
00087     if (hi>nChannelModule ) {
00088         throw OutOfRangeError<unsigned>("ModuleElement last", __FILE__, __LINE__, hi, 0, nChannelModule);
00089     }
00090     if (lo>hi ){
00091         throw OutOfRangeError<unsigned>("ModuleElement first ", __FILE__, __LINE__, lo, 0, hi);
00092     }
00093 #endif
00094     last=hi;
00095     first=lo;
00096 
00097     }
00098     inline unsigned int ModuleElement::getNChannels() const throw() {
00099     return getLast() - getFirst() + 1;
00100     }
00101     inline bool ModuleElement::isChannel() const throw(){
00102     return (getNChannels() == 1);
00103     }
00104     inline bool ModuleElement::isChip() const throw(){
00105     return (getFirst() % nChannelChip == 0 && getNChannels() == nChannelChip);
00106     }
00107     inline bool ModuleElement::isLink() const throw(){
00108     return (getFirst() % nChannelLink == 0 && getNChannels() == nChannelLink);
00109     }
00110      inline bool ModuleElement::isModule() const throw(){
00111     return (getFirst() % nChannelModule == 0 && getNChannels() == nChannelModule);
00112     }
00113 
00114     inline bool ModuleElement::operator == (const ModuleElement& el) const throw(){
00115     return (getFirst()==el.getFirst() && getLast()==el.getLast() );
00116     }
00117 
00118     inline bool ModuleElement::isWithin(const ModuleElement& el) const throw(){
00119     return (getFirst()>=el.getFirst() && getLast()<=el.getLast() );
00120     }
00121     inline bool ModuleElement::contains(const ModuleElement& el) const throw(){
00122     return (getFirst()<=el.getFirst() && getLast()>=el.getLast() );
00123     }
00124     
00125     inline bool ModuleElement::overlaps(const ModuleElement& el) const throw(){
00126     return ( (getFirst()<=el.getFirst() && getLast()>=el.getFirst() )  // my first element contained
00127          || ( getFirst()>el.getFirst() && getFirst()<=el.getLast() ) ); // my last element contained
00128     }
00129     
00130     inline bool ModuleElement::adjacentTo(const ModuleElement& el) const throw(){
00131       if ( overlaps(el) ) return false;
00132       return ( getFirst()==el.getLast()+1 || getLast()==el.getFirst()-1 );
00133     }
00134 
00135     inline ModuleElement ModuleElement::Chip(const unsigned ichip) { 
00136     return ModuleElement(ichip*nChannelChip, (ichip+1)*nChannelChip-1);
00137     }
00138     
00139     inline ModuleElement ModuleElement::Link(const unsigned ilink) { 
00140     return ModuleElement(ilink*nChannelLink, (ilink+1)*nChannelLink-1);
00141     }
00142     
00143     inline ModuleElement ModuleElement::Channel(const unsigned ichannel) { 
00144     return ModuleElement(ichannel, ichannel);
00145     }
00146     
00147     inline ModuleElement ModuleElement::Module() throw() { 
00148     return ModuleElement(0, nChannelModule-1);
00149     }
00150 
00151 } // end of namespace SctData
00152 #endif //#ifndef MODULEELEMENT_H

Generated on Mon Feb 6 14:01:23 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6