Skip to content

Commit

Permalink
Refs #4024 working on nexus bug
Browse files Browse the repository at this point in the history
got it narrowed down to SaveMD(MakeFileBacked=1)
  • Loading branch information
Janik Zikovsky committed Nov 16, 2011
1 parent 05dba3d commit f5ae305
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 22 deletions.
9 changes: 9 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace MDEvents


/** Set whether the box is cached on disk (true) or in memory (false)
* DON'T CALL THIS DIRECTLY UNLESS YOU KNOW WHAT YOU ARE DOING!
* @param onDisk :: true if it is on disk */
void setOnDisk(const bool onDisk)
{ m_onDisk = onDisk; }
Expand All @@ -120,6 +121,7 @@ namespace MDEvents
{ return m_inMemory; }

/** Set whether the box data (from disk) is loaded in memory (for SaveMD with MakeFileBacked).
* DON'T CALL THIS DIRECTLY UNLESS YOU KNOW WHAT YOU ARE DOING!
* @param inMem :: true if it is in memory */
void setInMemory(const bool inMem)
{ m_inMemory = inMem; }
Expand All @@ -137,6 +139,7 @@ namespace MDEvents
{ return m_dataModified; }

/** Set the dataModified flag.
* DON'T CALL THIS DIRECTLY UNLESS YOU KNOW WHAT YOU ARE DOING!
* @param value :: true if the data was modified in some way. */
void setDataModified(const bool value)
{ m_dataModified = value; }
Expand All @@ -145,6 +148,12 @@ namespace MDEvents
bool dataAdded() const
{ return m_dataAdded; }

/** Set the dataAdded flag.
* DON'T CALL THIS DIRECTLY UNLESS YOU KNOW WHAT YOU ARE DOING!
* @param value :: true if data was added in some way. */
void setDataAdded(const bool value)
{ m_dataAdded = value; }


std::vector< MDE > & getEvents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "MantidGeometry/MDGeometry/MDTypes.h"
#include <numeric>
#include <cmath>
#include <iostream>

namespace Mantid
{
Expand Down Expand Up @@ -242,8 +243,9 @@ namespace MDEvents
dims[1] = (nd)+2; // One point per dimension, plus signal, plus error = nd+2

// Now the chunk size.
std::vector<int64_t> chunk(dims);
std::vector<int64_t> chunk(2, 0);
chunk[0] = int64_t(chunkSize);
chunk[1] = (nd)+2;

// Make and open the data
file->makeCompData("event_data", ::NeXus::FLOAT64, dims, ::NeXus::NONE, chunk, true);
Expand All @@ -264,7 +266,8 @@ namespace MDEvents
// Open the data
file->openData("event_data");
// Return the size of dimension 0 = the number of events in the field
return uint64_t(file->getInfo().dims[0]);
uint64_t currentSize = uint64_t(file->getInfo().dims[0]);
return currentSize;
}

//---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -297,10 +300,12 @@ namespace MDEvents
signal_t & totalSignal, signal_t & totalErrorSquared)
{
size_t numEvents = events.size();
//std::cout << "Saving " << numEvents << " at " << startIndex << " in file " << uint64_t(file) << std::endl;
std::vector<double> data;
data.reserve(numEvents*(nd+2));
std::vector<int64_t> start(2,0);
start[0] = int64_t(startIndex);
start[1] = 0;

totalSignal = 0;
totalErrorSquared = 0;
Expand Down
12 changes: 9 additions & 3 deletions Code/Mantid/Framework/MDEvents/src/SaveMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,17 @@ namespace MDEvents
{
if (update)
{
// File-backed: update where on the file it is
// File-backed: re-save any boxes THAT WERE MODIFED
// This will relocate and save the box if it has any events
mdbox->save();
// We've now forced it to go on disk
mdbox->setOnDisk(true);
// Save the index
box_event_index[id*2] = mdbox->getFileIndexStart();
box_event_index[id*2+1] = mdbox->getFileNumEvents();
std::cout << file->getInfo().dims[0] << " size of event_data (updating) \n";
// file->closeData();
// file->openData("event_data");
//std::cout << file->getInfo().dims[0] << " size of event_data (updating) \n";
}
else
{
Expand All @@ -284,6 +286,8 @@ namespace MDEvents
// Save, set that it is on disk and clear the actual events to free up memory
mdbox->setOnDisk(true);
mdbox->clearDataOnly();
// mdbox->setDataAdded(false);
// mdbox->setDataModified(false);
}
// Save the index
box_event_index[id*2] = start;
Expand All @@ -292,7 +296,7 @@ namespace MDEvents
start += numEvents;
}

std::cout << file->getInfo().dims[0] << " size of event_data (writing) \n";
//std::cout << file->getInfo().dims[0] << " size of event_data (writing) \n";
mdbox->releaseEvents();
}
}
Expand Down Expand Up @@ -397,6 +401,7 @@ namespace MDEvents

