Commit fb35a5cd authored by Janik Zikovsky's avatar Janik Zikovsky
Browse files

Refs #3126: clone() method and copy constructor for PeaksWorkspace.

parent f093f68a
...@@ -68,8 +68,12 @@ namespace DataObjects ...@@ -68,8 +68,12 @@ namespace DataObjects
PeaksWorkspace(); PeaksWorkspace();
PeaksWorkspace(PeaksWorkspace & other);
virtual ~PeaksWorkspace(); virtual ~PeaksWorkspace();
boost::shared_ptr<PeaksWorkspace> clone();
void appendFile( std::string filename, Mantid::Geometry::IInstrument_sptr inst); void appendFile( std::string filename, Mantid::Geometry::IInstrument_sptr inst);
/** Sets the default instrument for new peaks */ /** Sets the default instrument for new peaks */
...@@ -179,6 +183,8 @@ namespace DataObjects ...@@ -179,6 +183,8 @@ namespace DataObjects
/** Column names */ /** Column names */
std::vector<std::string> columnNames; std::vector<std::string> columnNames;
void initColumns();
public: public:
......
...@@ -44,7 +44,43 @@ namespace DataObjects ...@@ -44,7 +44,43 @@ namespace DataObjects
* *
* @return PeaksWorkspace object * @return PeaksWorkspace object
*/ */
PeaksWorkspace::PeaksWorkspace():ITableWorkspace( ) PeaksWorkspace::PeaksWorkspace()
: ITableWorkspace()
{
initColumns();
}
//---------------------------------------------------------------------------------------------
/** Copy constructor
*
* @param other :: other PeaksWorkspace to copy from
* @return
*/
PeaksWorkspace::PeaksWorkspace(PeaksWorkspace & other)
: ITableWorkspace(),
peaks(other.peaks),
m_defaultInst(other.m_defaultInst)
{
initColumns();
this->peaks = other.peaks;
}
//---------------------------------------------------------------------------------------------
/** Clone a shared pointer
*
* @param other :: other PeaksWorkspace to copy from
* @return copy of the peaksworkspace
*/
boost::shared_ptr<PeaksWorkspace> PeaksWorkspace::clone()
{
// Copy construct and return
return boost::shared_ptr<PeaksWorkspace>(new PeaksWorkspace(*this));
}
//---------------------------------------------------------------------------------------------
/** Initialize all columns */
void PeaksWorkspace::initColumns()
{ {
// Note: These column names must match what PeakColumn expects! // Note: These column names must match what PeakColumn expects!
addColumn( "int", "RunNumber"); addColumn( "int", "RunNumber");
...@@ -67,7 +103,6 @@ namespace DataObjects ...@@ -67,7 +103,6 @@ namespace DataObjects
} }
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
/** Destructor */ /** Destructor */
PeaksWorkspace::~PeaksWorkspace() PeaksWorkspace::~PeaksWorkspace()
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "MantidGeometry/V3D.h" #include "MantidGeometry/V3D.h"
#include "MantidKernel/Strings.h" #include "MantidKernel/Strings.h"
#include "MantidKernel/PhysicalConstants.h" #include "MantidKernel/PhysicalConstants.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
using namespace Mantid::DataObjects; using namespace Mantid::DataObjects;
using namespace Mantid::API; using namespace Mantid::API;
...@@ -24,222 +25,80 @@ class PeaksWorkspaceTest : public CxxTest::TestSuite ...@@ -24,222 +25,80 @@ class PeaksWorkspaceTest : public CxxTest::TestSuite
{ {
public: public:
int removeFile( std::string outfile)
{
return remove( outfile.c_str());
}
bool sameFileContents( std::string file1, std::string file2) // int removeFile( std::string outfile)
{ // {
std::ifstream in1( file1.c_str() ); // return remove( outfile.c_str());
std::ifstream in2( file2.c_str() ); // }
//
std::string s1, s2; // bool sameFileContents( std::string file1, std::string file2)
while (in1.good() && in2.good()) // {
{ // std::ifstream in1( file1.c_str() );
std::getline(in1,s1); // std::ifstream in2( file2.c_str() );
std::getline(in2,s2); //
s1 = Strings::replace(s1, "\r", ""); // std::string s1, s2;
s2 = Strings::replace(s2, "\r", ""); // while (in1.good() && in2.good())
if (s1 != s2)
return false;
}
if( in1.good() || in2.good())
return false;
return true;
// bool done = false;
// char c1,c2;
// while( !done)
// { // {
// if( !in1.good() || !in2.good()) // std::getline(in1,s1);
// done = true; // std::getline(in2,s2);
// else // s1 = Strings::replace(s1, "\r", "");
// { // s2 = Strings::replace(s2, "\r", "");
// c1= in1.get(); // if (s1 != s2)
// c2= in2.get(); // return false;
// if( c1 != c2)
// return false;
// }
// } // }
// if( in1.good() || in2.good()) // if( in1.good() || in2.good())
// return false; // return false;
// return true; // return true;
// return true; // }
}
void test_Something() /** Build a test PeaksWorkspace
*
* @return PeaksWorkspace
*/
PeaksWorkspace * buildPW()
{ {
std::vector<std::string>ext; IInstrument_sptr inst = ComponentCreationHelper::createTestInstrumentRectangular2(1, 10);
ext.push_back(std::string("peaks")); PeaksWorkspace * pw = new PeaksWorkspace();
Mantid::API::FileProperty fProp("Filename","",FileProperty::Load,ext, Mantid::Kernel::Direction::Input ); Peak p(inst, 1, 3.0);
fProp.setValue("Ni1172A.peaks"); pw->addPeak(p);
return pw;
PeaksWorkspace pw;
} }
// std::string infile(fProp.value()); /** Check that the PeaksWorkspace build by buildPW() is correct */
// void checkPW(PeaksWorkspace * pw)
// TS_ASSERT_THROWS_NOTHING( pw.append(infile)); {
// TS_ASSERT_EQUALS( pw->columnCount(), 17);
// std::string outfile( infile); TS_ASSERT_EQUALS( pw->rowCount(), 1);
// TS_ASSERT_EQUALS( pw->getNumberPeaks(), 1);
// if (pw->getNumberPeaks() != 1) return;
// outfile.append("1"); TS_ASSERT_DELTA( pw->getPeak(0).getWavelength(), 3.0, 1e-4);
// removeFile( outfile ); }
// TS_ASSERT_THROWS_NOTHING( pw.write(outfile ));
//
// TS_ASSERT( sameFileContents(infile,outfile));
//
// TS_ASSERT_EQUALS( removeFile( outfile ),0);
//
// //Check base data read in correctly
// V3D hkl=pw.get_hkl(6);
// V3D test(5,3,-3);
// V3D save(hkl);
// hkl -= test;
// TS_ASSERT_LESS_THAN(hkl.norm(),.00001);
// TS_ASSERT( save==pw.get_hkl(6));
//
//
// V3D position =pw.getPosition(6);
// V3D ptest;
// ptest.spherical(.45647,1.3748*180/M_PI,2.52165*180/M_PI);
// V3D psave(position);
//
// position -=ptest;
// TS_ASSERT_LESS_THAN(position.norm(),.001);
// TS_ASSERT( psave==pw.getPosition(6));
//
// TS_ASSERT_LESS_THAN(abs( 187.25-pw.get_column(6)),.05 );
// TS_ASSERT_LESS_THAN(abs( 121.29-pw.get_row(6)),.05 );
// TS_ASSERT_LESS_THAN(abs( 283.13-pw.get_time_channel(6)),.05 );
// TS_ASSERT_LESS_THAN(abs( 17-pw.getPeakCellCount(6)),.05 );
// TS_ASSERT_LESS_THAN(abs( 4571.82-pw.getPeakIntegrationCount(6)),.05 );
// TS_ASSERT_LESS_THAN(abs( 88.13-pw.getPeakIntegrationError(6)),.01 );
// TS_ASSERT_LESS_THAN(abs(10 -pw.getReflag(6)),.001 );
//
//
// TS_ASSERT_EQUALS( 1172,pw.cell<int>(6,pw.IrunNumCol) );
// TS_ASSERT_EQUALS(3 , pw.get_Bank(6));
// TS_ASSERT_LESS_THAN(abs( 10000-pw.getMonitorCount(6)),.1 );
//
// TS_ASSERT_LESS_THAN( abs(18-pw.get_L1(6)),.0001);
// TS_ASSERT_LESS_THAN( abs(0-pw.get_time_offset(6)),.001);
//
// V3D sampOrient = pw.getSampleOrientation(6);
// V3D soSave(sampOrient);
// V3D soTest(164.96,45,0);
// soTest *=M_PI/180;
// sampOrient -=soTest;
// TS_ASSERT_LESS_THAN( sampOrient.norm(), .001);
// TS_ASSERT( soSave ==pw.getSampleOrientation(6) );
//
// TS_ASSERT_LESS_THAN( abs(.5203-pw.get_dspacing(6)),.001);
//
// TS_ASSERT_LESS_THAN( abs(.660962-pw.get_wavelength(6)),.001);
//
// TS_ASSERT_LESS_THAN( abs(1/.5203-pw.get_Qmagnitude(6)),.004);
//
//
// V3D Qlab= pw.get_Qlab(6);
// // McStas==back,up,beam
// V3D QlabTest(-1.2082262,.8624681,-1.220807);
// Qlab -=QlabTest;
// TS_ASSERT_LESS_THAN( Qlab.norm(), .001);
//
// V3D QlabR= pw.get_QXtal(6);
// // McStas==back,up,beam
// V3D QlabRSave = V3D(QlabR);
// V3D QlabRTest(.55290407,1.4642019,1.1155452);
// QlabR -=QlabRTest;
// TS_ASSERT_LESS_THAN( QlabR.norm(), .001);
//
// Matrix<double> mat(3,3);
// int beam =2;
// int up =1;
// int back =0;
// int base1=0;
// int base2 = 1;
// int base3 =2;
// mat[beam][base1]=-0.36622801;
// mat[back][base1]=-0.17730089;
// mat[up][base1]=-0.29209167;
// mat[beam][base2]=-0.52597409;
// mat[back][base2]=0.20688301;
// mat[up][base2]=0.00279823;
// mat[beam][base3]=-0.15912011;
// mat[back][base3]=0.36190018;
// mat[up][base3]=-0.28579932;
//
// pw.sethkls( mat, .1, false, 1);
// Matrix<double>matSave = Matrix<double>(mat);
// mat.Invert();
// QlabRSave = pw.get_QXtal(6);
//
// V3D hklD = (mat*QlabRSave)-pw.get_hkl(6);
// TS_ASSERT_LESS_THAN( hklD.norm() ,.001);
// TS_ASSERT_EQUALS( pw.getReflag(6),10);
//
// pw.sethkls( matSave, .1, true, 2);
// hklD = (mat*QlabRSave)-pw.get_hkl(6);
// TS_ASSERT_LESS_THAN( hklD.norm() ,.001);
// TS_ASSERT_EQUALS( pw.getReflag(6),10);
//
//
// pw.sethkls( matSave, .01, false, 1);
// TS_ASSERT_EQUALS( pw.get_hkl(6).norm(),0);
// TS_ASSERT_EQUALS( pw.getReflag(6),0);
//
// pw.sethkls( matSave, .1, true, 2);
// hklD = (mat*QlabRSave)-pw.get_hkl(6);
// TS_ASSERT_LESS_THAN( hklD.norm() ,.001);
// TS_ASSERT_EQUALS( pw.getReflag(6),20);
//
// //Now test out the various sets. Not all sets are possible.
// V3D testV(3,5,-6);
// pw.sethkl( testV, 6);
// TS_ASSERT( pw.get_hkl(6)==testV);
//
// pw.setPeakCount(23,6);
// TS_ASSERT_EQUALS( pw.getPeakCellCount(6),23);
//
// pw.setPeakIntegrateCount( 235,6);
// TS_ASSERT_EQUALS( pw.getPeakIntegrationCount(6),235);
//
// //add set row, col ,chan, time
//
// pw.setPeakIntegrateError( 15,6);
// TS_ASSERT_EQUALS(pw.getPeakIntegrationError(6),15 );
//
//
// pw.setReflag(35,6);
// TS_ASSERT_EQUALS( pw.getReflag(6) , 35);
//
// V3D pos(12,3,-5);
// pw.setPeakPos( pos, 6);
// TS_ASSERT_EQUALS( pw.getPosition(6), pos);
//
// pw.setTime( 1280,6);
// TS_ASSERT_EQUALS( pw.getTime( 6), 1280 );
//
// pw.setRowColChan( 5,8,200,6);
// TS_ASSERT_EQUALS( pw.get_row(6) , 5);
// TS_ASSERT_EQUALS( pw.get_column(6) , 8);
// TS_ASSERT_EQUALS( pw.get_time_channel(6) , 200);
// }
void test_defaultConstructor()
{
PeaksWorkspace * pw = buildPW();
checkPW(pw);
delete pw;
}
void test_copyConstructor()
{
PeaksWorkspace * pw = buildPW();
PeaksWorkspace * pw2 = new PeaksWorkspace(*pw);
checkPW(pw2);
delete pw;
delete pw2;
}
void test_constructor() void test_clone()
{ {
PeaksWorkspace pw; PeaksWorkspace_sptr pw(buildPW());
//pw.addPeak(p); PeaksWorkspace_sptr pw2 = pw->clone();
checkPW(pw2.get());
} }
}; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment