Mantid
Loading...
Searching...
No Matches
LoadSampleDetailsFromRaw.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//-------------------------------------------------------
8// Includes
9//------------------------------------------------------
13#include "MantidAPI/Sample.h"
14
15// The isis RAW data structure
16#include "LoadRaw/isisraw2.h"
17#include <cstdio> //MG: Required for gcc 4.4
18
19namespace Mantid::DataHandling {
20
21using namespace Mantid::Kernel;
22using namespace Mantid::API;
23using namespace Mantid::DataHandling;
24
25// Register the algorithm into the AlgorithmFactory
27
28
32 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
33 "The sample details are attached to this workspace.");
34 const std::vector<std::string> exts{"raw", ".s*"};
35 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Load, exts),
36 "The raw file containing the sample geometry information.");
37}
38
43 MatrixWorkspace_sptr data_ws = getProperty("InputWorkspace");
44
45 std::string filename = getPropertyValue("Filename");
46 FILE *file = fopen(filename.c_str(), "rb");
47 if (file == nullptr) {
48 g_log.error("Unable to open file " + filename);
49 throw Exception::FileError("Unable to open File:", filename);
50 }
51
52 auto isis_raw = ISISRAW2();
53 isis_raw.ioRAW(file, true);
54 fclose(file);
55
56 // Pick out the geometry information
57 data_ws->mutableSample().setGeometryFlag(isis_raw.spb.e_geom);
58 data_ws->mutableSample().setThickness(static_cast<double>(isis_raw.spb.e_thick));
59 data_ws->mutableSample().setHeight(static_cast<double>(isis_raw.spb.e_height));
60 data_ws->mutableSample().setWidth(static_cast<double>(isis_raw.spb.e_width));
61
62 g_log.debug() << "Raw file sample details:\n"
63 << "\tsample geometry flag: " << isis_raw.spb.e_geom << "\n"
64 << "\tsample thickness: " << data_ws->mutableSample().getThickness() << "\n"
65 << "\tsample height: " << data_ws->mutableSample().getHeight() << "\n"
66 << "\tsample width: " << data_ws->mutableSample().getWidth() << '\n';
67
68 // Not much happens really
69 progress(1.);
70}
71
72} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
isis raw file.
Definition: isisraw2.h:13
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Kernel::Logger & g_log
Definition: Algorithm.h:451
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
A property class for workspaces.
An algorithm to extract the sample details from the SPB structure within a RAW file.
Records the filename and the description of failure.
Definition: Exception.h:98
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
Definition: Property.h:53