if (update || MakeFileBacked)
{
//std::cout << "Finished updating file " << uint64_t(bc->getFile()) << std::endl;
// Need to keep the file open since it is still used as a back end.
// Reopen the file
filename = bc->getFilename();
Expand All @@ -405,6 +410,7 @@ namespace MDEvents
file->openGroup("MDEventWorkspace", "NXentry");
file->openGroup("event_data", "NXdata");
uint64_t totalNumEvents = MDE::openNexusData(file);
std::cout << totalNumEvents << " events in reopened file \n";
bc->setFile(file, filename, totalNumEvents);
// Mark file is up-to-date
ws->setFileNeedsUpdating(false);
Expand Down
37 changes: 26 additions & 11 deletions Code/Mantid/Framework/MDEvents/test/LoadMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class LoadMDTest : public CxxTest::TestSuite
}
}



//=================================================================================================================
/** Compare two MDEventWorkspaces
*
* @param ws :: workspace to check
Expand Down Expand Up @@ -86,7 +89,7 @@ class LoadMDTest : public CxxTest::TestSuite
IMDBox<MDE,nd>* box1 = boxes[j];
IMDBox<MDE,nd>* box2 = boxes1[j];

// std::cout << "ID: " << box1->getId() << std::endl;
std::cout << "ID: " << box1->getId() << std::endl;
TS_ASSERT_EQUALS( box1->getId(), box2->getId() );
TS_ASSERT_EQUALS( box1->getDepth(), box2->getDepth() );
TS_ASSERT_EQUALS( box1->getNumChildren(), box2->getNumChildren() );
Expand Down Expand Up @@ -165,6 +168,7 @@ class LoadMDTest : public CxxTest::TestSuite



//=================================================================================================================
template <size_t nd>
void do_test_exec(bool FileBackEnd, bool deleteWorkspace=true, double memory=0, bool BoxStructureOnly = false)
{
Expand Down Expand Up @@ -280,6 +284,8 @@ class LoadMDTest : public CxxTest::TestSuite
}



//=================================================================================================================
/** Follow up test that:
* - Modifies the data in a couple of ways
* - Saves AGAIN to update a file back end
Expand All @@ -304,25 +310,29 @@ class LoadMDTest : public CxxTest::TestSuite
iws->addExperimentInfo(ei);

// Add one event using addEvent(). The event will need to be written out to disk too.
MDLeanEvent<nd> ev(1.0, 2.3);
MDLeanEvent<nd> ev(1.0, 1.0);
for (size_t d=0; d<nd; d++) ev.setCenter(d, 0.5);
box->addEvent(ev);

// Modify a different box by accessing the events
MDBox<MDLeanEvent<nd>,nd> * box8 = dynamic_cast<MDBox<MDLeanEvent<nd>,nd>*>(box->getChild(8));
std::vector<MDLeanEvent<nd> > & events = box8->getEvents();
events[0].setSignal(10.0);

// Modify a third box by accessing the events AND adding an event
MDBox<MDLeanEvent<nd>,nd> * box17 = dynamic_cast<MDBox<MDLeanEvent<nd>,nd>*>(box->getChild(17));
std::vector<MDLeanEvent<nd> > & events17 = box17->getEvents();
box->addEvent( events17[0] ); // Copy the event so that it ends up in the same box
events17[0].setSignal(100.0);
// Add 10 to this signal
signal_t newSignal = events[0].getSignal() + 10.0;
events[0].setSignal(newSignal);
box8->releaseEvents();

// // Modify a third box by adding an event
// MDBox<MDLeanEvent<nd>,nd> * box17 = dynamic_cast<MDBox<MDLeanEvent<nd>,nd>*>(box->getChild(17));
// std::vector<MDLeanEvent<nd> > & events17 = box17->getEvents();
// MDLeanEvent<nd> ev_new(1.0, 1.0);
// box->addEvent( ev_new );
// box17->releaseEvents();

ws2->refreshCache();

// There are now 2 more events
TS_ASSERT_EQUALS( ws2->getNPoints(), 10002 );
TS_ASSERT_EQUALS( ws2->getNPoints(), 10001 );

// There are some new boxes that are not cached to disk at this point.
// Save it again.
Expand All @@ -337,7 +347,7 @@ class LoadMDTest : public CxxTest::TestSuite

// Now we look at the file that's currently open
::NeXus::File * file = ws2->getBoxController()->getFile();
TSM_ASSERT_LESS_THAN( "The event_data field in the file must be at least 10002 long.", 10002, file->getInfo().dims[0] );
TSM_ASSERT_LESS_THAN( "The event_data field in the file must be at least 10001 long.", 10001, file->getInfo().dims[0] );


// The file should have been modified but that's tricky to check directly.
Expand Down Expand Up @@ -366,6 +376,8 @@ class LoadMDTest : public CxxTest::TestSuite
}


//=================================================================================================================

/// Load directly to memory
void test_exec_1D()
{
Expand Down Expand Up @@ -417,6 +429,9 @@ class LoadMDTest : public CxxTest::TestSuite




//=================================================================================================================

void testMetaDataOnly()
{
//------ Start by creating the file ----------------------------------------------
Expand Down

0 comments on commit f5ae305

Please sign in to comment.