Skip to content

Commit

Permalink
Merge pull request #388 from mantidproject/11350_converttomd_no_expt_…
Browse files Browse the repository at this point in the history
…info_loading

Avoid loading experiment info from accumulated MD file
  • Loading branch information
Anders-Markvardsen committed Mar 20, 2015
2 parents ac8dd14 + 9ca2298 commit b642131
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 43 deletions.
7 changes: 4 additions & 3 deletions Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp
Expand Up @@ -28,11 +28,12 @@ FileBackedExperimentInfo::FileBackedExperimentInfo(const std::string &filename,
: ExperimentInfo(), m_loaded(false), m_filename(filename), m_nxpath(nxpath) {}

/**
* @return A clone of the object
* This clones the FileBackedExperimentInfo and will not cause a load
* of the information.
* @return A clone of the object.
*/
ExperimentInfo *FileBackedExperimentInfo::cloneExperimentInfo() const {
populateIfNotLoaded();
return ExperimentInfo::cloneExperimentInfo();
return new FileBackedExperimentInfo(*this);
}

/// @returns A human-readable description of the object
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h
Expand Up @@ -45,12 +45,12 @@ class FileBackedExperimentInfoTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(fileBacked->toString(), m_inMemoryExptInfo->toString());
}

void test_cloneExperimentInfo_populates_object() {
void test_cloneExperimentInfo_returns_new_file_backed_object_and_does_not_touch_file() {
auto fileBacked = createTestObject();
auto *clonedFileBacked = fileBacked->cloneExperimentInfo();

TS_ASSERT_EQUALS(clonedFileBacked->toString(),
m_inMemoryExptInfo->toString());
TS_ASSERT(dynamic_cast<FileBackedExperimentInfo*>(clonedFileBacked));

delete clonedFileBacked;
}

Expand Down
46 changes: 24 additions & 22 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
Expand Up @@ -87,8 +87,9 @@ void ConvertToMD::init() {
setPropertyGroup("MinRecursionDepth", getBoxSettingsGroupName());

declareProperty(
new PropertyWithValue<bool>("InitialSplitting", 0, Direction::Input),
"This option causes an initial split of 50 for the first four dimensions at level 0.");
new PropertyWithValue<bool>("InitialSplitting", 0, Direction::Input),
"This option causes an initial split of 50 for the first four dimensions "
"at level 0.");
}
//----------------------------------------------------------------------------------------------
/** Destructor
Expand Down Expand Up @@ -326,9 +327,13 @@ void ConvertToMD::copyMetaData(API::IMDEventWorkspace_sptr &mdEventWS) const {
}
}

// The last experiment info should always be the one that refers
// to latest converting workspace. All others should have had this
// information set already
uint16_t nexpts = mdEventWS->getNumExperimentInfo();
for (uint16_t i = 0; i < nexpts; ++i) {
ExperimentInfo_sptr expt = mdEventWS->getExperimentInfo(i);
if (nexpts > 0) {
ExperimentInfo_sptr expt =
mdEventWS->getExperimentInfo(static_cast<uint16_t>(nexpts - 1));
expt->mutableRun().storeHistogramBinBoundaries(binBoundaries);
expt->cacheDetectorGroupings(*mapping);
}
Expand Down Expand Up @@ -471,13 +476,10 @@ API::IMDEventWorkspace_sptr ConvertToMD::createNewMDWorkspace(
// Check if the user want sto force an initial split or not
bool initialSplittingChecked = this->getProperty("InitialSplitting");

if (!initialSplittingChecked)
{
if (!initialSplittingChecked) {
// split boxes;
spws->splitBox();
}
else
{
} else {
// Perform initial split with the forced settings
performInitialSplitting(spws, bc);
}
Expand All @@ -494,35 +496,35 @@ API::IMDEventWorkspace_sptr ConvertToMD::createNewMDWorkspace(
}

/**
* Splits the initial box at level 0 into a defined number of subboxes for the the first level.
* Splits the initial box at level 0 into a defined number of subboxes for the
* the first level.
* @param spws A pointer to the newly created event workspace.
* @param bc A pointer to the box controller.
*/
void ConvertToMD::performInitialSplitting(API::IMDEventWorkspace_sptr spws, Mantid::API::BoxController_sptr bc)
{
void ConvertToMD::performInitialSplitting(API::IMDEventWorkspace_sptr spws,
Mantid::API::BoxController_sptr bc) {
const size_t initialSplitSetting = 50;
const size_t dimCutoff = 4;

// Record the split settings of the box controller in a buffer and set the new value
// Record the split settings of the box controller in a buffer and set the new
// value
std::vector<size_t> splitBuffer;

for (size_t dim = 0; dim < bc->getNDims(); dim++)
{

for (size_t dim = 0; dim < bc->getNDims(); dim++) {
splitBuffer.push_back(bc->getSplitInto(dim));

// Replace the box controller setting only for a max of the first three dimensions
if (dim < dimCutoff)
{
bc->setSplitInto(dim, initialSplitSetting);
// Replace the box controller setting only for a max of the first three
// dimensions
if (dim < dimCutoff) {
bc->setSplitInto(dim, initialSplitSetting);
}
}

// Perform the initial splitting
spws->splitBox();

// Revert changes on the box controller
for (size_t dim = 0; dim < bc->getNDims(); ++dim)
{
for (size_t dim = 0; dim < bc->getNDims(); ++dim) {
bc->setSplitInto(dim, splitBuffer[dim]);
}
}
Expand Down
Expand Up @@ -138,7 +138,7 @@ class DLLExport MDBoxFlatTree {
static void loadExperimentInfos(
::NeXus::File *const file,
const std::string & filename,
boost::shared_ptr<API::MultipleExperimentInfos> ei,
boost::shared_ptr<API::MultipleExperimentInfos> mei,
bool lazy = false);

static void saveAffineTransformMatricies(::NeXus::File *const file,
Expand Down
10 changes: 0 additions & 10 deletions Code/Mantid/Framework/MDEvents/src/MDWSDescription.cpp
Expand Up @@ -156,16 +156,6 @@ MDWSDescription::buildFromMDWS(const API::IMDEventWorkspace_const_sptr &pWS) {
m_DimMax[i] = pDim->getMaximum();
}
m_Wtransf = Kernel::DblMatrix(pWS->getWTransf());
// deal with the case when source MD workspace does not have any experiment
// infos
if (pWS->getNumExperimentInfo() != 0) {
this->addProperty(
"W_MATRIX",
pWS->getExperimentInfo(0)
->run()
.getPropertyValueAsType<std::vector<double>>("W_MATRIX"),
true);
}
}
/** When the workspace has been build from existing MDWrokspace, some target
*workspace parameters can not be defined,
Expand Down
Expand Up @@ -39,7 +39,6 @@ class vtkDataSetToNonOrthogonalDataSetTest : public CxxTest::TestSuite
// information necessary for the non-orthogonal axes
std::string wsName = "simpleWS";
IMDEventWorkspace_sptr ws = makeAnyMDEW<MDEvent<4>, 4>(1, 0.0, 1.0, 1, wsName);

// Set the coordinate system
if (!wrongCoords)
{
Expand All @@ -51,9 +50,6 @@ class vtkDataSetToNonOrthogonalDataSetTest : public CxxTest::TestSuite
}

// Set the UB matrix
ExperimentInfo_sptr expInfo = ExperimentInfo_sptr(new ExperimentInfo());
ws->addExperimentInfo(expInfo);

if (!forgetUB)
{
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("SetUB");
Expand Down

0 comments on commit b642131

Please sign in to comment.