/
LoadSampleDetailsFromRaw.cpp
72 lines (60 loc) · 2.65 KB
/
LoadSampleDetailsFromRaw.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
//-------------------------------------------------------
// Includes
//------------------------------------------------------
#include "MantidDataHandling/LoadSampleDetailsFromRaw.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Sample.h"
// The isis RAW data structure
#include "LoadRaw/isisraw2.h"
#include <cstdio> //MG: Required for gcc 4.4
namespace Mantid::DataHandling {
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataHandling;
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(LoadSampleDetailsFromRaw)
/**
* Initialize the algorithm
*/
void LoadSampleDetailsFromRaw::init() {
declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
"The sample details are attached to this workspace.");
const std::vector<std::string> exts{"raw", ".s*"};
declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Load, exts),
"The raw file containing the sample geometry information.");
}
/**
* Execute the algorithm
*/
void LoadSampleDetailsFromRaw::exec() {
MatrixWorkspace_sptr data_ws = getProperty("InputWorkspace");
std::string filename = getPropertyValue("Filename");
FILE *file = fopen(filename.c_str(), "rb");
if (file == nullptr) {
g_log.error("Unable to open file " + filename);
throw Exception::FileError("Unable to open File:", filename);
}
auto isis_raw = ISISRAW2();
isis_raw.ioRAW(file, true);
fclose(file);
// Pick out the geometry information
data_ws->mutableSample().setGeometryFlag(isis_raw.spb.e_geom);
data_ws->mutableSample().setThickness(static_cast<double>(isis_raw.spb.e_thick));
data_ws->mutableSample().setHeight(static_cast<double>(isis_raw.spb.e_height));
data_ws->mutableSample().setWidth(static_cast<double>(isis_raw.spb.e_width));
g_log.debug() << "Raw file sample details:\n"
<< "\tsample geometry flag: " << isis_raw.spb.e_geom << "\n"
<< "\tsample thickness: " << data_ws->mutableSample().getThickness() << "\n"
<< "\tsample height: " << data_ws->mutableSample().getHeight() << "\n"
<< "\tsample width: " << data_ws->mutableSample().getWidth() << '\n';
// Not much happens really
progress(1.);
}
} // namespace Mantid::DataHandling