WEEG2.cpp 4.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#include <cstddef>

#include <sstream>
28
#include <string>
29 30 31 32 33
#include <vector>

#include <boost/shared_ptr.hpp>

#include "../common/exceptions/WOutOfBounds.h"
34
#include "exceptions/WDHException.h"
35
#include "io/WPagerEEG.h"
36
#include "WEEGChannelInfo.h"
37
#include "WEEGPositionsLibrary.h"
38
#include "WEEG2Segment.h"
39 40 41
#include "WEEG2.h"


42 43
boost::shared_ptr< WPrototyped > WEEG2::m_prototype = boost::shared_ptr< WPrototyped >();

44
WEEG2::WEEG2( boost::shared_ptr< WPagerEEG > pager, boost::shared_ptr< WEEGPositionsLibrary > positionsLibrary )
45
{
46 47
    if( !pager )
    {
48
        throw WDHException( std::string( "Couldn't construct new EEG: pager invalid" ) );
49 50
    }

51 52
    if( !positionsLibrary )
    {
53
        throw WDHException( std::string( "Couldn't construct new EEG: positions library invalid" ) );
54 55
    }

56
    std::size_t nbSegments = pager->getNumberOfSegments();
57
    if( nbSegments <= 0 || WRecording::MAX_RECORDING_SEGMENTS < nbSegments )
58
    {
59
        throw WDHException( std::string( "Couldn't construct new EEG: invalid number of segments" ) );
60 61 62
    }

    std::size_t nbChannels = pager->getNumberOfChannels();
63
    if( nbChannels <= 0 || WRecording::MAX_RECORDING_CHANNELS < nbChannels )
64
    {
65
        throw WDHException( std::string( "Couldn't construct new EEG: invalid number of channels" ) );
66 67
    }

68
    m_samplingRate = pager->getSamplingRate();
69
    if( m_samplingRate <= 0.0 || WRecording::MAX_RECORDING_SAMPLING_FREQUENCY < m_samplingRate )
70
    {
71
        throw WDHException( std::string( "Couldn't construct new EEG: invalid sampling rate" ) );
72 73 74 75
    }

    setFileName( pager->getFileName() );

76 77
    m_segments.reserve( nbSegments );
    for( std::size_t segmentID = 0; segmentID < nbSegments; ++segmentID )
78
    {
79
        m_segments.push_back( boost::shared_ptr< WEEG2Segment >( new WEEG2Segment( segmentID, pager ) ) );
80
    }
81

82 83
    m_channelInfos.reserve( nbChannels );
    for( std::size_t channelID = 0; channelID < nbChannels; ++channelID )
84
    {
85
        m_channelInfos.push_back( boost::shared_ptr< WEEGChannelInfo >( new WEEGChannelInfo( channelID, pager, positionsLibrary ) ) );
86
    }
87 88
}

89 90 91 92
WEEG2::WEEG2()
{
}

93 94 95 96 97
std::size_t WEEG2::getNumberOfSegments() const
{
    return m_segments.size();
}

98 99 100 101 102
std::size_t WEEG2::getNumberOfChannels() const
{
    return m_channelInfos.size();
}

103 104 105 106 107
double WEEG2::getSamplingRate() const
{
    return m_samplingRate;
}

108 109 110 111 112 113 114 115 116 117 118
boost::shared_ptr< WEEG2Segment > WEEG2::getSegment( std::size_t segmentID ) const
{
    if( segmentID >= m_segments.size() )
    {
        std::ostringstream stream;
        stream << "The EEG has no segment number " << segmentID;
        throw WOutOfBounds( stream.str() );
    }

    return m_segments[segmentID];
}
119 120 121 122 123 124 125 126 127 128 129 130

boost::shared_ptr< WEEGChannelInfo > WEEG2::getChannelInfo( std::size_t channelID ) const
{
    if( channelID >= m_channelInfos.size() )
    {
        std::ostringstream stream;
        stream << "The EEG has no channel number " << channelID;
        throw WOutOfBounds( stream.str() );
    }

    return m_channelInfos[channelID];
}
131 132 133 134 135 136 137 138 139 140 141 142 143

const std::string WEEG2::getName() const
{
    return "WEEG2";
}

const std::string WEEG2::getDescription() const
{
    return "Contains EEG data";
}

boost::shared_ptr< WPrototyped > WEEG2::getPrototype()
{
144
    if( !m_prototype )
145 146 147 148 149 150
    {
        m_prototype = boost::shared_ptr< WPrototyped >( new WEEG2() );
    }

    return m_prototype;
}