Skip to content
Snippets Groups Projects
Commit a8c9477e authored by Savici, Andrei T.'s avatar Savici, Andrei T. Committed by GitHub
Browse files

Merge pull request #17203 from mantidproject/LoadGSS_flexibility

Make LoadGSS more flexible
parents 281bd83b a012daa3
No related branches found
No related tags found
No related merge requests found
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
#include "MantidGeometry/Instrument/Component.h" #include "MantidGeometry/Instrument/Component.h"
#include "MantidKernel/UnitFactory.h" #include "MantidKernel/UnitFactory.h"
#include <boost/math/special_functions/fpclassify.hpp> #include <boost/regex.hpp>
#include <Poco/File.h>
#include <fstream> #include <fstream>
#include <Poco/File.h>
#include <sstream> #include <sstream>
#include <string>
using namespace Mantid::DataHandling; using namespace Mantid::DataHandling;
using namespace Mantid::API; using namespace Mantid::API;
...@@ -29,6 +29,13 @@ namespace DataHandling { ...@@ -29,6 +29,13 @@ namespace DataHandling {
DECLARE_FILELOADER_ALGORITHM(LoadGSS) DECLARE_FILELOADER_ALGORITHM(LoadGSS)
namespace { // anonymous namespace
const boost::regex DET_POS_REG_EXP{"^#.+flight path\\s+([0-9.]+).+"
"tth\\s+([0-9.]+).+"
"DIFC\\s+([0-9.]+)"};
const boost::regex L1_REG_EXP{"^#.+flight path\\s+([0-9.]+)\\s*m"};
} // end of anonymous namespace
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Return the confidence with with this algorithm can load the file /** Return the confidence with with this algorithm can load the file
* @param descriptor A descriptor for the file * @param descriptor A descriptor for the file
...@@ -187,33 +194,51 @@ API::MatrixWorkspace_sptr LoadGSS::loadGSASFile(const std::string &filename, ...@@ -187,33 +194,51 @@ API::MatrixWorkspace_sptr LoadGSS::loadGSASFile(const std::string &filename,
} }
} else if (key1 == "Primary") { } else if (key1 == "Primary") {
// Primary flight path ... // Primary flight path ...
std::string s1, s2; boost::smatch result;
inputLine >> s1 >> s2; if (boost::regex_search(inputLine.str(), result, L1_REG_EXP) &&
primaryflightpath = atof(s2.c_str()); // convertToDouble(s2); result.size() == 2) {
g_log.information() << "L1 = " << primaryflightpath << '\n'; primaryflightpath = std::stod(std::string(result[1]));
} else {
std::stringstream msg;
msg << "Failed to parse primary flight path from line \""
<< inputLine.str() << "\"";
g_log.warning(msg.str());
}
std::stringstream msg;
msg << "L1 = " << primaryflightpath;
g_log.information(msg.str());
} else if (key1 == "Total") { } else if (key1 == "Total") {
// Total flight path .... .... including total flying path, difc and // Total flight path .... .... including total flying path, difc and
// 2theta of 1 bank // 2theta of 1 bank
std::string s1, s2, s3, s4, s5, s6;
inputLine >> s1 >> s2 >> s3 >> s4 >> s5 >> s6; double totalpath(0.f);
#if 0 double tth(0.f);
double totalpath = convertToDouble(s2); double difc(0.f);
double tth = convertToDouble(s4);
double difc = convertToDouble(s6); boost::smatch result;
#else if (boost::regex_search(inputLine.str(), result, DET_POS_REG_EXP) &&
double totalpath = atof(s2.c_str()); result.size() == 4) {
double tth = atof(s4.c_str()); totalpath = std::stod(std::string(result[1]));
double difc = atof(s6.c_str()); tth = std::stod(std::string(result[2]));
#endif difc = std::stod(std::string(result[3]));
} else {
std::stringstream msg;
msg << "Failed to parse position from line \"" << inputLine.str()
<< "\"";
g_log.warning(msg.str());
}
totalflightpaths.push_back(totalpath); totalflightpaths.push_back(totalpath);
twothetas.push_back(tth); twothetas.push_back(tth);
difcs.push_back(difc); difcs.push_back(difc);
g_log.information() << "Bank " << difcs.size() - 1 std::stringstream msg;
<< ": Total flight path = " << totalpath msg << "Bank " << difcs.size() - 1
<< " 2Theta = " << tth << " DIFC = " << difc << ": Total flight path = " << totalpath << " 2Theta = " << tth
<< "\n"; << " DIFC = " << difc;
g_log.information(msg.str());
} // if keys.... } // if keys....
} // ENDIF for Line with # } // ENDIF for Line with #
...@@ -443,7 +468,7 @@ double LoadGSS::convertToDouble(std::string inputstring) { ...@@ -443,7 +468,7 @@ double LoadGSS::convertToDouble(std::string inputstring) {
} }
} }
double rd = atof(temps.c_str()); double rd = std::stod(temps);
return rd; return rd;
} }
......
...@@ -7,10 +7,12 @@ ...@@ -7,10 +7,12 @@
#include "MantidAPI/Axis.h" #include "MantidAPI/Axis.h"
#include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/MatrixWorkspace.h"
#include "MantidTestHelpers/ScopedFileHelper.h" #include "MantidTestHelpers/ScopedFileHelper.h"
#include "MantidGeometry/Instrument.h"
using namespace Mantid; using namespace Mantid;
using Mantid::DataHandling::LoadGSS; using Mantid::DataHandling::LoadGSS;
using ScopedFileHelper::ScopedFile; using ScopedFileHelper::ScopedFile;
using Mantid::Kernel::V3D;
class LoadGSSTest : public CxxTest::TestSuite { class LoadGSSTest : public CxxTest::TestSuite {
public: public:
...@@ -52,7 +54,16 @@ public: ...@@ -52,7 +54,16 @@ public:
" 115206.06310 1234567.00000003 0.00000000\n" " 115206.06310 1234567.00000003 0.00000000\n"
" 115209.92877 12345678.00000004 0.00000000\n" " 115209.92877 12345678.00000004 0.00000000\n"
" 115213.79731123456789.00000005 0.00000000\n" " 115213.79731123456789.00000005 0.00000000\n"
" 115217.66873234567890.00000006 0.00000000"; " 115217.66873234567890.00000006 0.00000000\n"
"\n"
"# Total flight path 42.060 m, tth 154.257 deg, DIFC 10398.8\n"
"# Data for spectrum :1\n"
"BANK 2 4399 4399 RALF 166409 124 166409 0.00074 FXYE\n"
" 115202.20029 1.00000000 0.00000000\n"
" 115206.06310 1.00000000 0.00000000\n"
" 115209.92877 2.00000000 0.00000000\n"
" 115213.79731 3.00000000 0.00000000\n"
" 115217.66873 5.00000000 0.00000000\n";
ScopedFile file(gss, "gss_large_x.txt"); ScopedFile file(gss, "gss_large_x.txt");
API::IAlgorithm_sptr loader = createAlgorithm(); API::IAlgorithm_sptr loader = createAlgorithm();
loader->setPropertyValue("Filename", file.getFileName()); loader->setPropertyValue("Filename", file.getFileName());
...@@ -69,6 +80,21 @@ public: ...@@ -69,6 +80,21 @@ public:
dx = x2 - x1; dx = x2 - x1;
y = ws->readY(0)[3] * dx; y = ws->readY(0)[3] * dx;
TS_ASSERT_DELTA(y, 123456789.00000005, 1e-10); TS_ASSERT_DELTA(y, 123456789.00000005, 1e-10);
const auto source = ws->getInstrument()->getSource();
const auto sample = ws->getInstrument()->getSample();
TS_ASSERT_DELTA(sample->getDistance(*source), 40., 1e-4);
const auto det0 = ws->getDetector(0);
TS_ASSERT_DELTA(det0->getDistance(*sample), 2.2222, 1e-4);
TS_ASSERT_DELTA(det0->getTwoTheta(V3D(0.0, 0.0, 0.0), V3D(0.0, 0.0, 1.0)) *
180. / M_PI,
58.308, 1e-4);
const auto det1 = ws->getDetector(1);
TS_ASSERT_DELTA(det1->getDistance(*sample), 2.060, 1e-4);
TS_ASSERT_DELTA(det1->getTwoTheta(V3D(0.0, 0.0, 0.0), V3D(0.0, 0.0, 1.0)) *
180. / M_PI,
154.257, 1e-4);
} }
void test_load_gss_ExtendedHeader_gsa() { void test_load_gss_ExtendedHeader_gsa() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment