Skip to content

Commit

Permalink
refs #5548. Should handle periods now.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jun 27, 2012
1 parent a0b016d commit 6848f38
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 12 deletions.
Expand Up @@ -102,7 +102,8 @@ namespace Mantid
// Load a data block
void loadBlock(Mantid::NeXus::NXDataSetTyped<int> & data, int64_t blocksize, int64_t period, int64_t start,
int64_t &hist, int64_t& spec_num, DataObjects::Workspace2D_sptr localWorkspace);

// Load period logs
void loadPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr local_workspace);

/// The name and path of the input file
std::string m_filename;
Expand Down
41 changes: 30 additions & 11 deletions Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp
Expand Up @@ -228,6 +228,12 @@ namespace Mantid
}
int64_t firstentry = (m_entrynumber > 0) ? m_entrynumber : 1;
loadPeriodData(firstentry, entry, local_workspace);

// Clone the workspace at this point to provide a base object for future workspace generation.
DataObjects::Workspace2D_sptr period_free_workspace = boost::dynamic_pointer_cast<DataObjects::Workspace2D>
(WorkspaceFactory::Instance().create(local_workspace));

loadPeriodLogs(firstentry, local_workspace);

if( m_numberOfPeriods > 1 && m_entrynumber == 0 )
{
Expand All @@ -237,7 +243,7 @@ namespace Mantid
//This forms the name of the group
const std::string base_name = getPropertyValue("OutputWorkspace") + "_";
const std::string prop_name = "OutputWorkspace_";

for( size_t p = 1; p <= m_numberOfPeriods; ++p )
{
std::ostringstream os;
Expand All @@ -246,8 +252,9 @@ namespace Mantid
if( p > 1 )
{
local_workspace = boost::dynamic_pointer_cast<DataObjects::Workspace2D>
(WorkspaceFactory::Instance().create(local_workspace));
(WorkspaceFactory::Instance().create(period_free_workspace));
loadPeriodData(p, entry, local_workspace);
loadPeriodLogs(p, local_workspace);
}
declareProperty(new WorkspaceProperty<Workspace>(prop_name + os.str(), base_name + os.str(), Direction::Output));
wksp_group->addWorkspace(local_workspace);
Expand Down Expand Up @@ -496,6 +503,27 @@ namespace Mantid
}
}

/**
Loads period log data into the workspace
@param period :: period number
@param local_workspace :: workspace to add period log data to.
*/
void LoadISISNexus2::loadPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr local_workspace)
{
// If we loaded an icp_event log then create the necessary period logs
if( local_workspace->run().hasProperty("icp_event") )
{
Kernel::Property *log = local_workspace->run().getProperty("icp_event");
LogParser parser(log);
local_workspace->mutableRun().addProperty(parser.createPeriodLog(static_cast<int>(period)));
Property* periods = parser.createAllPeriodsLog();
if(!local_workspace->mutableRun().hasProperty(periods->name()))
{
local_workspace->mutableRun().addProperty(periods);
}
}
}


