Skip to content

Commit

Permalink
Add SplittersWorkspace. Refs #5056.
Browse files Browse the repository at this point in the history
Add
(1) abstract class ISplittersWorkspace for python.
(2) SplitterWorkspace inheriting from TableWorkspace.
  • Loading branch information
wdzhou committed Apr 4, 2012
1 parent 5b5d4d3 commit 4e8c127
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set ( SRC_FILES
src/IPeakFunction.cpp
src/IPeaksWorkspace.cpp
src/ISpectrum.cpp
src/ISplittersWorkspace.cpp
src/ITableWorkspace.cpp
src/ImplicitFunctionParameterParserFactory.cpp
src/ImplicitFunctionParserFactory.cpp
Expand Down Expand Up @@ -162,6 +163,7 @@ set ( INC_FILES
inc/MantidAPI/IPeakFunction.h
inc/MantidAPI/IPeaksWorkspace.h
inc/MantidAPI/ISpectrum.h
inc/MantidAPI/ISplittersWorkspace.h
inc/MantidAPI/ITableWorkspace.h
inc/MantidAPI/IWorkspaceProperty.h
inc/MantidAPI/ImplicitFunctionBuilder.h
Expand Down
82 changes: 82 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/ISplittersWorkspace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef MANTID_API_ISPLITTERSWORKSPACE_H_
#define MANTID_API_ISPLITTERSWORKSPACE_H_

#include "MantidKernel/System.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidKernel/TimeSplitter.h"


namespace Mantid
{
namespace API
{

/** ISplittersWorkspace : Workspace to contain splitters for event filtering.
* It inherits from ITableWorkspace
@date 2012-04-03
Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport ISplittersWorkspace : virtual public API::ITableWorkspace
{
public:
/*
* Constructor
*/
ISplittersWorkspace()
:API::ITableWorkspace()
{
}

/*
* Destructor
*/
virtual ~ISplittersWorkspace();

/*
* Add a time splitter to table workspace
*/
virtual void addSplitter(Kernel::SplittingInterval splitter) = 0;

/*
* Get the corresponding workspace index of a time
* Input time must the total nanoseconds of the absolute time from 1990.00.00
*/
virtual Kernel::SplittingInterval getSplitter(size_t index) = 0;

/*
* Get number of splitters
*/
virtual size_t getNumberSplitters() = 0;

/*
* Remove one entry of a splitter
*/
virtual bool removeSplitter(size_t splitterindex) = 0;

};


} // namespace API
} // namespace Mantid

#endif /* MANTID_API_ISPLITTERSWORKSPACE_H_ */
19 changes: 19 additions & 0 deletions Code/Mantid/Framework/API/src/ISplittersWorkspace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/ISplittersWorkspace.h"

namespace Mantid
{
namespace API
{

using namespace Kernel;

ISplittersWorkspace::~ISplittersWorkspace() {}


} //API namespace

} //Mantid namespace

11 changes: 7 additions & 4 deletions Code/Mantid/Framework/DataObjects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ set ( SRC_FILES
src/ManagedDataBlock2D.cpp
src/ManagedHistogram1D.cpp
src/ManagedWorkspace2D.cpp
src/MaskWorkspace.cpp
src/MaskWorkspace.cpp
src/MementoTableWorkspace.cpp
src/OffsetsWorkspace.cpp
src/Peak.cpp
src/PeakColumn.cpp
src/PeaksWorkspace.cpp
src/SpecialWorkspace2D.cpp
src/SplittersWorkspace.cpp
src/TableColumn.cpp
src/TableWorkspace.cpp
src/Workspace2D.cpp
Expand All @@ -44,20 +45,21 @@ set ( INC_FILES
inc/MantidDataObjects/ManagedDataBlock2D.h
inc/MantidDataObjects/ManagedHistogram1D.h
inc/MantidDataObjects/ManagedWorkspace2D.h
inc/MantidDataObjects/MaskWorkspace.h
inc/MantidDataObjects/MaskWorkspace.h
inc/MantidDataObjects/MementoTableWorkspace.h
inc/MantidDataObjects/OffsetsWorkspace.h
inc/MantidDataObjects/Peak.h
inc/MantidDataObjects/PeakColumn.h
inc/MantidDataObjects/PeaksWorkspace.h
inc/MantidDataObjects/SpecialWorkspace2D.h
inc/MantidDataObjects/SplittersWorkspace.h
inc/MantidDataObjects/TableColumn.h
inc/MantidDataObjects/TableWorkspace.h
inc/MantidDataObjects/Workspace2D.h
inc/MantidDataObjects/WorkspaceSingleValue.h
)

set ( TEST_FILES
set ( TEST_FILES
test/CompressedWorkspace2DTest.h
test/EventListTest.h
test/EventWorkspaceMRUTest.h
Expand All @@ -68,14 +70,15 @@ set ( TEST_FILES
test/ManagedDataBlock2DTest.h
test/ManagedHistogram1DTest.h
test/ManagedWorkspace2DTest.h
test/MaskWorkspaceTest.h
test/MaskWorkspaceTest.h
test/MementoTableWorkspaceTest.h
test/OffsetsWorkspaceTest.h
test/PeakColumnTest.h
test/PeakTest.h
test/PeaksWorkspaceTest.h
test/RefAxisTest.h
test/SpecialWorkspace2DTest.h
test/SplittersWorkspaceTest.h
test/TableWorkspacePropertyTest.h
test/TableWorkspaceTest.h
test/TofEventTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef MANTID_DATAOBJECTS_SPLITTERSWORKSPACE_H_
#define MANTID_DATAOBJECTS_SPLITTERSWORKSPACE_H_

#include "MantidKernel/System.h"
#include "MantidAPI/ISplittersWorkspace.h"
#include "MantidKernel/TimeSplitter.h"
#include "MantidDataObjects/TableWorkspace.h"


namespace Mantid
{
namespace DataObjects
{

/** SplittersWorkspace : A TableWorkspace to contain TimeSplitters.
It will be used as an input for FilterEvents, which is the ultimate method for event filtering.
There can be various algorithms to generate an object like this.
A SplittersWorkspace contains 3 columns as int64, int64 and int32 to denote
(1) splitter start time (2) splitter end time and (3) group workspace index
@date 2012-04-03
Copyright &copy; 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport SplittersWorkspace : public API::ISplittersWorkspace, public DataObjects::TableWorkspace
{
public:
SplittersWorkspace();
virtual ~SplittersWorkspace();

void addSplitter(Kernel::SplittingInterval splitter);

Kernel::SplittingInterval getSplitter(size_t index);

size_t getNumberSplitters();

bool removeSplitter(unsigned long);

};


} // namespace DataObjects
} // namespace Mantid

#endif /* MANTID_DATAOBJECTS_SPLITTERSWORKSPACE_H_ */
87 changes: 87 additions & 0 deletions Code/Mantid/Framework/DataObjects/src/SplittersWorkspace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "MantidDataObjects/SplittersWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidAPI/Column.h"
#include "MantidAPI/TableRow.h"

using namespace Mantid::Kernel;
using namespace Mantid::API;

namespace Mantid
{
namespace DataObjects
{

Kernel::Logger& mg_log = Kernel::Logger::get("ITableWorkspace");

//----------------------------------------------------------------------------------------------
/** Constructor
*/
SplittersWorkspace::SplittersWorkspace()
{
this->addColumn("long64", "start");
this->addColumn("long64", "stop");
this->addColumn("int", "workspacegroup");
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
SplittersWorkspace::~SplittersWorkspace()
{
}

/*
* Add a Splitter to
*/
void SplittersWorkspace::addSplitter(Mantid::Kernel::SplittingInterval splitter)
{
Mantid::API::TableRow row = this->appendRow();
row << splitter.start().totalNanoseconds();
row << splitter.stop().totalNanoseconds();
row << splitter.index();

return;
}

Kernel::SplittingInterval SplittersWorkspace::getSplitter(size_t index)
{
API::Column_const_sptr column = this->getColumn("start");
API::TableRow row = this->getRow(index);
int64_t start, stop;
int wsgroup;
row >> start;
row >> stop;
row >> wsgroup;

Kernel::SplittingInterval splitter(Kernel::DateAndTime(start), Kernel::DateAndTime(stop), wsgroup);

return splitter;
}

size_t SplittersWorkspace::getNumberSplitters()
{
return this->rowCount();
}


bool SplittersWorkspace::removeSplitter(unsigned long index)
{
bool removed;
if (index >= this->rowCount())
{
mg_log.error() << "Try to delete a non-existing splitter " << index << std::endl;
removed = false;
}
else
{
this->removeRow(index);
removed = true;
}

return removed;
}



} // namespace Mantid
} // namespace DataObjects

0 comments on commit 4e8c127

Please sign in to comment.