Skip to content

Commit

Permalink
Re #8526 Cleaning up before closing the ticket.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Leal committed Dec 6, 2013
1 parent a2607be commit 355be9e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 69 deletions.
101 changes: 50 additions & 51 deletions Code/Mantid/Framework/DataHandling/src/LoadILL.cpp
Expand Up @@ -9,8 +9,6 @@ The property FilenameVanadium is optional. If it is present the EPP will be load
To date this algorithm only supports: IN4, IN5 and IN6
*WIKI*/
//---------------------------------------------------
// Includes
Expand Down Expand Up @@ -122,36 +120,6 @@ namespace Mantid

}

/**
*
*/
int LoadILL::validateVanadium(const std::string &filenameVanadium) {
NeXus::NXRoot vanaRoot(filenameVanadium);
NXEntry vanaFirstEntry = vanaRoot.openFirstEntry();

double wavelength = vanaFirstEntry.getFloat("wavelength");

// read in the data
NXData dataGroup = vanaFirstEntry.openNXData("data");
NXInt data = dataGroup.openIntData();

size_t numberOfTubes = static_cast<size_t>(data.dim0());
size_t numberOfPixelsPerTube = static_cast<size_t>(data.dim1());
size_t numberOfChannels = static_cast<size_t>(data.dim2());

if (wavelength != m_wavelength || numberOfTubes != m_numberOfTubes
|| numberOfPixelsPerTube != m_numberOfPixelsPerTube
|| numberOfChannels != m_numberOfChannels) {
throw std::runtime_error(
"Vanadium and Data were not collected in the same conditions!");
}

data.load();
int calculatedDetectorElasticPeakPosition = getDetectorElasticPeakPosition(
data);
return calculatedDetectorElasticPeakPosition;
}


/**
* Execute the algorithm
Expand Down Expand Up @@ -467,6 +435,43 @@ namespace Mantid
return calculatedDetectorElasticPeakPosition;

}

/**
* It loads the vanadium nexus file and cross checks it against the
* data file already loaded (same wavelength and same instrument configuration).
* If matches looks for the elastic peak in the vanadium file and returns
* it position.
*
* @param filenameVanadium :: The path for the vanadium nexus file.
* @return The elastic peak position inside the tof channels.
*/
int LoadILL::validateVanadium(const std::string &filenameVanadium) {
NeXus::NXRoot vanaRoot(filenameVanadium);
NXEntry vanaFirstEntry = vanaRoot.openFirstEntry();

double wavelength = vanaFirstEntry.getFloat("wavelength");

// read in the data
NXData dataGroup = vanaFirstEntry.openNXData("data");
NXInt data = dataGroup.openIntData();

size_t numberOfTubes = static_cast<size_t>(data.dim0());
size_t numberOfPixelsPerTube = static_cast<size_t>(data.dim1());
size_t numberOfChannels = static_cast<size_t>(data.dim2());

if (wavelength != m_wavelength || numberOfTubes != m_numberOfTubes
|| numberOfPixelsPerTube != m_numberOfPixelsPerTube
|| numberOfChannels != m_numberOfChannels) {
throw std::runtime_error(
"Vanadium and Data were not collected in the same conditions!");
}

data.load();
int calculatedDetectorElasticPeakPosition = getDetectorElasticPeakPosition(
data);
return calculatedDetectorElasticPeakPosition;
}

/**
* Loads all the spectra into the workspace, including that from the monitor
*
Expand Down Expand Up @@ -550,29 +555,23 @@ namespace Mantid
/**
* Run the Child Algorithm LoadInstrument.
*/
void LoadILL::runLoadInstrument()
{
void LoadILL::runLoadInstrument() {

IAlgorithm_sptr loadInst = createChildAlgorithm("LoadInstrument");

// Now execute the Child Algorithm. Catch and log any error, but don't stop.
try
{

// TODO: depending on the m_numberOfPixelsPerTube we might need to load a different IDF

loadInst->setPropertyValue("InstrumentName", m_instrumentName);
loadInst->setProperty<MatrixWorkspace_sptr>("Workspace",
m_localWorkspace);
loadInst->execute();
} catch (...)
{
g_log.information("Cannot load the instrument definition.");
}
}
IAlgorithm_sptr loadInst = createChildAlgorithm("LoadInstrument");

// Now execute the Child Algorithm. Catch and log any error, but don't stop.
try {

// TODO: depending on the m_numberOfPixelsPerTube we might need to load a different IDF

loadInst->setPropertyValue("InstrumentName", m_instrumentName);
loadInst->setProperty<MatrixWorkspace_sptr>("Workspace",
m_localWorkspace);
loadInst->execute();
} catch (...) {
g_log.information("Cannot load the instrument definition.");
}
}



Expand Down
40 changes: 22 additions & 18 deletions Code/Mantid/Framework/DataHandling/test/LoadILLTest.h
Expand Up @@ -17,8 +17,7 @@ class LoadILLTest: public CxxTest::TestSuite
static void destroySuite( LoadILLTest *suite ) { delete suite; }

LoadILLTest() :
m_testFile("ILLIN5_104007.nxs")
{
m_dataFile("ILLIN5_104007.nxs") {
}

void testName() {
Expand All @@ -37,35 +36,32 @@ class LoadILLTest: public CxxTest::TestSuite
TS_ASSERT( loader.isInitialized());
}

// void testFileCheck() {
// std::cerr << loader.fileCheck(testFile);
// }

void testExec() {
/*
* This test only loads the Sample Data
* The elastic peak is obtained on the fly from the sample data.
*/
void testExecJustSample() {
LoadILL loader;
loader.initialize();
loader.setPropertyValue("Filename", m_testFile);
loader.setPropertyValue("Filename", m_dataFile);

std::string outputSpace = "LoadILLTest_out";
loader.setPropertyValue("OutputWorkspace", outputSpace);
TS_ASSERT_THROWS_NOTHING( loader.execute());

// test workspace, copied from LoadMuonNexusTest.h
MatrixWorkspace_sptr output;

(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
outputSpace));
MatrixWorkspace_sptr output2D = boost::dynamic_pointer_cast<
MatrixWorkspace>(output);
MatrixWorkspace_sptr output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputSpace);
MatrixWorkspace_sptr output2D = boost::dynamic_pointer_cast<MatrixWorkspace>(output);

TS_ASSERT_EQUALS( output2D->getNumberHistograms(), 98304);

AnalysisDataService::Instance().clear();
}



private:
std::string m_dataFile;

std::string m_testFile;
};

//------------------------------------------------------------------------------
Expand All @@ -74,13 +70,21 @@ class LoadILLTest: public CxxTest::TestSuite

class LoadILLTestPerformance: public CxxTest::TestSuite {
public:
LoadILLTestPerformance() :
m_dataFile("ILLIN5_104007.nxs"){
}

void testDefaultLoad() {
Mantid::DataHandling::LoadILL loader;
loader.initialize();
loader.setPropertyValue("Filename", "ILLIN5_104007.nxs");
loader.setPropertyValue("Filename", m_dataFile);
loader.setPropertyValue("OutputWorkspace", "ws");
TS_ASSERT( loader.execute());
TS_ASSERT(loader.execute());
}

private:
std::string m_dataFile;

};

#endif /*LoadILLTEST_H_*/

0 comments on commit 355be9e

Please sign in to comment.