Skip to content

Commit

Permalink
Checkpointing work. Refs #6968.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Jun 21, 2013
1 parent f4b60b9 commit 5c733ad
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidDataObjects/TableWorkspace.h"

namespace Mantid
{
Expand Down Expand Up @@ -76,6 +77,9 @@ class DLLExport SaveGSASInstrumentFile : public API::Algorithm
/// Execution code
void exec();

/// Process properties
void processProperties();

/// Set up some constant by default
void initConstants(double chopperfrequency);

Expand All @@ -99,6 +103,8 @@ class DLLExport SaveGSASInstrumentFile : public API::Algorithm
/// Caclualte L2 from DIFFC and L1
double calL2FromDtt1(double difc, double L1, double twotheta);

/// Input workspace
DataObjects::TableWorkspace_sptr m_inpWS;

/// Instrument
std::string m_instrument;
Expand All @@ -109,12 +115,18 @@ class DLLExport SaveGSASInstrumentFile : public API::Algorithm
/// 2Theta
double m_2theta;
/// Frequency
double m_frequency;
int m_frequency;
/// User input ID line
std::string m_id_line;
/// Sample
std::string m_sample;

/// Banks IDs to process
std::vector<unsigned int> m_bankIDsOutput;

/// Output file name
std::string m_gsasFileName;

};

/// Examine whether str1's last few characters are same as str2
Expand Down
97 changes: 65 additions & 32 deletions Code/Mantid/Framework/Algorithms/src/SaveGSASInstrumentFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ There can be several types of Fullprof files as the input file
*/

#include "MantidAlgorithms/SaveGSASInstrumentFile.h"
#include "MantidAPI/FileProperty.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/ArrayProperty.h"

using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::DataObjects;

using namespace std;

Expand Down Expand Up @@ -55,56 +63,70 @@ namespace Algorithms
//----------------------------------------------------------------------------------------------
void SaveGSASInstrumentFile::initDocs()
{
setWikiSummary("");
setWikiSummary("Save a instrument parameter table workspace to GSAS instrument file.");
setOptionalMessage("");
}

//----------------------------------------------------------------------------------------------
/** Declare properties
*/
void SaveGSASInstrumentFile::init()
{
/**
""" Set Property
"""
instruments = ["PG3", "NOM", "VULCAN", "SNAP"]
frequencies = ["10", "30", "60"]
self.declareProperty("Instrument", "PG3", Validator=ListValidator(instruments),
Description="SNS Instrument Name")
self.declareFileProperty("InputFile", "", FileAction.Load, [".irf", ".pcr"],
Description="Resolution (Fullprof, .irf) file")
self.declareProperty("IDLine", "", Description="ID Line in output GSAS instrument file")
self.declareProperty("Sample", "", Description="Sample information written to header (title)")
self.declareListProperty("Banks", [1], Validator=ArrayBoundedValidator(Lower=0),
Description="Banks to be written into output file")
self.declareProperty("Frequency", "60", Validator=ListValidator(frequencies),
Description="Frequency of the instrument file corresponds to")
self.declareProperty("L1", -1.0)
self.declareProperty("L2", -1.0,
Description="Distance from sample to detector. If 2Theta is given, this won't work. ")
self.declareProperty("2Theta", 1001.0,
Description="Angle of the detector bank. It is to calculate L2 with given Dtt1")
self.declareFileProperty("OutputFile", "", FileAction.Save, [".iparm", ".prm"],
Description="Output .iparm or .prm file")
*/
declareProperty(new WorkspaceProperty<TableWorkspace>("InputWorkspace", "", Direction::Input),
"Name of the table workspace containing the parameters. Usually it is generated by "
"LoadFullprofResolution.");

vector<string> exts;
exts.push_back(".iparam");
exts.push_back(".prm");
auto fileprop = new FileProperty("OutputFileName", "", FileProperty::Save, exts);
declareProperty(fileprop, "Name of the output GSAS instrument file.");

declareProperty(new ArrayProperty<unsigned int>("BankIDs"), "Bank IDs of the banks to be written to GSAS instrument file.");


vector<string> instruments;
instruments.push_back("PG3");
instruments.push_back("NOM");
instruments.push_back("VULCAN");
// auto instrumentval = new ListValidator<string>(instruments);
declareProperty("Instrument", "PG3", boost::make_shared<StringListValidator>(instruments), "Name of the instrument that parameters are belonged to. ");

vector<int> vecfreq;
vecfreq.push_back(10);
vecfreq.push_back(30);
vecfreq.push_back(60);
ListValidator<int> freqva(vecfreq);
auto freqval = new ListValidator<int>(vecfreq);
declareProperty("ChopperFrequency", 60, boost::make_shared<ListValidator<int> >(freqval), "Frequency of the chopper. ");

declareProperty("IDLine", "", "ID line to be written in GSAS instrumetn file.");
declareProperty("Sample", "", "Name of the sample used to calibrate the instrument parameters. ");

declareProperty("L1", EMPTY_DBL(), "L1 (primary flight path) of the instrument. ");
declareProperty("L2", EMPTY_DBL(), "L2 (secondary flight path) of the insturment. ");
declareProperty("TwoTheta", EMPTY_DBL(), "Angle of the detector bank. ");

return;
}

//----------------------------------------------------------------------------------------------
void SaveGSASInstrumentFile::exec()
void SaveGSASInstrumentFile::processProperties()
{
// Get properties
m_inpWS = getProperty("InputWorkspace");

m_instrument = getPropertyValue("Instrument");
m_id_line = getPropertyValue("IDLine"); // Standard Run LB4844 Vanadium: 4866 J.P. Hodges 2011-09-01
m_sample = getPropertyValue("Sample"); // titleline = "LaB6 NIST RT 4844[V=4866] 60Hz CW=.533"

string inputfilename = getProperty("InputFile");
string outputfilename = getProperty("OutputFile");
int banks = getProperty("Banks");
m_gsasFileName = getPropertyValue("OutputFileName");
m_bankIDsOutput = getProperty("BankIDs");

m_L1 = getProperty("L1");
m_2theta = getProperty("2Theta");
m_L2 = getProperty("L2");
m_frequency = getProperty("Frequency");

#if 0
// Process input
bool useirf = false;
string irffilename, pcrfilename;
Expand All @@ -117,6 +139,7 @@ namespace Algorithms
{
pcrfilename = inputfilename;
}
#endif

// Set default value for L1
if (m_L1 == EMPTY_DBL())
Expand Down Expand Up @@ -158,6 +181,16 @@ namespace Algorithms
m_L2 = EMPTY_DBL();
}

}

//----------------------------------------------------------------------------------------------
/** Main execution body
*/
void SaveGSASInstrumentFile::exec()
{
// Process user specified properties
processProperties();

// Execute
initConstants(m_frequency);

Expand Down Expand Up @@ -266,7 +299,7 @@ namespace Algorithms
cwlstr = "3.198";
mndspstr = "0.10";
mxdspstr = "12.36";
mxtofstr = "280.5";
maxtofstr = "280.5";

break;

Expand Down

0 comments on commit 5c733ad

Please sign in to comment.