OpenWalnut  1.4.0
WEEG2.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 
27 #include <sstream>
28 #include <string>
29 #include <vector>
30 
31 #include <boost/shared_ptr.hpp>
32 
33 #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 #include "WEEG2.h"
40 
41 
42 boost::shared_ptr< WPrototyped > WEEG2::m_prototype = boost::shared_ptr< WPrototyped >();
43 
44 WEEG2::WEEG2( boost::shared_ptr< WPagerEEG > pager, boost::shared_ptr< WEEGPositionsLibrary > positionsLibrary )
45 {
46  if( !pager )
47  {
48  throw WDHException( std::string( "Couldn't construct new EEG: pager invalid" ) );
49  }
50 
51  if( !positionsLibrary )
52  {
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();
70  {
71  throw WDHException( std::string( "Couldn't construct new EEG: invalid sampling rate" ) );
72  }
73 
74  setFilename( pager->getFilename() );
75 
76  m_segments.reserve( nbSegments );
77  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  m_channelInfos.reserve( nbChannels );
83  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 
90 {
91 }
92 
93 std::size_t WEEG2::getNumberOfSegments() const
94 {
95  return m_segments.size();
96 }
97 
98 std::size_t WEEG2::getNumberOfChannels() const
99 {
100  return m_channelInfos.size();
101 }
102 
104 {
105  return m_samplingRate;
106 }
107 
108 boost::shared_ptr< WEEG2Segment > WEEG2::getSegment( std::size_t segmentID ) const
109 {
110  if( segmentID >= m_segments.size() )
111  {
112  std::ostringstream stream;
113  stream << "The EEG has no segment number " << segmentID;
114  throw WOutOfBounds( stream.str() );
115  }
116 
117  return m_segments[segmentID];
118 }
119 
120 boost::shared_ptr< WEEGChannelInfo > WEEG2::getChannelInfo( std::size_t channelID ) const
121 {
122  if( channelID >= m_channelInfos.size() )
123  {
124  std::ostringstream stream;
125  stream << "The EEG has no channel number " << channelID;
126  throw WOutOfBounds( stream.str() );
127  }
128 
129  return m_channelInfos[channelID];
130 }
131 
132 const std::string WEEG2::getName() const
133 {
134  return "WEEG2";
135 }
136 
137 const std::string WEEG2::getDescription() const
138 {
139  return "Contains EEG data";
140 }
141 
142 boost::shared_ptr< WPrototyped > WEEG2::getPrototype()
143 {
144  if( !m_prototype )
145  {
146  m_prototype = boost::shared_ptr< WPrototyped >( new WEEG2() );
147  }
148 
149  return m_prototype;
150 }