Skip to content
Snippets Groups Projects
Commit c6fb28a3 authored by Michael Hart's avatar Michael Hart
Browse files

Re #13632 Cleanup, comments, formatting, tweaks

parent 9f0f37b4
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,8 @@
namespace Mantid {
namespace Crystal {
/** LoadIsawPeaks : Load an ISAW-style .peaks file
/**
* Load an ISAW-style .peaks or .integrate file
* into a PeaksWorkspace
*
* @author Janik Zikovsky, SNS
......@@ -17,18 +18,24 @@ namespace Crystal {
class DLLExport LoadIsawPeaks
: public API::IFileLoader<Kernel::FileDescriptor> {
public:
LoadIsawPeaks();
virtual ~LoadIsawPeaks();
LoadIsawPeaks() = default;
virtual ~LoadIsawPeaks() = default;
/// Algorithm's name for identification
virtual const std::string name() const { return "LoadIsawPeaks"; };
virtual const std::string name() const {
return "LoadIsawPeaks";
}
/// Summary of algorithms purpose
virtual const std::string summary() const {
return "Load an ISAW-style .peaks file into a PeaksWorkspace.";
}
/// Algorithm's version for identification
virtual int version() const { return 1; };
virtual int version() const {
return 1;
}
/// Algorithm's category for identification
virtual const std::string category() const {
return "Crystal;DataHandling\\Isaw";
......@@ -40,16 +47,20 @@ public:
private:
/// Initialise the properties
void init();
/// Run the algorithm
void exec();
/// Reads calibration/detector section and returns first word of next line
std::string ApplyCalibInfo(std::ifstream &in, std::string startChar,
Geometry::Instrument_const_sptr instr_old,
Geometry::Instrument_const_sptr instr, double &T0);
/// Reads first line of peaks file and returns first word of next line
std::string readHeader(Mantid::DataObjects::PeaksWorkspace_sptr outWS,
std::ifstream &in, double &T0);
/// Read a single peak from peaks file
DataObjects::Peak readPeak(DataObjects::PeaksWorkspace_sptr outWS,
std::string &lastStr, std::ifstream &in,
int &seqNum, std::string bankName);
......@@ -57,12 +68,17 @@ private:
int findPixelID(Geometry::Instrument_const_sptr inst, std::string bankName,
int col, int row);
/// Read the header of a peak block section, returns first word of next line
std::string readPeakBlockHeader(std::string lastStr, std::ifstream &in,
int &run, int &detName, double &chi,
double &phi, double &omega, double &monCount);
/// Append peaks from given file to given workspace
void appendFile(Mantid::DataObjects::PeaksWorkspace_sptr outWS,
std::string filename);
/// Compare number of peaks in given file to given workspace
/// Throws std::length_error on mismatch
void checkNumberPeaks(Mantid::DataObjects::PeaksWorkspace_sptr outWS,
std::string filename);
......
......@@ -19,18 +19,10 @@ using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::Geometry;
//----------------------------------------------------------------------------------------------
/** Constructor
*/
LoadIsawPeaks::LoadIsawPeaks() {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
LoadIsawPeaks::~LoadIsawPeaks() {}
/**
* Return the confidence with with this algorithm can load the file
* Determine the confidence with which this algorithm can load a given file
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not
* be used
......@@ -76,14 +68,13 @@ int LoadIsawPeaks::confidence(Kernel::FileDescriptor &descriptor) const {
getWord(in, false);
readToEndOfLine(in, true);
confidence = 95;
} catch (std::exception &) {
}
catch (std::exception &) {
}
return confidence;
}
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
......@@ -99,6 +90,23 @@ void LoadIsawPeaks::init() {
"Name of the output workspace.");
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void LoadIsawPeaks::exec() {
// Create the workspace
PeaksWorkspace_sptr ws(new PeaksWorkspace());
// This loads (appends) the peaks
this->appendFile(ws, getPropertyValue("Filename"));
// Save it in the output
setProperty("OutputWorkspace", boost::dynamic_pointer_cast<Workspace>(ws));
this->checkNumberPeaks(ws, getPropertyValue("Filename"));
}
//----------------------------------------------------------------------------------------------
std::string
LoadIsawPeaks::ApplyCalibInfo(std::ifstream &in, std::string startChar,
Geometry::Instrument_const_sptr instr_old,
......@@ -113,7 +121,6 @@ LoadIsawPeaks::ApplyCalibInfo(std::ifstream &in, std::string startChar,
startChar = getWord(in, false);
}
if (!(in.good())) {
// g_log.error()<<"Peaks file has no time shift and L0 info"<<std::endl;
throw std::invalid_argument("Peaks file has no time shift and L0 info");
}
std::string L1s = getWord(in, false);
......@@ -291,15 +298,11 @@ std::string LoadIsawPeaks::readHeader(PeaksWorkspace_sptr outWS,
Geometry::Instrument_const_sptr instr(
new Geometry::Instrument(instr_old->baseInstrument(), map));
// std::string s;
std::string s = ApplyCalibInfo(in, "", instr_old, instr, T0);
outWS->setInstrument(instr);
// Now skip all lines on L1, detector banks, etc. until we get to a block of
// peaks. They start with 0.
// readToEndOfLine( in , true );
// readToEndOfLine( in , true );
// s = getWord(in, false);
while (s != "0" && in.good()) {
readToEndOfLine(in, true);
s = getWord(in, false);
......@@ -402,6 +405,7 @@ DataObjects::Peak LoadIsawPeaks::readPeak(PeaksWorkspace_sptr outWS,
return peak;
}
//----------------------------------------------------------------------------------------------
int LoadIsawPeaks::findPixelID(Instrument_const_sptr inst, std::string bankName,
int col, int row) {
boost::shared_ptr<const IComponent> parent =
......@@ -492,6 +496,11 @@ void LoadIsawPeaks::appendFile(PeaksWorkspace_sptr outWS,
// Open the file
std::ifstream in(filename.c_str());
// Calculate filesize
in.seekg(0, in.end);
auto filelen = in.tellg();
in.seekg(0, in.beg);
// Read the header, load the instrument
double T0;
std::string s = readHeader(outWS, in, T0);
......@@ -515,8 +524,8 @@ void LoadIsawPeaks::appendFile(PeaksWorkspace_sptr outWS,
Mantid::Geometry::Goniometer uniGonio;
uniGonio.makeUniversalGoniometer();
// TODO: Can we find the number of peaks to get better progress reporting?
Progress prog(this, 0.0, 1.0, 100);
// Progress is reported based on how much of the file we've read
Progress prog(this, 0.0, 1.0, filelen);
while (in.good()) {
// Read the header if necessary
......@@ -566,9 +575,10 @@ void LoadIsawPeaks::appendFile(PeaksWorkspace_sptr outWS,
<< e.what() << std::endl;
}
prog.report();
prog.report(in.tellg());
}
}
//-----------------------------------------------------------------------------------------------
/** Count the peaks from a .peaks file and compare with the workspace
* @param outWS :: the workspace in which to place the information
......@@ -592,22 +602,6 @@ void LoadIsawPeaks::checkNumberPeaks(PeaksWorkspace_sptr outWS,
}
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void LoadIsawPeaks::exec() {
// Create the workspace
PeaksWorkspace_sptr ws(new PeaksWorkspace());
// This loads (appends) the peaks
this->appendFile(ws, getPropertyValue("Filename"));
// Save it in the output
setProperty("OutputWorkspace", boost::dynamic_pointer_cast<Workspace>(ws));
this->checkNumberPeaks(ws, getPropertyValue("Filename"));
}
//----------------------------------------------------------------------------------------------
/** Retrieves pointer to given bank from local cache.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment