Skip to content

Commit

Permalink
Modified loadLog tests, and commented loadLog.h. Refs #3189.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Jul 18, 2013
1 parent dec330f commit 6e3c629
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace Mantid
/// Takes as input a string and try to determine what type it is
kind classify(const std::string& s) const;

/// convert string to lower case
/// Convert string to lower case
std::string stringToLower(std::string strToConvert);

/// Checks if the file is an ASCII file
Expand All @@ -119,12 +119,13 @@ namespace Mantid
/// Check for SNS-style text file
bool SNSTextFormatColumns(const std::string& str, std::vector<double> & out) const;

/// create timeseries property from .log file and adds taht to sample object
/// Create timeseries property from .log file and adds that to sample object
std::set<std::string> createthreecolumnFileLogProperty(const std::string& logfile, API::Run& run);

/// if a file with the second column(block column) name in .log file exists in the raw file directory
/// If a file with the second column(block column) name in .log file exists in the raw file directory
bool blockcolumnFileExists(const std::string& fileName);

/// Loads two column log file data into local workspace
void loadTwoColumnLogFile(std::string names);

/// TimeSeriesProperty<int> containing data periods. Created by LogParser
Expand Down
270 changes: 27 additions & 243 deletions Code/Mantid/Framework/DataHandling/test/LoadLogTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class LoadLogTest : public CxxTest::TestSuite
{
public:


static LoadLogTest *createSuite() { return new LoadLogTest(); }
static void destroySuite(LoadLogTest *suite) { delete suite; }

Expand All @@ -34,27 +33,26 @@ class LoadLogTest : public CxxTest::TestSuite
//initialise framework manager to allow logging
//Mantid::API::FrameworkManager::Instance().initialize();
}

void testInit()
{
TS_ASSERT( !loader.isInitialized() );
TS_ASSERT_THROWS_NOTHING(loader.initialize());
TS_ASSERT( loader.isInitialized() );
}

void testExecWithSingleLogFile()
void testThreeColumnLogFile()
{
if ( !loader.isInitialized() ) loader.initialize();

// Path to test input file assumes Test directory checked out from SVN
TS_ASSERT_THROWS_NOTHING(loader.setPropertyValue("Filename", "HRP37129_ICPevent.txt") )
TS_ASSERT_THROWS_NOTHING(loader.setPropertyValue("Filename", "NIMROD00001097.log") )
inputFile = loader.getPropertyValue("Filename");

outputSpace = "LoadLogTest-singleLogFile";
outputSpace = "LoadLogTest-threeColumnFile";
TS_ASSERT_THROWS(loader.setPropertyValue("Workspace", outputSpace), std::invalid_argument)
// Create an empty workspace and put it in the AnalysisDataService

Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);

TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(outputSpace, ws));
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(outputSpace, ws));

std::string result;
TS_ASSERT_THROWS_NOTHING( result = loader.getPropertyValue("Filename") )
Expand All @@ -65,279 +63,66 @@ class LoadLogTest : public CxxTest::TestSuite

TS_ASSERT_THROWS_NOTHING(loader.execute());


TS_ASSERT( loader.isExecuted() );
TS_ASSERT( loader.isExecuted() );

// Get back the saved workspace
MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputSpace));

// boost::shared_ptr<Sample> sample = output->getSample();

Property *l_property = output->run().getLogData("HRP37129_ICPevent");
TimeSeriesProperty<std::string> *l_timeSeries = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property);

std::string timeSeriesString = l_timeSeries->value();

//std::cerr<<timeSeriesString<<'\n';

// test that log file read in ok
TS_ASSERT_EQUALS( timeSeriesString.substr(0,26), "2007-Nov-16 13:25:48 END" );

AnalysisDataService::Instance().remove(outputSpace);
}


void testExecWithRawDatafile()
{
FrameworkManager::Instance();
//if ( !loader.isInitialized() ) loader.initialize();

LoadLog loaderRawFile;
loaderRawFile.initialize();

// Path to test input file assumes Test directory checked out from SVN
loaderRawFile.setPropertyValue("Filename", "HRP37125.raw");
inputFile = loaderRawFile.getPropertyValue("Filename");

outputSpace = "LoadLogTestraw-datafile";
// Create an empty workspace and put it in the AnalysisDataService
Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);

TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(outputSpace, ws));
loaderRawFile.setPropertyValue("Workspace", outputSpace);

std::string result;
TS_ASSERT_THROWS_NOTHING( result = loaderRawFile.getPropertyValue("Filename") )
TS_ASSERT( ! result.compare(inputFile));

TS_ASSERT_THROWS_NOTHING( result = loaderRawFile.getPropertyValue("Workspace") )

TS_ASSERT( ! result.compare(outputSpace));


TS_ASSERT_THROWS_NOTHING(loaderRawFile.execute());

TS_ASSERT( loaderRawFile.isExecuted() );

// Get back the saved workspace
MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputSpace));

