00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <cstddef>
00026
00027 #include <sstream>
00028 #include <string>
00029 #include <vector>
00030
00031 #include <boost/shared_ptr.hpp>
00032
00033 #include "../common/exceptions/WOutOfBounds.h"
00034 #include "exceptions/WDHException.h"
00035 #include "io/WPagerEEG.h"
00036 #include "WEEGChannelInfo.h"
00037 #include "WEEGPositionsLibrary.h"
00038 #include "WEEG2Segment.h"
00039 #include "WEEG2.h"
00040
00041
00042 boost::shared_ptr< WPrototyped > WEEG2::m_prototype = boost::shared_ptr< WPrototyped >();
00043
00044 WEEG2::WEEG2( boost::shared_ptr< WPagerEEG > pager, boost::shared_ptr< WEEGPositionsLibrary > positionsLibrary )
00045 {
00046 if( !pager )
00047 {
00048 throw WDHException( std::string( "Couldn't construct new EEG: pager invalid" ) );
00049 }
00050
00051 if( !positionsLibrary )
00052 {
00053 throw WDHException( std::string( "Couldn't construct new EEG: positions library invalid" ) );
00054 }
00055
00056 std::size_t nbSegments = pager->getNumberOfSegments();
00057 if( nbSegments <= 0 || WRecording::MAX_RECORDING_SEGMENTS < nbSegments )
00058 {
00059 throw WDHException( std::string( "Couldn't construct new EEG: invalid number of segments" ) );
00060 }
00061
00062 std::size_t nbChannels = pager->getNumberOfChannels();
00063 if( nbChannels <= 0 || WRecording::MAX_RECORDING_CHANNELS < nbChannels )
00064 {
00065 throw WDHException( std::string( "Couldn't construct new EEG: invalid number of channels" ) );
00066 }
00067
00068 m_samplingRate = pager->getSamplingRate();
00069 if( m_samplingRate <= 0.0 || WRecording::MAX_RECORDING_SAMPLING_FREQUENCY < m_samplingRate )
00070 {
00071 throw WDHException( std::string( "Couldn't construct new EEG: invalid sampling rate" ) );
00072 }
00073
00074 setFileName( pager->getFileName() );
00075
00076 m_segments.reserve( nbSegments );
00077 for( std::size_t segmentID = 0; segmentID < nbSegments; ++segmentID )
00078 {
00079 m_segments.push_back( boost::shared_ptr< WEEG2Segment >( new WEEG2Segment( segmentID, pager ) ) );
00080 }
00081
00082 m_channelInfos.reserve( nbChannels );
00083 for( std::size_t channelID = 0; channelID < nbChannels; ++channelID )
00084 {
00085 m_channelInfos.push_back( boost::shared_ptr< WEEGChannelInfo >( new WEEGChannelInfo( channelID, pager, positionsLibrary ) ) );
00086 }
00087 }
00088
00089 WEEG2::WEEG2()
00090 {
00091 }
00092
00093 std::size_t WEEG2::getNumberOfSegments() const
00094 {
00095 return m_segments.size();
00096 }
00097
00098 std::size_t WEEG2::getNumberOfChannels() const
00099 {
00100 return m_channelInfos.size();
00101 }
00102
00103 double WEEG2::getSamplingRate() const
00104 {
00105 return m_samplingRate;
00106 }
00107
00108 boost::shared_ptr< WEEG2Segment > WEEG2::getSegment( std::size_t segmentID ) const
00109 {
00110 if( segmentID >= m_segments.size() )
00111 {
00112 std::ostringstream stream;
00113 stream << "The EEG has no segment number " << segmentID;
00114 throw WOutOfBounds( stream.str() );
00115 }
00116
00117 return m_segments[segmentID];
00118 }
00119
00120 boost::shared_ptr< WEEGChannelInfo > WEEG2::getChannelInfo( std::size_t channelID ) const
00121 {
00122 if( channelID >= m_channelInfos.size() )
00123 {
00124 std::ostringstream stream;
00125 stream << "The EEG has no channel number " << channelID;
00126 throw WOutOfBounds( stream.str() );
00127 }
00128
00129 return m_channelInfos[channelID];
00130 }
00131
00132 const std::string WEEG2::getName() const
00133 {
00134 return "WEEG2";
00135 }
00136
00137 const std::string WEEG2::getDescription() const
00138 {
00139 return "Contains EEG data";
00140 }
00141
00142 boost::shared_ptr< WPrototyped > WEEG2::getPrototype()
00143 {
00144 if( !m_prototype )
00145 {
00146 m_prototype = boost::shared_ptr< WPrototyped >( new WEEG2() );
00147 }
00148
00149 return m_prototype;
00150 }