Commit 76b5c790 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[CHANGE #213] Discarded WDataHandler class

 * deleted the class
 * deleted the corresponding tests
 * adapted all code that was using WDataHandler
parent c73c25bc
//---------------------------------------------------------------------------
//
// 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 <iostream>
#include <string>
#include <vector>
#include "WDataHandler.h"
#include "WSubject.h"
#include "exceptions/WDHNoSuchDataSet.h"
WDataHandler::WDataHandler()
{
}
boost::shared_ptr< WSubject > WDataHandler::getSubject( const unsigned int subjectId ) const
{
if( subjectId >= m_subjects.size() )
throw WDHNoSuchDataSet( "Index too large." );
return m_subjects.at( subjectId );
}
boost::shared_ptr< WSubject > WDataHandler::operator[]( size_t subjectId ) const
{
return getSubject( subjectId );
}
void WDataHandler::addSubject( boost::shared_ptr< WSubject > newSubject )
{
m_subjects.push_back( newSubject );
}
unsigned int WDataHandler::getNumberOfSubjects() const
{
return m_subjects.size();
}
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#ifndef WDATAHANDLER_H
#define WDATAHANDLER_H
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../gui/qt4/signalslib.h"
#include <boost/enable_shared_from_this.hpp>
#include "WDataSet.h"
class WSubject;
/**
* Provides the environment for storing and accessing different subjects.
* As all measured data belongs to one subject, this is the main access point
* to our data.
* \ingroup dataHandler
*/
class WDataHandler : public boost::enable_shared_from_this< WDataHandler >
{
/**
* Only UnitTests may be friends.
*/
friend class WDataHandlerTest;
public:
/**
* Empty standard constructor.
*/
WDataHandler();
/**
* Get the pointer to the i'th WSubject. The return type is const since we
* want to ensure that each subject cannot modified after retrival.
* \param subjectId the number of the subject to be retrieved.
*/
boost::shared_ptr< WSubject > getSubject( const unsigned int subjectId ) const;
/**
* Returns a to the i'th WSubject. The return type is const since we
* want to ensure that each subject cannot modified after retrival.
* \param subjectId the number of the subject to be retrieved.
*/
boost::shared_ptr< WSubject > operator[]( size_t subjectId ) const;
/**
* Insert a new WSubject referenced by a pointer.
* \param newSubject a pointer to the subject that will be added
*/
void addSubject( boost::shared_ptr< WSubject > newSubject );
/**
* Get the number of subjects which are actually handled by our WDataHandler.
*/
unsigned int getNumberOfSubjects() const;
protected:
private:
/**
* A container for all WSubjects.
*/
std::vector< boost::shared_ptr< WSubject > > m_subjects;
};
/**
* \defgroup dataHandler Data Handler
*
* \brief
* This module implements the data storage facility of OpenWalnut.
*/
#endif // WDATAHANDLER_H
......@@ -29,29 +29,11 @@
#include "exceptions/WDHIOFailure.h"
WLoader::WLoader( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler ) throw( WDHIOFailure )
: m_fileName( fileName ),
m_dataHandler( dataHandler )
WLoader::WLoader( std::string fileName ) throw( WDHIOFailure )
: m_fileName( fileName )
{
if( !wiotools::fileExists( m_fileName ) )
{
throw WDHIOFailure( "file '" + m_fileName + "' doesn't exists." );
}
}
void WLoader::commitDataSet( boost::shared_ptr< WDataSet > data )
{
// TODO(wiebel): this is a dummy implementation. We need to fix
// this as soon as we can distinguish which data belongs to which subject.
boost::shared_ptr< WSubject > subject;
if( m_dataHandler->getNumberOfSubjects() == 0 )
{
subject = boost::shared_ptr< WSubject >( new WSubject );
m_dataHandler->addSubject( subject );
}
else
{
subject = m_dataHandler->getSubject( 0 );
}
subject->addDataSet( data );
}
......@@ -30,7 +30,6 @@
#include <boost/shared_ptr.hpp>
#include "exceptions/WDHIOFailure.h"
#include "WDataHandler.h"
#include "WSubject.h"
/**
......@@ -43,14 +42,12 @@ class WLoader
{
public:
/**
* Constructs basic Loader with access to the DataHandler (for inserting
* new stuff) and a file name.
* Constructs basic Loader with a file name.
*
*\param fileName Path to be loaded
*\param dataHanlder A pointer where the loaded data set are stored
*\throw WDHIOFailure in case of an error
*/
explicit WLoader( std::string fileName, boost::shared_ptr< WDataHandler > dataHanlder ) throw( WDHIOFailure );
explicit WLoader( std::string fileName ) throw( WDHIOFailure );
/**
* Destructor is virtual since there are virtual methods.
......@@ -69,13 +66,6 @@ public:
protected:
std::string m_fileName; //!< Name of file to load.
boost::shared_ptr< WDataHandler > m_dataHandler; //!< Reference to DataHandler
/**
* Commit new data into the DataHandler.
* \param data This dataset will be added to the WDataHandler
*/
void commitDataSet( boost::shared_ptr< WDataSet > data );
private:
};
......
......@@ -31,13 +31,12 @@
#include "WLoaderBiosig.h"
#include "../WDataHandler.h"
#include "../WEEG.h"
#include "../WSubject.h"
#include "../../common/WException.h"
WLoaderBiosig::WLoaderBiosig( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler )
: WLoader( fileName, dataHandler ),
WLoaderBiosig::WLoaderBiosig( std::string fileName )
: WLoader( fileName ),
m_columns( 0 ),
m_rows( 0 )
{
......@@ -127,7 +126,6 @@ boost::shared_ptr< WDataSet> WLoaderBiosig::load()
boost::shared_ptr< WEEG > eeg = boost::shared_ptr< WEEG >( new WEEG( segments, lib, labels ) );
eeg->setFileName( m_fileName );
commitDataSet( eeg );
std::cout << "BIOSIG loading done." << std::endl;
std::cout << "===================================" << std::endl;
......
......@@ -32,8 +32,6 @@
#include "../WLoader.h"
#include "biosig/biosig.h"
class WDataHandler;
/**
* Loader for several formats for biological signal.
* Uses BiosigC++ 4.
......@@ -46,9 +44,8 @@ public:
* Constructs a loader to be executed in its own thread and sets the data needed
* for the loader when executed in its own thread.
* \param fileName this file will be loaded
* \param dataHandler a pointer to the dataHandler to be able to add the loaded data
*/
WLoaderBiosig( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler );
explicit WLoaderBiosig( std::string fileName );
/**
* Loads the dataset.
......
......@@ -35,8 +35,8 @@
#include "../WSubject.h"
#include "WLoaderEEGASCII.h"
WLoaderEEGASCII::WLoaderEEGASCII( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler )
: WLoader( fileName, dataHandler )
WLoaderEEGASCII::WLoaderEEGASCII( std::string fileName )
: WLoader( fileName )
{
}
......@@ -84,7 +84,6 @@ boost::shared_ptr< WDataSet > WLoaderEEGASCII::load()
boost::shared_ptr< WEEG > eeg = boost::shared_ptr< WEEG >( new WEEG( segments, lib, labels ) );
eeg->setFileName( m_fileName );
commitDataSet( eeg );
return eeg;
}
......@@ -28,7 +28,6 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include "../WDataHandler.h"
#include "../WLoader.h"
/**
......@@ -42,9 +41,8 @@ public:
* Constructs a loader to be executed in its own thread and sets the data needed
* for the loader when executed in its own thread.
* \param fileName this file will be loaded
* \param dataHandler a pointer to the dataHandler to be able to add the loaded data
*/
WLoaderEEGASCII( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler );
explicit WLoaderEEGASCII( std::string fileName );
/**
* Loads the dataset.
......
......@@ -36,13 +36,12 @@
#include "../../math/WPosition.h"
#include "../../utils/WIOTools.h"
#include "../../utils/WStringUtils.h"
#include "../WDataHandler.h"
#include "../WDataSetFibers.h"
#include "../WSubject.h"
#include "WLoaderFibers.h"
WLoaderFibers::WLoaderFibers( std::string fname, boost::shared_ptr< WDataHandler > dataHandler ) throw( WDHIOFailure )
: WLoader( fname, dataHandler )
WLoaderFibers::WLoaderFibers( std::string fname ) throw( WDHIOFailure )
: WLoader( fname )
{
m_ifs = boost::shared_ptr< std::ifstream >( new std::ifstream() );
m_ifs->open( m_fileName.c_str(), std::ifstream::in | std::ifstream::binary );
......@@ -81,7 +80,6 @@ boost::shared_ptr< WDataSet > WLoaderFibers::load()
shared_ptr< WDataSetFibers > fibers = shared_ptr< WDataSetFibers >( new WDataSetFibers( data ) );
fibers->setFileName( m_fileName );
commitDataSet( fibers );
assert( !m_ifs->is_open() );
return fibers;
}
......
......@@ -36,8 +36,6 @@
#include "../../math/WPosition.h"
#include "../../math/WFiber.h"
class WDataHandler;
/**
* Loader for the VTK file formats. For VTK just see http://www.vtk.org.
* Currently only a subset of the legacy format is supported: MedInria's
......@@ -54,10 +52,9 @@ public:
* Constructs and makes a new VTK loader for separate thread start.
*
* \param fname File name where to load data from
* \param dataHandler Pointer of the dataHandler (where to put the DataSet)
* \throws WDHIOFailure
*/
WLoaderFibers( std::string fname, boost::shared_ptr< WDataHandler > dataHandler ) throw( WDHIOFailure );
explicit WLoaderFibers( std::string fname ) throw( WDHIOFailure );
/**
* Destroys this instance and closes the file.
......
......@@ -30,7 +30,6 @@
#include <boost/shared_ptr.hpp>
#include "WLoaderNIfTI.h"
#include "../WDataHandler.h"
#include "../WDataSet.h"
#include "../WSubject.h"
#include "../WDataSetSingle.h"
......@@ -41,8 +40,8 @@
#include "../WDataHandlerEnums.h"
WLoaderNIfTI::WLoaderNIfTI( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler )
: WLoader( fileName, dataHandler )
WLoaderNIfTI::WLoaderNIfTI( std::string fileName )
: WLoader( fileName )
{
}
......@@ -152,7 +151,6 @@ boost::shared_ptr< WDataSet > WLoaderNIfTI::load()
boost::shared_ptr< WDataSet > newDataSet = boost::shared_ptr< WDataSet >( new WDataSetSingle( newValueSet, newGrid ) );
newDataSet->setFileName( m_fileName );
commitDataSet( newDataSet );
return newDataSet;
}
......
......@@ -34,8 +34,6 @@
#include "nifti/nifti1_io.h"
class WDataHandler;
/**
* Loader for the NIfTI file format. For NIfTI just see http://nifti.nimh.nih.gov/.
* \ingroup dataHandler
......@@ -52,9 +50,8 @@ public:
* Constructs a loader to be executed in its own thread and ets the data needed
* for the loader when executed in its own thread.
* \param fileName this file will be loaded
* \param dataHandler a pointer to the dataHandler to be able to add the loaded data
*/
WLoaderNIfTI( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler );
explicit WLoaderNIfTI( std::string fileName );
/**
* Loads the dataset.
......
......@@ -30,7 +30,6 @@
#include <boost/thread.hpp>
#include "../WLoaderBiosig.h"
#include "../../WDataHandler.h"
/**
* Tests for the biosignal loader that uses biosig library.
......@@ -43,13 +42,11 @@ public:
*/
void testSomething( void )
{
// TODO(wiebel): Improve this test for EEG loading
// std::string fileName = "/dargb/bv_data/Medical/MPI-CBS/ASA/A1_alex_Segment_1.edf";
std::string fileName = "/windows/C/Users/wiebel/Documents/ASA/Export/A1_alex_Segment_1.edf";
// std::string fileName = "/home/wiebel/Data/EEG/A1.cnt";
std::cout << std::endl << "Test loading of " << fileName << "." << std::endl;
boost::shared_ptr< WDataHandler > dataHandler =
boost::shared_ptr< WDataHandler >( new WDataHandler() );
TS_ASSERT_EQUALS( dataHandler->getNumberOfSubjects(), 0 );
// WLoaderBiosig biosigLoader( fileName, dataHandler );
// boost::thread loaderThread( biosigLoader );
......
......@@ -46,25 +46,8 @@ public:
std::string fileName = "../fixtures/eeg_testData.asc";
std::cout << std::endl << "Test loading of " << fileName << "." << std::endl;
boost::shared_ptr< WDataHandler > dataHandler =
boost::shared_ptr< WDataHandler >( new WDataHandler() );
TS_ASSERT_EQUALS( dataHandler->getNumberOfSubjects(), 0 );
WLoaderEEGASCII eegASCIILoader( fileName, dataHandler );
eegASCIILoader.load();
std::clock_t startTime;
startTime = std::clock();
std::clock_t elapsedTime = 0;
while( dataHandler->getNumberOfSubjects() == 0 && ( elapsedTime / static_cast< double >( CLOCKS_PER_SEC ) ) < 4 )
{
elapsedTime = std::clock() - startTime;
}
// TODO(wiebel): we need to change this because loading, in the end,
// should not always increase the number of subjects.
TS_ASSERT_EQUALS( dataHandler->getNumberOfSubjects(), 1 );
WLoaderEEGASCII eegASCIILoader( fileName );
TS_ASSERT( eegASCIILoader.load() );
}
};
......
......@@ -36,7 +36,6 @@
#include "../../../common/test/WStreamPosTraits.h"
#include "../../../math/test/WFiberTraits.h"
#include "../../WDataHandler.h"
#include "../WLoaderFibers.h"
/**
......@@ -45,14 +44,6 @@
class WLoaderFibersTest : public CxxTest::TestSuite
{
public:
/**
* Create test environment.
*/
void setUp( void )
{
m_dataHandler = boost::shared_ptr< WDataHandler >( new WDataHandler() );
}
/**
* A valid "header" of a VTK file consists of 4 lines of text (this is
* arbitrary specified by me, the author of this class)
......@@ -70,7 +61,7 @@ public:
*/
void testReadHeader( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
std::vector< std::string > expected;
expected.push_back( "# vtk DataFile Version 3.0" );
expected.push_back( "Neural Pathways aka as fibers." );
......@@ -85,7 +76,7 @@ public:
*/
void testUnsupportedVTKFileFormatString( void )
{
WLoaderFibers loader( "fixtures/Fibers/unsupported_format_version_string.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/unsupported_format_version_string.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
......@@ -97,7 +88,7 @@ public:
*/
void testReadHeaderOnTooBigVTKHeader( void )
{
WLoaderFibers loader( "fixtures/Fibers/invalid_header_length.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/invalid_header_length.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
......@@ -109,7 +100,7 @@ public:
*/
void testBinaryOrAscii( void )
{
WLoaderFibers loader( "fixtures/Fibers/ascii.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/ascii.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
......@@ -122,7 +113,7 @@ public:
*/
void testCheckDatasetType( void )
{
WLoaderFibers loader( "fixtures/Fibers/invalid_dataset.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/invalid_dataset.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
......@@ -135,7 +126,7 @@ public:
*/
void testStreamPosIsValidAfterReadHeaderCall( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
loader.readHeader();
TS_ASSERT_EQUALS( loader.m_ifs->tellg(), 82 );
}
......@@ -145,7 +136,7 @@ public:
*/
void testNoHeaderThere( void )
{
WLoaderFibers loader( "fixtures/Fibers/no_header.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/no_header.fib" );
TS_ASSERT_THROWS( loader.readHeader(), WDHException );
}
......@@ -154,7 +145,7 @@ public:
*/
void testOnAbruptHeader( void )
{
WLoaderFibers loader( "fixtures/Fibers/crippled_header.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/crippled_header.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
......@@ -167,7 +158,7 @@ public:
*/
void testReadPoints( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
loader.readHeader();
loader.readPoints();
double delta = 0.0001;
......@@ -189,7 +180,7 @@ public:
using std::vector;
using wmath::WFiber;
using wmath::WPosition;
WLoaderFibers loader( "fixtures/Fibers/small_example_one_fiber.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/small_example_one_fiber.fib" );
loader.readHeader();
loader.readPoints();
shared_ptr< vector< WFiber > > actual = loader.readLines();
......@@ -212,7 +203,7 @@ public:
{
std::vector< WLoaderFibers > loaders;
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
loaders.push_back( loader );
// destructor invoked
}
......@@ -226,17 +217,9 @@ public:
*/
void testBracesOperatorTerminatesWell( void )
{
TS_ASSERT_EQUALS( m_dataHandler->getNumberOfSubjects(), 0 );
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
loader.load();
TS_ASSERT_EQUALS( m_dataHandler->getNumberOfSubjects(), 1 );
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
TS_ASSERT( loader.load() );
}
private:
/**
* Dummy DataHandler instance
*/
boost::shared_ptr< WDataHandler > m_dataHandler;
};
#endif // WLOADERFIBERS_TEST_H
......@@ -31,34 +31,19 @@
#include "../WLoaderNIfTI.h"
#include "../WLoaderNIfTI.cpp" //need this to be able instatiate template function
#include "../../WDataHandler.h"
/**
* test class the nifti loader class
*/
class WLoaderNIfTITest : public CxxTest::TestSuite
{
private: // private normally comes behind public, but I would like to make it easily visible here.
/**
* Dummy DataHandler instance
*/
boost::shared_ptr< WDataHandler > m_dataHandler;
public:
/**
* Create test environment.
*/
void setUp( void )
{