//boost::shared_ptr<Sample> sample = output->getSample();

// obtain the expected log files which should be in the same directory as the raw datafile

Property *l_property = output->run().getLogData( std::string("ICPevent") );
TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property);
std::string timeSeriesString = l_timeSeriesString->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,28), "2007-Nov-13 15:19:13 BEGIN" );

l_property = output->run().getLogData( std::string("cphs_6") );
// This value is at the start of the log file.
Property *l_property = output->run().getLogData( std::string("BeamCurrent") );
TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property);
timeSeriesString = l_timeSeriesDouble->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" );

l_property = output->run().getLogData( std::string("PROP3") );
l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property);
timeSeriesString = l_timeSeriesDouble->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" );

l_property = output->run().getLogData( std::string("SE_He_Level") );
l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property);
timeSeriesString = l_timeSeriesDouble->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,24), "2007-Nov-13 15:17:08 -1" );

l_property = output->run().getLogData( std::string("TEMP1") );
std::string timeSeriesString = l_timeSeriesDouble->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,20), "2009-Nov-10 10:14:03" );
// While this value is at the end.
l_property = output->run().getLogData( std::string("J6CX") );
l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property);
timeSeriesString = l_timeSeriesDouble->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" );

AnalysisDataService::Instance().remove(outputSpace);
}


// Same idea as testExecWithRawDataFile() but testing on a raw file with the extension .s#
// where # is some integer ranging from 01,02,...,99 I believe
void testExecWithRawDatafile_s_type()
{
//if ( !loader.isInitialized() ) loader.initialize();

LoadLog loaderRawFile;
loaderRawFile.initialize();

// Path to test input file assumes Test directory checked out from SVN
TS_ASSERT_THROWS_NOTHING( loaderRawFile.setPropertyValue("Filename", "CSP74683.s02") )
inputFile = loaderRawFile.getPropertyValue("Filename");

outputSpace = "LoadLogTest-rawdatafile_so_type";
TS_ASSERT_THROWS( loaderRawFile.setPropertyValue("Workspace", outputSpace), std::invalid_argument)
// Create an empty workspace and put it in the AnalysisDataService
Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);

TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(outputSpace, ws));

std::string result;
TS_ASSERT_THROWS_NOTHING( result = loaderRawFile.getPropertyValue("Filename") )
TS_ASSERT( ! result.compare(inputFile));

TS_ASSERT_THROWS_NOTHING( result = loaderRawFile.getPropertyValue("Workspace") )
TS_ASSERT( ! result.compare(outputSpace));


TS_ASSERT_THROWS_NOTHING(loaderRawFile.execute());

TS_ASSERT( loaderRawFile.isExecuted() );

// Get back the saved workspace
MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputSpace));

// boost::shared_ptr<Sample> sample = output->getSample();

// obtain the expected log files which should be in the same directory as the raw datafile

Property *l_property = output->run().getLogData( std::string("ICPevent") );
TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property);
std::string timeSeriesString = l_timeSeriesString->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,26), "2007-Oct-02 17:16:04 END" );

AnalysisDataService::Instance().remove(outputSpace);
}

void testExecWiththreecolumnLogfile()
{
FrameworkManager::Instance();
//if ( !loader.isInitialized() ) loader.initialize();

LoadLog loaderRawFile;
loaderRawFile.initialize();

// Path to test input file assumes Test directory checked out from SVN
loaderRawFile.setPropertyValue("Filename", "NIMROD00001097.raw");
inputFile = loaderRawFile.getPropertyValue("Filename");

outputSpace = "threecoulmlog_datafile";
// Create an empty workspace and put it in the AnalysisDataService
Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);

TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(outputSpace, ws));
loaderRawFile.setPropertyValue("Workspace", outputSpace);

std::string result;
TS_ASSERT_THROWS_NOTHING( result = loaderRawFile.getPropertyValue("Filename") )
TS_ASSERT( ! result.compare(inputFile));

TS_ASSERT_THROWS_NOTHING( result = loaderRawFile.getPropertyValue("Workspace") )

TS_ASSERT( ! result.compare(outputSpace));


TS_ASSERT_THROWS_NOTHING(loaderRawFile.execute());

TS_ASSERT( loaderRawFile.isExecuted() );

// Get back the saved workspace
MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputSpace));

//boost::shared_ptr<Sample> sample = output->getSample();

// obtain the expected log files which should be in the same directory as the raw datafile

Property *l_property = output->run().getLogData( std::string("ICPevent") );
TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property);
std::string timeSeriesString = l_timeSeriesString->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,36), "2009-Nov-10 17:22:13 CHANGE_PERIOD" );

l_property =output->run().getLogData( std::string("J6CX") );
TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property);
timeSeriesString = l_timeSeriesDouble->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,20), "2009-Nov-10 17:22:14" );

l_property = output->run().getLogData( std::string("BeamCurrent") );
l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property);
timeSeriesString = l_timeSeriesDouble->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,20), "2009-Nov-10 10:14:03" );

