34 const std::string &extn = descriptor.
extension();
35 if (extn !=
".grp" && extn !=
".sqe" && extn !=
".txt" && extn !=
".dat")
45 std::getline(descriptor.
data(), curline);
46 if (curline.substr(0, 1) ==
"#") {
52 std::getline(descriptor.
data(), curline);
54 std::istringstream is(curline);
56 daveGrp = daveGrp && !is.fail();
59 std::getline(descriptor.
data(), curline);
60 if (curline.substr(0, 1) !=
"#")
64 std::getline(descriptor.
data(), curline);
69 daveGrp = daveGrp && !is.fail();
78 std::vector<std::string> exts{
".grp",
".sqe",
".txt",
".dat"};
81 "A DAVE grouped ASCII file");
83 "The name of the workspace that will be created.");
89 "The name of the units for the X-Axis (must be one of "
90 "those registered in "
95 "The name of the units for the Y-Axis (must be one of "
96 "those registered in "
99 "Original file is in units of micro-eV for DeltaE");
102 "Convert output workspace to histogram data.");
106 const std::string filename =
getProperty(
"Filename");
107 std::vector<double> xAxis;
108 std::vector<double> yAxis;
111 ifile.open(filename.c_str());
112 if (
ifile.is_open()) {
118 }
catch (boost::bad_lexical_cast &) {
119 throw std::runtime_error(
"LoadDaveGrp: Failed to parse axis length from file.");
132 throw std::runtime_error(
"LoadDaveGrp: Failed to open file.");
138 std::transform(xAxis.cbegin(), xAxis.cend(), xAxis.begin(), [](
const auto &
value) { return value / 1000.0; });
143 const bool convertToHistogram =
getProperty(
"ConvertToHistogram");
144 if (convertToHistogram)
147 outputWorkspace->mutableRun().addProperty(
"Filename", filename);
156 outputWorkspace->setDistribution(
true);
160 auto verticalAxis = std::make_unique<API::NumericAxis>(
nGroups);
164 outputWorkspace->replaceAxis(1, std::move(verticalAxis));
165 return outputWorkspace;
169 const std::vector<double> &yAxis)
const {
171 auto verticalAxis =
workspace->getAxis(1);
172 auto sharedX = Kernel::make_cow<HistogramData::HistogramX>(xAxis);
173 for (
size_t i = 0; i <
nGroups; i++) {
175 verticalAxis->setValue(i, yAxis.at(i));
181 convert2HistAlg->setProperty(
"InputWorkspace",
workspace);
182 convert2HistAlg->setProperty(
"OutputWorkspace",
workspace);
183 convert2HistAlg->execute();
184 workspace = convert2HistAlg->getProperty(
"OutputWorkspace");
187 convertFromDistAlg->setProperty(
"Workspace",
workspace);
188 convertFromDistAlg->execute();
200 std::istringstream is(
line);
201 std::string strLength;
204 length = boost::lexical_cast<size_t>(strLength);
212 for (std::size_t i = 0; i < length; i++) {
214 std::istringstream is(
line);
216 axis.emplace_back(
value);
221 double data_val = 0.0;
222 double err_val = 0.0;
226 for (
size_t j = 0; j <
nGroups; j++) {
233 for (std::size_t k = 0; k <
xLength; k++) {
235 std::istringstream is(
line);
236 is >> data_val >> err_val;
double value
The value of the point.
IPeaksWorkspace_sptr workspace
#define DECLARE_FILELOADER_ALGORITHM(classname)
DECLARE_FILELOADER_ALGORITHM should be used in place of the standard DECLARE_ALGORITHM macro when wri...
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
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
Helper class for reporting progress from algorithms.
A property class for workspaces.
Reads the DAVE grouped ASCII format into a workspace.
void getData(const API::MatrixWorkspace_sptr &workspace)
Function to parse and store the signal and errors from the data file.
void getAxisLength(size_t &length)
Function to retrieve the lengths of the x and y axes.
API::MatrixWorkspace_sptr setupWorkspace() const
Function to setup the workspace ready for data to be loaded into it.
void exec() override
Execution code.
void readLine()
Function to read a line from the data file.
void setWorkspaceAxes(const API::MatrixWorkspace_sptr &workspace, const std::vector< double > &xAxis, const std::vector< double > &yAxis) const
Function to set the workspace axes.
std::string line
Placeholder for file lines.
void getAxisValues(std::vector< double > &axis, const std::size_t length)
Function to parse and store the actual axis values.
std::ifstream ifile
Handle for input data file.
API::MatrixWorkspace_sptr convertWorkspaceToHistogram(API::MatrixWorkspace_sptr workspace)
Convert a workspace to a histogram.
int confidence(Kernel::FileDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
std::size_t nGroups
The number of groups present in the data file.
std::size_t xLength
The size of the x-axis in the data file.
void init() override
Initialization code.
Defines a wrapper around an open file.
static bool isAscii(const std::string &filename, const size_t nbytes=256)
Returns true if the file is considered ascii.
std::istream & data()
Access the open file stream.
const std::string & extension() const
Access the file extension.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
@ Input
An input workspace.
@ Output
An output workspace.