Mantid
Loading...
Searching...
No Matches
LoadMappingTable.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 +
8#include "LoadRaw/isisraw2.h"
13
14namespace Mantid::DataHandling {
15
16using namespace Kernel;
17using namespace API;
18
19DECLARE_ALGORITHM(LoadMappingTable)
20
22
24 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Load),
25 "The name of the RAW file from which to obtain the mapping "
26 "information, including its full or relative path.");
27 declareProperty(std::make_unique<WorkspaceProperty<>>("Workspace", "Anonymous", Direction::InOut),
28 "The name of the input and output workspace on which to perform the "
29 "algorithm.");
30}
31
33 // Get the raw file name
34 m_filename = getPropertyValue("Filename");
35 // Get the input workspace
36 const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
37
39 auto iraw = std::make_unique<ISISRAW2>();
40
41 if (iraw->readFromFile(m_filename.c_str(), false) != 0) // ReadFrom File with no data
42 {
43 g_log.error("Unable to open file " + m_filename);
44 throw Kernel::Exception::FileError("Unable to open File:", m_filename);
45 }
46 progress(0.5);
47 const int number_spectra = iraw->i_det; // Number of entries in the spectra/udet table
48 if (number_spectra == 0) {
49 g_log.warning("The spectra to detector mapping table is empty");
50 }
51 // Fill in the mapping in the workspace's ISpectrum objects
52 localWorkspace->updateSpectraUsing(SpectrumDetectorMapping(iraw->spec, iraw->udet, number_spectra));
53 // Map spectra whose file detector IDs the instrument does not define onto the detector of the same ID; a no-op
54 // unless the instrument definition enables it.
55 correctSpectraMapping(*localWorkspace, g_log);
56 progress(1);
57}
58
59} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:542
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Kernel::Logger & g_log
Definition Algorithm.h:423
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
@ Load
allowed here which will be passed to the algorithm
A minimal class to hold the mapping between the spectrum number and its related detector ID numbers f...
A property class for workspaces.
Loads the mapping table between spectra and IDetector from a raw file.
void init() override
Overwrites Algorithm method.
std::string m_filename
The name and path of the input file.
void exec() override
Overwrites Algorithm method.
Records the filename and the description of failure.
Definition Exception.h:98
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
MANTID_DATAHANDLING_DLL bool correctSpectraMapping(API::MatrixWorkspace &workspace, Kernel::Logger &log)
Corrects spectrum-to-detector mappings for files that use detector IDs not recognized by the instrume...
@ InOut
Both an input & output workspace.
Definition Property.h:55