Mantid
Loading...
Searching...
No Matches
RawFileInfo.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//----------------------------
11#include "LoadRaw/isisraw2.h"
14#include "MantidAPI/TableRow.h"
16#include <cstdio>
17
18// Register the algorithm into the AlgorithmFactory
19namespace Mantid::DataHandling {
20
21using namespace Mantid::Kernel;
22using namespace Mantid::API;
23using namespace Mantid::DataHandling;
24
26
27
32const std::string RawFileInfo::runTitle(const ISISRAW &isisRaw) { return std::string(isisRaw.r_title, 80); }
33
39const std::string RawFileInfo::runHeader(const ISISRAW &isisRaw) {
40 // coverity doesn't like assuming that the whole hdr struct
41 // has each array of characters laid out consecutively in memory
42 // so we shouldn't just do:
43 // header(isis_raw.hdr.hd_run, 69) to pull out everything
44
45 // Separate each section with a character. 80 chars + 6 separators
46 const auto &rawHdr = isisRaw.hdr;
47 char header[86] = {};
48 const size_t byte = sizeof(char);
49 const char fieldSep(' ');
50 char *start = header;
51
52 memcpy(start, rawHdr.inst_abrv, 3 * byte);
53 start += 3;
54 memset(start, fieldSep, byte); // insert separator
55 start += 1;
56
57 memcpy(start, rawHdr.hd_run, 5 * byte);
58 start += 5;
59 memset(start, fieldSep, byte);
60 start += 1;
61
62 memcpy(start, rawHdr.hd_user, 20 * byte);
63 start += 20;
64 memset(start, fieldSep, byte);
65 start += 1;
66
67 memcpy(start, rawHdr.hd_title, 24 * byte);
68 start += 24;
69 memset(start, fieldSep, byte);
70 start += 1;
71
72 memcpy(start, rawHdr.hd_date, 12 * byte);
73 start += 12;
74 memset(start, fieldSep, byte);
75 start += 1;
76
77 memcpy(start, rawHdr.hd_time, 8 * byte);
78 start += 8;
79 memset(start, fieldSep, byte);
80 start += 1;
81
82 memcpy(start, rawHdr.hd_dur, 8 * byte);
83 // final field so no space afterward
84
85 return std::string(header, header + 86);
86}
87
90 const std::vector<std::string> exts{".raw", ".s*"};
91 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Load, exts),
92 "The name of the [[RAW_File | RAW]] file from which to "
93 "extract the parameters");
94 declareProperty("GetRunParameters", false,
95 "If this is true, the parameters from the RPB struct are "
96 "placed into a TableWorkspace called Raw_RPB",
98 declareProperty("GetSampleParameters", false,
99 "If this is true, the parameters from the SPB struct are "
100 "placed into a TableWorkspace called Raw_SPB. ",
102 declareProperty("RunTitle", std::string(""), "The run title from the HDR struct", Direction::Output);
103 declareProperty("RunHeader", std::string(""), "The run header", Direction::Output);
104 declareProperty("SpectraCount", -1, "The number of spectra", Direction::Output);
105 declareProperty("TimeChannelCount", -1, "The number of time channels", Direction::Output);
106 declareProperty("PeriodCount", -1, "The number of periods", Direction::Output);
107}
108
110 const std::string filename = getPropertyValue("Filename");
111
112 ISISRAW2 isis_raw;
113 // ReadFrom File with no data
114 if (isis_raw.readFromFile(filename.c_str(), false) != 0) {
115 g_log.error("Unable to open file " + filename);
116 throw Exception::FileError("Unable to open File:", filename);
117 }
118
119 const std::string title = RawFileInfo::runTitle(isis_raw);
120 const std::string header = RawFileInfo::runHeader(isis_raw);
121
122 g_log.debug() << "Properties retrieved from " << filename << "\n"
123 << "\tRun title: " << title << "\n\tRun header: " << header << "\n";
124 setProperty("RunTitle", title);
125 setProperty("RunHeader", header);
126
127 // Spectra count
128 int num_holder = isis_raw.t_nsp1;
129 setProperty("SpectraCount", num_holder);
130 g_log.debug() << "\tNumber of spectra: " << num_holder << "\n";
131
132 // Time channel count. Note here that the raw file will say N time channels
133 // which transforms into
134 // (N+1) bin boundaries in Mantid
135 num_holder = isis_raw.t_ntc1;
136 setProperty("TimeChannelCount", num_holder);
137 g_log.debug() << "\tNumber of time channels: " << num_holder << "\n";
138 // The number of periods
139 num_holder = isis_raw.t_nper;
140 setProperty("PeriodCount", num_holder);
141 g_log.debug() << "\tNumber of periods: " << num_holder << "\n";
142
143 // Get the run information if we are told to
144 bool get_run_info = getProperty("GetRunParameters");
145 if (get_run_info) {
147 std::make_unique<WorkspaceProperty<API::ITableWorkspace>>("RunParameterTable", "Raw_RPB", Direction::Output),
148 "The name of the TableWorkspace in which to store the list "
149 "of run parameters");
150
151 API::ITableWorkspace_sptr run_table = WorkspaceFactory::Instance().createTable("TableWorkspace");
152 run_table->addColumn("int", "r_dur"); // actual run duration
153 run_table->addColumn("int", "r_durunits"); // scaler for above (1=seconds)
154 run_table->addColumn("int",
155 "r_dur_freq"); // testinterval for above (seconds)
156 run_table->addColumn("int", "r_dmp"); // dump interval
157 run_table->addColumn("int", "r_dmp_units"); // scaler for above
158 run_table->addColumn("int", "r_dmp_freq"); // interval for above
159 run_table->addColumn("int",
160 "r_freq"); // 2**k where source frequency = 50 / 2**k
161 run_table->addColumn("double",
162 "r_gd_prtn_chrg"); // good proton charge (uA.hour)
163 run_table->addColumn("double",
164 "r_tot_prtn_chrg"); // total proton charge (uA.hour)
165 run_table->addColumn("int", "r_goodfrm"); // good frames
166 run_table->addColumn("int", "r_rawfrm"); // raw frames
167 run_table->addColumn("int", "r_dur_wanted"); // requested run duration
168 // (units as for "duration"
169 // above)
170 run_table->addColumn("int", "r_dur_secs"); // actual run duration in seconds
171 run_table->addColumn("int", "r_mon_sum1"); // monitor sum 1
172 run_table->addColumn("int", "r_mon_sum2"); // monitor sum 2
173 run_table->addColumn("int", "r_mon_sum3"); // monitor sum 3
174 run_table->addColumn("str", "r_enddate"); // format DD-MMM-YYYY
175 run_table->addColumn("str", "r_endtime"); // format HH-MM-SS
176 run_table->addColumn("int", "r_prop"); // RB (proposal) number
177
178 API::TableRow t = run_table->appendRow();
179 t << isis_raw.rpb.r_dur << isis_raw.rpb.r_durunits << isis_raw.rpb.r_dur_freq << isis_raw.rpb.r_dmp
180 << isis_raw.rpb.r_dmp_units << isis_raw.rpb.r_dmp_freq << isis_raw.rpb.r_freq
181 << static_cast<double>(isis_raw.rpb.r_gd_prtn_chrg) << static_cast<double>(isis_raw.rpb.r_tot_prtn_chrg)
182 << isis_raw.rpb.r_goodfrm << isis_raw.rpb.r_rawfrm << isis_raw.rpb.r_dur_wanted << isis_raw.rpb.r_dur_secs
183 << isis_raw.rpb.r_mon_sum1 << isis_raw.rpb.r_mon_sum2 << isis_raw.rpb.r_mon_sum3
184 << std::string(isis_raw.rpb.r_enddate, 11) << std::string(isis_raw.rpb.r_endtime, 8) << isis_raw.rpb.r_prop;
185
186 setProperty("RunParameterTable", run_table);
187 }
188
189 bool getSampleParameters = getProperty("GetSampleParameters");
190 if (getSampleParameters) {
192 std::make_unique<WorkspaceProperty<API::ITableWorkspace>>("SampleParameterTable", "Raw_SPB", Direction::Output),
193 "The name of the TableWorkspace in which to store the list "
194 "of sample parameters");
195
196 API::ITableWorkspace_sptr sample_table = WorkspaceFactory::Instance().createTable("TableWorkspace");
197 sample_table->addColumn("int", "e_posn"); //< sample changer position
198 sample_table->addColumn("int", "e_type"); //< sample type (1=sample+can,2=empty can)
199 sample_table->addColumn("int", "e_geom"); //< sample geometry
200 sample_table->addColumn("double", "e_thick"); //< sample thickness normal to sample (mm)
201 sample_table->addColumn("double", "e_height"); //< sample height (mm)
202 sample_table->addColumn("double", "e_width"); //< sample width (mm)
203 sample_table->addColumn("double",
204 "e_omega"); //< omega sample angle (degrees)
205 sample_table->addColumn("double", "e_chi"); //< chi sample angle (degrees)
206 sample_table->addColumn("double", "e_phi"); //< phi sample angle (degrees)
207 sample_table->addColumn("double", "e_scatt"); //< scattering geometry (1=trans, 2 =reflect)
208 sample_table->addColumn("double",
209 "e_xscatt"); //< sample coherent scattering cross section (barn)
210 sample_table->addColumn("double",
211 "samp_cs_inc"); //< sample incoherent cross section
212 sample_table->addColumn("double",
213 "samp_cs_abs"); //< sample absorption cross section
214 sample_table->addColumn("double",
215 "e_dens"); //< sample number density (atoms.A-3)
216 sample_table->addColumn("double", "e_canthick"); //< can wall thickness (mm)
217 sample_table->addColumn("double",
218 "e_canxsect"); //< can coherent scattering cross section (barn)
219 sample_table->addColumn("double", "can_cs_inc"); //< dunno
220 sample_table->addColumn("double", "can_cs_abs"); //< dunno
221 sample_table->addColumn("double",
222 "can_nd"); //< can number density (atoms.A-3)
223 sample_table->addColumn("str",
224 "e_name"); //< sample name of chemical formula
225 sample_table->addColumn("int", "e_equip"); //< dunno
226 sample_table->addColumn("int", "e_eqname"); //< dunno
227
228 const auto nameLength = static_cast<int>(strlen(isis_raw.spb.e_name));
229 std::string name(isis_raw.spb.e_name, nameLength);
230
231 API::TableRow t = sample_table->appendRow();
232 t << isis_raw.spb.e_posn << isis_raw.spb.e_type << isis_raw.spb.e_geom << static_cast<double>(isis_raw.spb.e_thick)
233 << static_cast<double>(isis_raw.spb.e_height) << static_cast<double>(isis_raw.spb.e_width)
234 << static_cast<double>(isis_raw.spb.e_omega) << static_cast<double>(isis_raw.spb.e_chi)
235 << static_cast<double>(isis_raw.spb.e_phi) << static_cast<double>(isis_raw.spb.e_scatt)
236 << static_cast<double>(isis_raw.spb.e_xscatt) << static_cast<double>(isis_raw.spb.samp_cs_inc)
237 << static_cast<double>(isis_raw.spb.samp_cs_abs) << static_cast<double>(isis_raw.spb.e_dens)
238 << static_cast<double>(isis_raw.spb.e_canthick) << static_cast<double>(isis_raw.spb.e_canxsect)
239 << static_cast<double>(isis_raw.spb.can_cs_inc) << static_cast<double>(isis_raw.spb.can_cs_abs)
240 << static_cast<double>(isis_raw.spb.can_nd) << name << isis_raw.spb.e_equip << isis_raw.spb.e_eqname;
241
242 setProperty("SampleParameterTable", sample_table);
243 }
244
245 // This is not going to be a slow algorithm
246 progress(1.0);
247}
248
249} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
isis raw file.
Definition: isisraw2.h:13
isis raw file.
Definition: isisraw.h:272
HDR_STRUCT hdr
header block (80 bytes)
Definition: isisraw.h:282
SPB_STRUCT spb
sample parameter block (64*4 bytes)
Definition: isisraw.h:310
int t_nper
number of periods
Definition: isisraw.h:327
int t_nsp1
number of spectra in time regime 1
Definition: isisraw.h:329
int readFromFile(const char *filename, bool read_data=true)
stuff
Definition: isisraw.cpp:923
RPB_STRUCT rpb
run parameter block (32*4 bytes)
Definition: isisraw.h:291
int t_ntc1
number of time channels in time regime 1
Definition: isisraw.h:330
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
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
TableRow represents a row in a TableWorkspace.
Definition: TableRow.h:39
A property class for workspaces.
An algorithm to extract pertinent information about a RAW file without loading the data.
Definition: RawFileInfo.h:46
void init() override
Initialisation code.
Definition: RawFileInfo.cpp:89
const std::string name() const override
Algorithm's name.
Definition: RawFileInfo.h:51
void exec() override
Execution code.
static const std::string runTitle(const ISISRAW &isisRaw)
Return the run title from the raw data structure.
Definition: RawFileInfo.cpp:32
static const std::string runHeader(const ISISRAW &isisRaw)
Return the run header from the raw data structure.
Definition: RawFileInfo.cpp:39
Records the filename and the description of failure.
Definition: Exception.h:98
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
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
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
STL namespace.
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54
int r_dur_secs
actual run duration in seconds
Definition: isisraw.h:75
int r_freq
2**k where source frequency = 50 / 2**k
Definition: isisraw.h:69
int r_dur_freq
test interval for above (seconds)
Definition: isisraw.h:65
int r_dmp
dump interval
Definition: isisraw.h:66
int r_mon_sum2
monitor sum 2
Definition: isisraw.h:77
char r_endtime[8]
format HH-MM-SS
Definition: isisraw.h:80
int r_dmp_units
scaler for above
Definition: isisraw.h:67
char r_enddate[12]
format DD-MMM-YYYY
Definition: isisraw.h:79
int r_goodfrm
good frames
Definition: isisraw.h:72
int r_dur_wanted
requested run duration (units as for "duration" above)
Definition: isisraw.h:74
int r_rawfrm
raw frames
Definition: isisraw.h:73
float r_gd_prtn_chrg
good proton charge (uA.hour)
Definition: isisraw.h:70
int r_durunits
scaler for above (1=seconds)
Definition: isisraw.h:64
int r_mon_sum1
monitor sum 1
Definition: isisraw.h:76
int r_dmp_freq
test interval for above
Definition: isisraw.h:68
int r_mon_sum3
monitor sum 3
Definition: isisraw.h:78
int r_dur
actual run duration
Definition: isisraw.h:63
int r_prop
RB (proposal) number.
Definition: isisraw.h:81
float r_tot_prtn_chrg
total proton charge (uA.hour)
Definition: isisraw.h:71
float e_canxsect
can coherent scattering cross section (barn)
Definition: isisraw.h:149
int e_type
sample type (1=sample+can,2=empty can)
Definition: isisraw.h:135
int e_equip
dunno
Definition: isisraw.h:154
float e_width
sample width (mm)
Definition: isisraw.h:139
float can_nd
can number density (atoms.A-3)
Definition: isisraw.h:152
float e_xscatt
sample coherent scattering cross section (barn)
Definition: isisraw.h:144
float e_phi
phi sample angle (degrees)
Definition: isisraw.h:142
float e_scatt
scattering geometry (1=trans, 2 =reflect)
Definition: isisraw.h:143
float e_omega
omega sample angle (degrees)
Definition: isisraw.h:140
float can_cs_abs
dunno
Definition: isisraw.h:151
int e_geom
sample geometry
Definition: isisraw.h:136
int e_posn
sample changer position
Definition: isisraw.h:134
float e_chi
chi sample angle (degrees)
Definition: isisraw.h:141
float samp_cs_inc
sample incoherent cross section
Definition: isisraw.h:145
float can_cs_inc
dunno
Definition: isisraw.h:150
int e_eqname
dunno
Definition: isisraw.h:155
float e_dens
sample number density (atoms.A-3)
Definition: isisraw.h:147
float e_height
sample height (mm)
Definition: isisraw.h:138
float samp_cs_abs
sample absorption cross section
Definition: isisraw.h:146
char e_name[40]
sample name of chemical formula
Definition: isisraw.h:153
float e_thick
sample thickness normal to sample (mm)
Definition: isisraw.h:137
float e_canthick
can wall thickness (mm)
Definition: isisraw.h:148