Skip to content

Commit

Permalink
Refs #3866 : fix for log names with spaces in them failing with this …
Browse files Browse the repository at this point in the history
…version of nexus
  • Loading branch information
Janik Zikovsky committed Nov 4, 2011
1 parent b84e2a4 commit 0a0227f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
25 changes: 21 additions & 4 deletions Code/Mantid/Framework/API/src/PropertyNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ namespace PropertyNexus
template <typename NumT>
void savePropertyWithValue(::NeXus::File * file, PropertyWithValue<NumT> * prop)
{
file->makeGroup(prop->name(), "NXlog", 1);
// Spaces are unacceptable in names - remove them
std::string name(prop->name());
for (size_t i=0; i<name.size(); i++)
if (name[i] == ' ') name[i] = '_';
file->makeGroup(name, "NXlog", 1);
file->writeData("value", (*prop)() );
file->closeGroup();
}
Expand All @@ -173,7 +177,11 @@ namespace PropertyNexus
/** Helper function to save a PropertyWithValue<> */
void savePropertyWithValueString(::NeXus::File * file, PropertyWithValue<std::string> * prop)
{
file->makeGroup(prop->name(), "NXlog", 1);
// Spaces are unacceptable in names - remove them
std::string name(prop->name());
for (size_t i=0; i<name.size(); i++)
if (name[i] == ' ') name[i] = '_';
file->makeGroup(name, "NXlog", 1);
file->writeData("value", prop->value() );
file->closeGroup();
}
Expand Down Expand Up @@ -202,7 +210,11 @@ namespace PropertyNexus
{
std::vector<NumT> value = prop->valuesAsVector();
if( value.empty() ) return;
file->makeGroup(prop->name(), "NXlog", 1);
// Spaces are unacceptable in names - remove them
std::string name(prop->name());
for (size_t i=0; i<name.size(); i++)
if (name[i] == ' ') name[i] = '_';
file->makeGroup(name, "NXlog", 1);
file->writeData("value", value );
saveTimeVector(file, prop);
file->closeGroup();
Expand All @@ -214,7 +226,12 @@ namespace PropertyNexus
{
std::vector<std::string> values = prop->valuesAsVector();
if( values.empty() ) return;
file->makeGroup(prop->name(), "NXlog", 1);

// Spaces are unacceptable in names - remove them
std::string name(prop->name());
for (size_t i=0; i<name.size(); i++)
if (name[i] == ' ') name[i] = '_';
file->makeGroup(name, "NXlog", 1);

// Find the max length of any string
size_t maxlen=0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Mantid
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling";}

private:
protected:
/// Sets documentation strings for this algorithm
virtual void initDocs();
/// Overwrites Algorithm method.
Expand Down
15 changes: 12 additions & 3 deletions Code/Mantid/Framework/DataHandling/test/SaveNexusProcessedTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,16 @@ class SaveNexusProcessedTest : public CxxTest::TestSuite

}

class SaveNexusProcessedExposed: public SaveNexusProcessed
{
public:
void exec()
{ SaveNexusProcessed::exec(); }
};

void testExecOnMuon()
{
SaveNexusProcessed algToBeTested;
SaveNexusProcessedExposed algToBeTested;

LoadNexus nxLoad;
std::string outputSpace,inputFile;
Expand All @@ -199,6 +205,9 @@ class SaveNexusProcessedTest : public CxxTest::TestSuite
// this would make all X's separate
// output2D->dataX(22)[3]=0.55;
//

// output2D->mutableRun().removeLogData("ISIS beam");

if ( !algToBeTested.isInitialized() ) algToBeTested.initialize();

algToBeTested.setPropertyValue("InputWorkspace", outputSpace);
Expand All @@ -222,15 +231,15 @@ class SaveNexusProcessedTest : public CxxTest::TestSuite
//TS_ASSERT_THROWS_NOTHING( result = algToBeTested.getPropertyValue("EntryName") );
//TS_ASSERT( ! result.compare(entryName));

TS_ASSERT_THROWS_NOTHING(algToBeTested.execute());
algToBeTested.execute();
TS_ASSERT( algToBeTested.isExecuted() );

// Nice idea, but confusing (seg-faulted) if algorithm doesn't clean its state
// In reality out algorithms are only call once
// // try writing data again
// TS_ASSERT_THROWS_NOTHING(algToBeTested.execute());
// TS_ASSERT( algToBeTested.isExecuted() );
if(clearfiles) Poco::File(outputFile).remove();
// if(clearfiles) Poco::File(outputFile).remove();
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().remove(outputSpace));
}

Expand Down

0 comments on commit 0a0227f

Please sign in to comment.