OpenWalnut  1.5.0dev
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 #include <memory>
27 #include <sstream>
28 #include <string>
29 #include <vector>
30 
31 
32 #include "../common/exceptions/WOutOfBounds.h"
33 #include "WEEG2.h"
34 #include "WEEG2Segment.h"
35 #include "WEEGChannelInfo.h"
36 #include "WEEGPositionsLibrary.h"
37 #include "exceptions/WDHException.h"
38 #include "io/WPagerEEG.h"
39 
40 
41 std::shared_ptr< WPrototyped > WEEG2::m_prototype = std::shared_ptr< WPrototyped >();
42 
43 WEEG2::WEEG2( std::shared_ptr< WPagerEEG > pager, std::shared_ptr< WEEGPositionsLibrary > positionsLibrary )
44 {
45  if( !pager )
46  {
47  throw WDHException( std::string( "Couldn't construct new EEG: pager invalid" ) );
48  }
49 
50  if( !positionsLibrary )
51  {
52  throw WDHException( std::string( "Couldn't construct new EEG: positions library invalid" ) );
53  }
54 
55  std::size_t nbSegments = pager->getNumberOfSegments();
56  if( nbSegments <= 0 || WRecording::MAX_RECORDING_SEGMENTS < nbSegments )
57  {
58  throw WDHException( std::string( "Couldn't construct new EEG: invalid number of segments" ) );
59  }
60 
61  std::size_t nbChannels = pager->getNumberOfChannels();
62  if( nbChannels <= 0 || WRecording::MAX_RECORDING_CHANNELS < nbChannels )
63  {
64  throw WDHException( std::string( "Couldn't construct new EEG: invalid number of channels" ) );
65  }
66 
67  m_samplingRate = pager->getSamplingRate();
69  {
70  throw WDHException( std::string( "Couldn't construct new EEG: invalid sampling rate" ) );
71  }
72 
73  setFilename( pager->getFilename() );
74 
75  m_segments.reserve( nbSegments );
76  for( std::size_t segmentID = 0; segmentID < nbSegments; ++segmentID )
77  {
78  m_segments.push_back( std::shared_ptr< WEEG2Segment >( new WEEG2Segment( segmentID, pager ) ) );
79  }
80 
81  m_channelInfos.reserve( nbChannels );
82  for( std::size_t channelID = 0; channelID < nbChannels; ++channelID )
83  {
84  m_channelInfos.push_back( std::shared_ptr< WEEGChannelInfo >( new WEEGChannelInfo( channelID, pager, positionsLibrary ) ) );
85  }
86 
87  m_infoProperties->addProperty( "Segments", "The number of segments", static_cast< WPVBaseTypes::PV_INT >( nbSegments ) );
88  m_infoProperties->addProperty( "Channels", "The number of channels", static_cast< WPVBaseTypes::PV_INT >( nbChannels ) );
89  m_infoProperties->addProperty( "Sampling rate", "Sampling rate of the recording", static_cast< WPVBaseTypes::PV_DOUBLE >( m_samplingRate ) );
90 }
91 
93 {
94 }
95 
96 std::size_t WEEG2::getNumberOfSegments() const
97 {
98  return m_segments.size();
99 }
100 
101 std::size_t WEEG2::getNumberOfChannels() const
102 {
103  return m_channelInfos.size();
104 }
105 
107 {
108  return m_samplingRate;
109 }
110 
111 std::shared_ptr< WEEG2Segment > WEEG2::getSegment( std::size_t segmentID ) const
112 {
113  if( segmentID >= m_segments.size() )
114  {
115  std::ostringstream stream;
116  stream << "The EEG has no segment number " << segmentID;
117  throw WOutOfBounds( stream.str() );
118  }
119 
120  return m_segments[segmentID];
121 }
122 
123 std::shared_ptr< WEEGChannelInfo > WEEG2::getChannelInfo( std::size_t channelID ) const
124 {
125  if( channelID >= m_channelInfos.size() )
126  {
127  std::ostringstream stream;
128  stream << "The EEG has no channel number " << channelID;
129  throw WOutOfBounds( stream.str() );
130  }
131 
132  return m_channelInfos[channelID];
133 }
134 
135 const std::string WEEG2::getName() const
136 {
137  return "WEEG2";
138 }
139 
140 const std::string WEEG2::getDescription() const
141 {
142  return "Contains EEG data";
143 }
144 
145 std::shared_ptr< WPrototyped > WEEG2::getPrototype()
146 {
147  if( !m_prototype )
148  {
149  m_prototype = std::shared_ptr< WPrototyped >( new WEEG2() );
150  }
151 
152  return m_prototype;
153 }
General purpose exception and therefore base class for all DataHandler related exceptions.
Definition: WDHException.h:40
void setFilename(const std::string filename)
Set the name of the file that this data set stems from.
Definition: WDataSet.cpp:58
std::shared_ptr< WProperties > m_infoProperties
The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION".
Definition: WDataSet.h:181
Class which contains one segment of an EEG recording, read from a WPagerEEG.
Definition: WEEG2Segment.h:42
static std::shared_ptr< WPrototyped > m_prototype
Prototype needed to allow the EEG dataset to be transferred.
Definition: WEEG2.h:127
std::size_t getNumberOfChannels() const
Get the number of channels this EEG has.
Definition: WEEG2.cpp:101
std::size_t getNumberOfSegments() const
Get the number of segments this EEG consists of.
Definition: WEEG2.cpp:96
double getSamplingRate() const
Get the sampling rate used by the recording.
Definition: WEEG2.cpp:106
static std::shared_ptr< WPrototyped > getPrototype()
Get dataset prototype.
Definition: WEEG2.cpp:145
std::vector< std::shared_ptr< WEEGChannelInfo > > m_channelInfos
list of the information about all channel infos this EEG has
Definition: WEEG2.h:134
WEEG2()
Constructor creating a quite unusable instance.
Definition: WEEG2.cpp:92
std::vector< std::shared_ptr< WEEG2Segment > > m_segments
list of all segments this EEG consists of
Definition: WEEG2.h:132
std::shared_ptr< WEEG2Segment > getSegment(std::size_t segmentID) const
Get one segment.
Definition: WEEG2.cpp:111
std::shared_ptr< WEEGChannelInfo > getChannelInfo(std::size_t channelID) const
Get one channel info object.
Definition: WEEG2.cpp:123
virtual const std::string getName() const
Return the name of the dataset.
Definition: WEEG2.cpp:135
virtual const std::string getDescription() const
Description of dataset.
Definition: WEEG2.cpp:140
double m_samplingRate
sampling rate used by the recording
Definition: WEEG2.h:130
Class which contains information about one channel of an EEG recording, read from a WPagerEEG.
Indicates invalid element access of a container.
Definition: WOutOfBounds.h:37
static const unsigned int MAX_RECORDING_SAMPLING_FREQUENCY
Maximum samplimg frequency of a recording.
Definition: WRecording.h:88
static const unsigned int MAX_RECORDING_CHANNELS
Maximum number of channels for a certain modality.
Definition: WRecording.h:72
static const unsigned int MAX_RECORDING_SEGMENTS
Maximum number of segments of a recording.
Definition: WRecording.h:83
double PV_DOUBLE
base type used for every WPVDouble
int32_t PV_INT
base type used for every WPVInt