Skip to content

Commit 31ee1f1

Browse files
committed
Updated LoadSpec to be a file loader (#39243)
Made changes to make LoadSpec a file loader, removed file from banned list since LoadSpec is now a file loader
1 parent ad419c8 commit 31ee1f1

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

Framework/DataHandling/inc/MantidDataHandling/LoadSpec.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
//----------------------------------------------------------------------
1010
// Includes
1111
//----------------------------------------------------------------------
12-
#include "MantidAPI/Algorithm.h"
12+
#include "MantidAPI/IFileLoader.h"
1313
#include "MantidDataHandling/DllConfig.h"
1414
#include "MantidHistogramData/Histogram.h"
15+
#include "MantidKernel/FileDescriptor.h"
1516

1617
namespace Mantid {
1718
namespace DataHandling {
@@ -31,7 +32,7 @@ data.</li>
3132
@author Roman Tolchenov, Tessella plc
3233
@date 3/07/09
3334
*/
34-
class MANTID_DATAHANDLING_DLL LoadSpec final : public API::Algorithm {
35+
class MANTID_DATAHANDLING_DLL LoadSpec : public API::IFileLoader<Kernel::FileDescriptor> {
3536
public:
3637
LoadSpec();
3738
const std::string name() const override { return "LoadSpec"; }
@@ -44,6 +45,9 @@ class MANTID_DATAHANDLING_DLL LoadSpec final : public API::Algorithm {
4445
int version() const override { return 1; }
4546
const std::string category() const override { return "DataHandling\\Text"; }
4647

48+
/// Returns a confidence value that this algorithm can load a file
49+
int confidence(Kernel::FileDescriptor &descriptor) const override;
50+
4751
private:
4852
void init() override;
4953
void exec() override;

Framework/DataHandling/src/LoadSpec.cpp

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// Includes
99
//----------------------------------------------------------------------
1010
#include "MantidDataHandling/LoadSpec.h"
11+
#include "MantidAPI/Algorithm.h"
1112
#include "MantidAPI/Axis.h"
1213
#include "MantidAPI/FileProperty.h"
14+
#include "MantidAPI/RegisterFileLoader.h"
1315
#include "MantidAPI/WorkspaceFactory.h"
1416
#include "MantidDataObjects/Workspace2D.h"
1517
#include "MantidKernel/ListValidator.h"
@@ -22,14 +24,66 @@
2224

2325
namespace Mantid::DataHandling {
2426
// Register the algorithm into the algorithm factory
25-
DECLARE_ALGORITHM(LoadSpec)
27+
DECLARE_FILELOADER_ALGORITHM(LoadSpec)
2628

2729
using namespace Kernel;
2830
using namespace API;
2931

3032
/// Empty constructor
3133
LoadSpec::LoadSpec() = default;
3234

35+
/**
36+
* Return the confidence with with this algorithm can load the file
37+
* @param descriptor A descriptor for the file
38+
* @returns An integer specifying the confidence level. 0 indicates it will not
39+
* be used
40+
*/
41+
int LoadSpec::confidence(Kernel::FileDescriptor &descriptor) const {
42+
if (!descriptor.isAscii())
43+
return 0;
44+
45+
auto &file = descriptor.data();
46+
47+
int confidence(0);
48+
size_t axiscols(0), datacols(0);
49+
std::string str;
50+
using tokenizer = Mantid::Kernel::StringTokenizer;
51+
const std::string sep = " ";
52+
bool snsspec(false);
53+
54+
while (std::getline(file, str)) {
55+
// File is opened in binary mode so getline will leave a \r at the end of an
56+
// empty line if it exists
57+
if (str.empty() || str == "\r")
58+
continue;
59+
60+
try {
61+
// if it's comment line
62+
tokenizer tok(str, sep, Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY);
63+
if (str.at(0) == '#') {
64+
if (str.at(1) == 'L') {
65+
axiscols = tok.count();
66+
// if the file contains a comment line starting with "#L" followed
67+
// by three columns this could be loadsnsspec file
68+
if (axiscols > 2) {
69+
snsspec = true;
70+
}
71+
}
72+
} else {
73+
// check first data line is a 3 column line
74+
datacols = tok.count();
75+
break;
76+
}
77+
} catch (std::out_of_range &) {
78+
}
79+
}
80+
if (snsspec && datacols == 3) // three column data
81+
{
82+
confidence = 80;
83+
}
84+
return confidence;
85+
}
86+
3387
/// Initialisation method.
3488
void LoadSpec::init() {
3589
const std::vector<std::string> exts{".dat", ".txt"};

Testing/SystemTests/tests/framework/LoadLotsOfFiles.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"batch_input.csv",
4242
"mar11015.msk",
4343
"LET_hard.msk", # It seems loade does not understand it?
44-
"LoadSNSspec.txt", # LoadSpec is not registered as a file loader
4544
"MASK.094AA",
4645
"MASKSANS2D_094i_RKH.txt",
4746
"MASKSANS2D.091A",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- :ref:`LoadSpec <algm-LoadSpec>` has been updated to be declared as a file loader

docs/source/release/v6.13.0/framework.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ Removed
4444
.. amalgamate:: Framework/Fit_Functions/Removed
4545

4646

47+
Data Handling
48+
-------------
49+
50+
New features
51+
############
52+
.. amalgamate:: Framework/Data_Handling/New_features
53+
54+
Deprecated
55+
############
56+
.. amalgamate:: Framework/Data_Handling/Deprecated
57+
58+
Removed
59+
############
60+
.. amalgamate:: Framework/Data_Handling/Removed
61+
62+
4763
Data Objects
4864
------------
4965

0 commit comments

Comments
 (0)