/**
* Perform a call to nxgetslab, via the NexusClasses wrapped methods for a given blocksize
Expand Down Expand Up @@ -727,15 +755,6 @@ namespace Mantid
return;
}
ws->populateInstrumentParameters();
// If we loaded an icp_event log then create the necessary period logs
if( ws->run().hasProperty("icp_event") )
{
Kernel::Property *log = ws->run().getProperty("icp_event");
LogParser parser(log);
ws->mutableRun().addProperty(parser.createPeriodLog(period));
ws->mutableRun().addProperty(parser.createAllPeriodsLog());
}

}

double LoadISISNexus2::dblSqrt(double in)
Expand Down
58 changes: 58 additions & 0 deletions Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h
Expand Up @@ -11,13 +11,37 @@
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidKernel/LogFilter.h"

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

class LoadISISNexusTest : public CxxTest::TestSuite
{
private:

// Helper method to fetch the log property entry corresponding to period.
Property* fetchPeriod(MatrixWorkspace_sptr workspace, int expectedPeriodNumber)
{
std::stringstream period_number_stream;
period_number_stream << expectedPeriodNumber;
std::string log_name = "period " + period_number_stream.str();
Property* p= workspace->run().getLogData(log_name);
return p;
}

// Helper method to check that the log data contains a specific period number entry.
void checkPeriodLogData(MatrixWorkspace_sptr workspace, int expectedPeriodNumber)
{
Property* p;
TS_ASSERT_THROWS_NOTHING(p = fetchPeriod(workspace, expectedPeriodNumber));
TSM_ASSERT_THROWS("Shouldn't have a period less than the expected entry", fetchPeriod(workspace, expectedPeriodNumber-1), Mantid::Kernel::Exception::NotFoundError);
TSM_ASSERT_THROWS("Shouldn't have a period greater than the expected entry", fetchPeriod(workspace, expectedPeriodNumber+1), Mantid::Kernel::Exception::NotFoundError);
Mantid::Kernel::TimeSeriesProperty<bool>* period_property = dynamic_cast<Mantid::Kernel::TimeSeriesProperty<bool>*>(p);
TS_ASSERT(period_property);
}

public:
void testExec()
{
Expand Down Expand Up @@ -80,6 +104,7 @@ class LoadISISNexusTest : public CxxTest::TestSuite

Property *l_property = ws->run().getLogData( "run_number" );
TS_ASSERT_EQUALS( l_property->value(), "49886" );
AnalysisDataService::Instance().remove("outWS");
}
void testExec2()
{
Expand Down Expand Up @@ -109,6 +134,7 @@ class LoadISISNexusTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws->readY(8)[1],2.);
TS_ASSERT_EQUALS(ws->readY(10)[3],1.);
TS_ASSERT_EQUALS(ws->readY(13)[4],1.);
AnalysisDataService::Instance().remove("outWS");
}
void testMultiPeriodEntryNumberZero()
{
Expand Down Expand Up @@ -143,6 +169,7 @@ class LoadISISNexusTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws->readY(7)[1],0.);
TS_ASSERT_EQUALS(ws->readY(9)[3],0.);
TS_ASSERT_EQUALS(ws->readY(9)[1],0.);
AnalysisDataService::Instance().remove("outWS");
}
void testMultiPeriodEntryNumberNonZero()
{
Expand Down Expand Up @@ -175,6 +202,37 @@ class LoadISISNexusTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws->readY(7)[1],0.);
TS_ASSERT_EQUALS(ws->readY(9)[3],0.);
TS_ASSERT_EQUALS(ws->readY(9)[1],0.);
AnalysisDataService::Instance().remove("outWS");
}

void testLoadMultiPeriodData()
{
Mantid::API::FrameworkManager::Instance();
const std::string wsName = "outWS";
LoadISISNexus2 loadingAlg;
loadingAlg.initialize();
loadingAlg.setRethrows(true);
loadingAlg.setPropertyValue("Filename","POLREF00004699.nxs");
loadingAlg.setPropertyValue("OutputWorkspace", wsName);
loadingAlg.execute();
TS_ASSERT(loadingAlg.isExecuted());

AnalysisDataServiceImpl& ADS = AnalysisDataService::Instance();

WorkspaceGroup_sptr grpWs;
TS_ASSERT_THROWS_NOTHING(grpWs=ADS.retrieveWS<WorkspaceGroup>(wsName));
TSM_ASSERT_EQUALS("Should be two workspaces in the group",2, grpWs->size());

// Check the individual workspace group members.
MatrixWorkspace_sptr ws1 = boost::dynamic_pointer_cast<MatrixWorkspace>(grpWs->getItem(0));
MatrixWorkspace_sptr ws2 = boost::dynamic_pointer_cast<MatrixWorkspace>(grpWs->getItem(1));
TS_ASSERT(ws1 != NULL);
TS_ASSERT(ws2 != NULL);
// Check that workspace 1 has the correct period data, and no other period log data
checkPeriodLogData(ws1, 1);
// Check that workspace 2 has the correct period data, and no other period log data
checkPeriodLogData(ws2, 2);
AnalysisDataService::Instance().remove(wsName);
}
};

Expand Down
Binary file added Test/AutoTestData/POLREF00004699.nxs
Binary file not shown.

0 comments on commit 6848f38

Please sign in to comment.