OpenWalnut  1.5.0dev
WEEG2Segment.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <cstddef>
26 #include <memory>
27 #include <sstream>
28 #include <string>
29 
30 
31 #include "../common/exceptions/WOutOfBounds.h"
32 #include "WEEG2Segment.h"
33 #include "WEEGValueMatrix.h"
34 #include "WRecording.h"
35 #include "exceptions/WDHException.h"
36 #include "io/WPagerEEG.h"
37 
38 WEEG2Segment::WEEG2Segment( std::size_t segmentID, std::shared_ptr< WPagerEEG > pager )
39  : m_segmentID( segmentID ),
40  m_pager( pager )
41 {
42  if( !m_pager )
43  {
44  throw WDHException( std::string( "Couldn't construct new EEG segment: pager invalid" ) );
45  }
46 
47  if( m_segmentID >= m_pager->getNumberOfSegments() )
48  {
49  std::ostringstream stream;
50  stream << "The EEG has no segment number " << m_segmentID;
51  throw WOutOfBounds( stream.str() );
52  }
53 
54  m_nbSamples = m_pager->getNumberOfSamples( m_segmentID );
56  {
57  throw WDHException( std::string( "Couldn't construct new EEG segment: invalid number of samples" ) );
58  }
59 }
60 
62 {
63  return m_nbSamples;
64 }
65 
66 std::shared_ptr< WEEGValueMatrix > WEEG2Segment::getValues( std::size_t start, std::size_t length ) const
67 {
68  // No test whether start and length are valid - this should be done only
69  // one time by the pager.
70  return m_pager->getValues( m_segmentID, start, length );
71 }
General purpose exception and therefore base class for all DataHandler related exceptions.
Definition: WDHException.h:40
WEEG2Segment(std::size_t segmentID, std::shared_ptr< WPagerEEG > pager)
Constructor.
std::size_t m_nbSamples
number of samples this segment consists of
Definition: WEEG2Segment.h:73
std::size_t getNumberOfSamples() const
Get the number of samples this segment consists of.
std::shared_ptr< WPagerEEG > m_pager
pager class which contains the data, read from a file on demand
Definition: WEEG2Segment.h:72
std::size_t m_segmentID
number of this segment
Definition: WEEG2Segment.h:71
std::shared_ptr< WEEGValueMatrix > getValues(std::size_t start, std::size_t length) const
Get the values of all channels for a given sample range.
Indicates invalid element access of a container.
Definition: WOutOfBounds.h:37
static const unsigned int MAX_RECORDING_SAMPLES
Maximum number of samples of a recording.
Definition: WRecording.h:78