Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Framework/DataHandling/inc/MantidDataHandling/LoadSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidDataHandling/DllConfig.h"
#include "MantidHistogramData/Histogram.h"
#include "MantidKernel/FileDescriptor.h"

namespace Mantid {
namespace DataHandling {
Expand All @@ -31,7 +32,7 @@ data.</li>
@author Roman Tolchenov, Tessella plc
@date 3/07/09
*/
class MANTID_DATAHANDLING_DLL LoadSpec final : public API::Algorithm {
class MANTID_DATAHANDLING_DLL LoadSpec : public API::IFileLoader<Kernel::FileDescriptor> {
public:
LoadSpec();
const std::string name() const override { return "LoadSpec"; }
Expand All @@ -44,6 +45,9 @@ class MANTID_DATAHANDLING_DLL LoadSpec final : public API::Algorithm {
int version() const override { return 1; }
const std::string category() const override { return "DataHandling\\Text"; }

/// Returns a confidence value that this algorithm can load a file
int confidence(Kernel::FileDescriptor &descriptor) const override;

private:
void init() override;
void exec() override;
Expand Down
56 changes: 55 additions & 1 deletion Framework/DataHandling/src/LoadSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// Includes
//----------------------------------------------------------------------
#include "MantidDataHandling/LoadSpec.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/Axis.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ListValidator.h"
Expand All @@ -22,14 +24,66 @@

namespace Mantid::DataHandling {
// Register the algorithm into the algorithm factory
DECLARE_ALGORITHM(LoadSpec)
DECLARE_FILELOADER_ALGORITHM(LoadSpec)

using namespace Kernel;
using namespace API;

/// Empty constructor
LoadSpec::LoadSpec() = default;

/**
* Return the confidence with with this algorithm can load the file
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not
* be used
*/
int LoadSpec::confidence(Kernel::FileDescriptor &descriptor) const {
if (!descriptor.isAscii())
return 0;

auto &file = descriptor.data();

int confidence(0);
size_t axiscols(0), datacols(0);
std::string str;
using tokenizer = Mantid::Kernel::StringTokenizer;
const std::string sep = " ";
bool snsspec(false);

while (std::getline(file, str)) {
// File is opened in binary mode so getline will leave a \r at the end of an
// empty line if it exists
if (str.empty() || str == "\r")
continue;

try {
// if it's comment line
tokenizer tok(str, sep, Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY);
if (str.at(0) == '#') {
if (str.at(1) == 'L') {
axiscols = tok.count();
// if the file contains a comment line starting with "#L" followed
// by three columns this could be loadsnsspec file
if (axiscols > 2) {
snsspec = true;
}
}
} else {
// check first data line is a 3 column line
datacols = tok.count();
break;
}
} catch (std::out_of_range &) {
}
}
if (snsspec && datacols == 3) // three column data
{
confidence = 80;
}
return confidence;
}

/// Initialisation method.
void LoadSpec::init() {
const std::vector<std::string> exts{".dat", ".txt"};
Expand Down
1 change: 0 additions & 1 deletion Testing/SystemTests/tests/framework/LoadLotsOfFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"batch_input.csv",
"mar11015.msk",
"LET_hard.msk", # It seems loade does not understand it?
"LoadSNSspec.txt", # LoadSpec is not registered as a file loader
"MASK.094AA",
"MASKSANS2D_094i_RKH.txt",
"MASKSANS2D.091A",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- :ref:`LoadSpec <algm-LoadSpec>` has been updated to be declared as a file loader
16 changes: 16 additions & 0 deletions docs/source/release/v6.13.0/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ Removed
.. amalgamate:: Framework/Fit_Functions/Removed


Data Handling
-------------

New features
############
.. amalgamate:: Framework/Data_Handling/New_features

Deprecated
############
.. amalgamate:: Framework/Data_Handling/Deprecated

Removed
############
.. amalgamate:: Framework/Data_Handling/Removed


Data Objects
------------

Expand Down