AnalysisDataService::Instance().remove(outputSpace);


}

void test_withAlternateDatastream()
void testTwoColumnLogFile()
{
FrameworkManager::Instance();
//if ( !loader.isInitialized() ) loader.initialize();

LoadLog loaderRawFile;
loaderRawFile.initialize();
if ( !loader.isInitialized() ) loader.initialize();

// Path to test input file assumes Test directory checked out from SVN
loaderRawFile.setPropertyValue("Filename", "OFFSPEC00004622.raw");
inputFile = loaderRawFile.getPropertyValue("Filename");
TS_ASSERT_THROWS_NOTHING(loader.setPropertyValue("Filename", "HRP37129_ICPevent.txt") )
inputFile = loader.getPropertyValue("Filename");

outputSpace = "ads_datafile";
outputSpace = "LoadLogTest-singleLogFile";
TS_ASSERT_THROWS(loader.setPropertyValue("Workspace", outputSpace), std::invalid_argument)
// Create an empty workspace and put it in the AnalysisDataService
Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);

TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(outputSpace, ws));
loaderRawFile.setPropertyValue("Workspace", outputSpace);

std::string result;
TS_ASSERT_THROWS_NOTHING( result = loaderRawFile.getPropertyValue("Filename") )
TS_ASSERT_THROWS_NOTHING( result = loader.getPropertyValue("Filename") )
TS_ASSERT( ! result.compare(inputFile));

TS_ASSERT_THROWS_NOTHING( result = loaderRawFile.getPropertyValue("Workspace") )

TS_ASSERT_THROWS_NOTHING( result = loader.getPropertyValue("Workspace") )
TS_ASSERT( ! result.compare(outputSpace));

TS_ASSERT_THROWS_NOTHING(loader.execute());

TS_ASSERT_THROWS_NOTHING(loaderRawFile.execute());

TS_ASSERT( loaderRawFile.isExecuted() );
TS_ASSERT( loader.isExecuted() );

// Get back the saved workspace
MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputSpace));

// boost::shared_ptr<Sample> sample = output->getSample();

// obtain the expected log files which should be in the same directory as the raw datafile

Property *l_property = output->run().getLogData( std::string("ICPevent") );
TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property);
std::string timeSeriesString = l_timeSeriesString->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,36), "2009-Nov-11 11:25:57 CHANGE_PERIOD" );

Property* string_property = output->run().getLogData( std::string("RF1Ampon") );
TimeSeriesProperty<std::string> *l_timeSeriesString1 = dynamic_cast<TimeSeriesProperty<std::string>*>(string_property);
std::map<DateAndTime, std::string> vmap=l_timeSeriesString1->valueAsMap();
std::map<DateAndTime, std::string>::const_iterator itr;
for(itr=vmap.begin();itr!=vmap.end();++itr)
{TS_ASSERT_EQUALS( itr->second, "False" );
}

string_property = output->run().getLogData( std::string("ShutterStatus") );
l_timeSeriesString1 = dynamic_cast<TimeSeriesProperty<std::string>*>(string_property);
std::map<DateAndTime, std::string> vmap1=l_timeSeriesString1->valueAsMap();
for(itr=vmap1.begin();itr!=vmap1.end();++itr)
{TS_ASSERT_EQUALS( itr->second, "OPEN" );
}

Property* double_property = output->run().getLogData( std::string("b2v2") );
TimeSeriesProperty<double> *l_timeSeriesDouble1 = dynamic_cast<TimeSeriesProperty<double>*>(double_property);
std::map<DateAndTime,double> vmapb2v2=l_timeSeriesDouble1->valueAsMap();
std::map<DateAndTime,double>::const_iterator vmapb2v2itr;
for(vmapb2v2itr=vmapb2v2.begin();vmapb2v2itr!=vmapb2v2.end();++vmapb2v2itr)
{TS_ASSERT_EQUALS( vmapb2v2itr->second, -0.004 );}
Property *l_property = output->run().getLogData("HRP37129_ICPevent");
TimeSeriesProperty<std::string> *l_timeSeries = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property);
std::string timeSeriesString = l_timeSeries->value();
TS_ASSERT_EQUALS( timeSeriesString.substr(0,26), "2007-Nov-16 13:25:48 END" );

AnalysisDataService::Instance().remove(outputSpace);


}


void do_test_SNSTextFile(std::string names, std::string units, bool willFail, bool createWorkspace = true,
std::string expectedLastUnit = "Furlongs")
{
Expand Down Expand Up @@ -454,7 +239,6 @@ class LoadLogTest : public CxxTest::TestSuite
do_test_SNSTextFile("Temp1,Temp2,Temp3,Extra", "C,K,F,Fortnights", false, false, "Fortnights");
}


private:
LoadLog loader;
std::string inputFile;
Expand Down

0 comments on commit 6e3c629

Please sign in to comment.