Newer
Older
Janik Zikovsky
committed
/*WIKI*
Extracts run parameters from the [[RAW_File | RAW]] file given as an input property. If the ''GetRunParameters'' argument is ''True'' then a TableWorkspace is created that contains a column for each value of the RPB_STRUCT, i.e. column names such as r_dur, r_goodfrm etc. This is Mantid's version of the '''Get''' routine in Open Genie.
*WIKI*/
Gigg, Martyn Anthony
committed
//----------------------------
// Includes
//----------------------------
#include "MantidDataHandling/RawFileInfo.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/FileProperty.h"
Gigg, Martyn Anthony
committed
#include "LoadRaw/isisraw2.h"
#include "MantidAPI/ITableWorkspace.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/TableRow.h"
#include <cstdio>
Gigg, Martyn Anthony
committed
// Register the algorithm into the AlgorithmFactory
namespace Mantid
{
namespace DataHandling
{
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataHandling;
Janik Zikovsky
committed
DECLARE_ALGORITHM(RawFileInfo)
/// Sets documentation strings for this algorithm
void RawFileInfo::initDocs()
Gigg, Martyn Anthony
committed
{
Janik Zikovsky
committed
this->setWikiSummary("Extract run parameters from a [[RAW_File | RAW]] file as output properties. ");
this->setOptionalMessage("Extract run parameters from a RAW file as output properties.");
}
Janik Zikovsky
committed
/// Initialise
void RawFileInfo::init()
{
Peterson, Peter
committed
std::vector<std::string> exts;
exts.push_back(".raw");
exts.push_back(".s*");
Gigg, Martyn Anthony
committed
declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts),
Gigg, Martyn Anthony
committed
"The RAW file from which to extract the information");
declareProperty("RunTitle", std::string(""), "The title of the run", Direction::Output);
Russell Taylor
committed
declareProperty("RunHeader", std::string(""), "The run header", Direction::Output);
Gigg, Martyn Anthony
committed
declareProperty("SpectraCount", -1, "The number of spectra", Direction::Output);
declareProperty("TimeChannelCount", -1, "The number of time channels in regime 1 ", Direction::Output);
declareProperty("PeriodCount", -1, "The number of periods", Direction::Output);
declareProperty("GetRunParameters", false, "Create a table workspace with each column having the title\n"
"of a paramter in the RPB struct of the RAW file", Direction::Input);
}
void RawFileInfo::exec()
{
Russell Taylor
committed
const std::string filename = getPropertyValue("Filename");
ISISRAW2 isis_raw;
// ReadFrom File with no data
if (isis_raw.readFromFile(filename.c_str(),false) != 0)
Gigg, Martyn Anthony
committed
{
g_log.error("Unable to open file " + filename);
throw Exception::FileError("Unable to open File:", filename);
}
Russell Taylor
committed
const std::string title(isis_raw.r_title,80);
Gigg, Martyn Anthony
committed
// First get the general information about the run
Russell Taylor
committed
std::string header(isis_raw.hdr.hd_run, 69);
Gigg, Martyn Anthony
committed
// Insert some spaces to tidy the string up a bit
Russell Taylor
committed
header.insert(5, " ");
header.insert(26, " ");
header.insert(51, " ");
Gigg, Martyn Anthony
committed
g_log.debug() << "Properties retrieved from " << filename << "\n"
Russell Taylor
committed
<< "\tRun title: " << title
<< "\n\tRun header: " << header << "\n";
Gigg, Martyn Anthony
committed
setProperty("RunTitle", title);
Russell Taylor
committed
setProperty("RunHeader", header);
Gigg, Martyn Anthony
committed
// Spectra count
Russell Taylor
committed
int num_holder = isis_raw.t_nsp1;
Gigg, Martyn Anthony
committed
setProperty("SpectraCount", num_holder);
g_log.debug() << "\tNumber of spectra: " << num_holder << "\n";
// Time channel count. Note here that the raw file will say N time channels which transforms into
// (N+1) bin boundaries in Mantid
Russell Taylor
committed
num_holder = isis_raw.t_ntc1;
Gigg, Martyn Anthony
committed
setProperty("TimeChannelCount", num_holder);
g_log.debug() << "\tNumber of time channels: " << num_holder << "\n";
// The number of periods
Russell Taylor
committed
num_holder = isis_raw.t_nper;
Gigg, Martyn Anthony
committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
setProperty("PeriodCount", num_holder);
g_log.debug() << "\tNumber of periods: " << num_holder << "\n";
// Get the run information if we are told to
bool get_run_info = getProperty("GetRunParameters");
if( get_run_info )
{
declareProperty(new WorkspaceProperty<API::ITableWorkspace>("RunParameterTable","Raw_RPB",Direction::Output),
"The name of the TableWorkspace in which to store the list of run parameters" );
API::ITableWorkspace_sptr run_table = WorkspaceFactory::Instance().createTable("TableWorkspace");
run_table->addColumn("int", "r_dur"); // actual run duration
run_table->addColumn("int", "r_durunits"); // scaler for above (1=seconds)
run_table->addColumn("int", "r_dur_freq"); // testinterval for above (seconds)
run_table->addColumn("int", "r_dmp"); // dump interval
run_table->addColumn("int", "r_dmp_units"); // scaler for above
run_table->addColumn("int", "r_dmp_freq"); // interval for above
run_table->addColumn("int", "r_freq"); // 2**k where source frequency = 50 / 2**k
run_table->addColumn("double", "r_gd_prtn_chrg"); // good proton charge (uA.hour)
run_table->addColumn("double", "r_tot_prtn_chrg"); // total proton charge (uA.hour)
run_table->addColumn("int", "r_goodfrm"); // good frames
run_table->addColumn("int", "r_rawfrm"); // raw frames
run_table->addColumn("int", "r_dur_wanted"); // requested run duration (units as for "duration" above)
run_table->addColumn("int", "r_dur_secs"); // actual run duration in seconds
run_table->addColumn("int", "r_mon_sum1"); // monitor sum 1
run_table->addColumn("int", "r_mon_sum2"); // monitor sum 2
run_table->addColumn("int", "r_mon_sum3"); // monitor sum 3
run_table->addColumn("str", "r_enddate"); // format DD-MMM-YYYY
run_table->addColumn("str", "r_endtime"); // format HH-MM-SS
run_table->addColumn("int", "r_prop"); // RB (proposal) number
API::TableRow t = run_table->appendRow();
Russell Taylor
committed
t << isis_raw.rpb.r_dur << isis_raw.rpb.r_durunits << isis_raw.rpb.r_dur_freq << isis_raw.rpb.r_dmp
<< isis_raw.rpb.r_dmp_units << isis_raw.rpb.r_dmp_freq << isis_raw.rpb.r_freq
<< static_cast<double>(isis_raw.rpb.r_gd_prtn_chrg) << static_cast<double>(isis_raw.rpb.r_tot_prtn_chrg)
<< isis_raw.rpb.r_goodfrm << isis_raw.rpb.r_rawfrm << isis_raw.rpb.r_dur_wanted
<< isis_raw.rpb.r_dur_secs << isis_raw.rpb.r_mon_sum1 << isis_raw.rpb.r_mon_sum2 << isis_raw.rpb.r_mon_sum3
<< std::string(isis_raw.rpb.r_enddate, 11) << std::string(isis_raw.rpb.r_endtime, 8) << isis_raw.rpb.r_prop;
Gigg, Martyn Anthony
committed
setProperty("RunParameterTable", run_table);
}
// This is not going to be a slow algorithm
progress(1.0);
}
Janik Zikovsky
committed
} // namespace
}