33 #include "WReaderELC.h"
34 #include "core/common/WLogger.h"
35 #include "core/common/WStringUtils.h"
36 #include "core/common/math/linearAlgebra/WPosition.h"
37 #include "core/dataHandler/WEEGPositionsLibrary.h"
38 #include "core/dataHandler/exceptions/WDHIOFailure.h"
39 #include "core/dataHandler/exceptions/WDHNoSuchFile.h"
40 #include "core/dataHandler/exceptions/WDHParseError.h"
50 ifs.open(
m_fname.c_str(), std::ifstream::in );
51 if( !ifs || ifs.bad() )
53 throw WDHNoSuchFile( std::string(
"Problem loading file " +
m_fname +
". Probably file not found." ) );
57 while( ifs.good() && line.substr( 0, 16 ) !=
"NumberPositions=" )
59 std::getline( ifs, line );
67 std::size_t numPositions = string_utils::fromString< std::size_t >( tokens.at( 1 ) );
69 while( ifs.good() && line.substr( 0, 9 ) !=
"Positions" )
71 std::getline( ifs, line );
78 std::size_t posCounter = 0;
79 std::vector< WPosition > positions;
80 positions.reserve( numPositions );
81 while( posCounter != numPositions && ifs.good() && line.substr( 0, 6 ) !=
"Labels" )
83 std::getline( ifs, line );
94 double posX = string_utils::fromString< double >( posTokens.at( posTokens.size() - 3 ) );
95 double posY = string_utils::fromString< double >( posTokens.at( posTokens.size() - 2 ) );
96 double posZ = string_utils::fromString< double >( posTokens.at( posTokens.size() - 1 ) );
97 positions.push_back(
WPosition( posX, posY, posZ ) );
101 if( positions.size() != numPositions )
103 throw WDHParseError( std::string(
"Could not find correct number of Positions regarding to NumberPositions statement in file " +
m_fname ) );
106 while( ifs.good() && line.substr( 0, 6 ) !=
"Labels" )
108 std::getline( ifs, line );
115 std::size_t labelCounter = 0;
116 std::map< std::string, WPosition > positionsMap;
117 while( labelCounter != numPositions && ifs.good() )
119 std::getline( ifs, line );
127 for( std::size_t i = 0; i < labelTokens.size(); ++i )
129 positionsMap[labelTokens[i]] = positions[labelCounter];
135 if( positionsMap.size() != numPositions )
137 throw WDHParseError( std::string(
"Could not find correct number of Labels regarding to NumberPositions statement in file " +
m_fname ) );
142 for( std::map< std::string, WPosition >::const_iterator iter = positionsMap.begin(); iter != positionsMap.end(); ++iter )
144 wlog::debug(
"WReaderELC" ) << iter->first <<
": " << iter->second;
Use this for IO error handling.
File not found exception.
Use this for IO error handling.
Class which contains the positions of EEG electrodes by label.
This only is a 3d double vector.
WReaderELC(std::string fname)
Constructs a reader object.
std::shared_ptr< WEEGPositionsLibrary > read()
Read the file and create a dataset out of it.
Read some data from a given file.
std::string m_fname
Absolute path of the file to read from.
std::vector< std::string > tokenize(const std::string &source, const std::string &delim=WHITESPACE, bool compress=true)
Splits the given string into a vector of strings (so called tokens).
WStreamedLogger debug(const std::string &source)
Logging a debug message.