Skip to content

Commit

Permalink
Checkpointing work. Refs #6737.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Apr 8, 2013
1 parent 5f70a68 commit 9fc9818
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"

#include "MantidGeometry/Instrument.h"

namespace Mantid
{
Expand Down Expand Up @@ -42,7 +43,20 @@ namespace Algorithms
public:
CreateLogTimeCorrection();
virtual ~CreateLogTimeCorrection();


virtual const std::string name() const {return "CreateLogTimeCorrection"; }
virtual int version() const {return 1; }
virtual const std::string category() const {return "Events\\EventFiltering"; }

private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
/// Implement abstract Algorithm methods
void init();
/// Implement abstract Algorithm methods
void exec();

API::MatrixWorkspace_sptr m_dataWS;
};


Expand Down
63 changes: 59 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/CreateLogTimeCorrection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::Geometry;
using namespace Mantid::Kernel;

using namespace std;
Expand All @@ -15,6 +16,7 @@ namespace Mantid
namespace Algorithms
{

DECLARE_ALGORITHM(CreateLogTimeCorrection)

//----------------------------------------------------------------------------------------------
/** Constructor
Expand All @@ -29,29 +31,82 @@ namespace Algorithms
CreateLogTimeCorrection::~CreateLogTimeCorrection()
{
}

//----------------------------------------------------------------------------------------------
/** Init documentation
*/
void CreateLogTimeCorrection::initDocs()
{
setWikiSummary("Create log time correction table for event filtering by log value"
", if frequency of log is high.");

setOptionalMessage("Create log time correction table. Correction for each pixel is based on L1 and L2.");

return;
}

//----------------------------------------------------------------------------------------------
/** Declare properties
*/
void CreateLogTimeCorrection::init()
{
declareProperty("Instrument", "", "Name of the instrument to create the correction from.");
auto inpwsprop = new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "Anonymous", Direction::Input);
declareProperty(inpwsprop, "Name of the input workspace to generate log correct from.");

auto outwsprop = new WorkspaceProperty<Workspace2D>("Outputworkspace", "AnonymousOut", Direction::Output);
declareProperty(outwsprop, "Name of the output workspace containing the corrections.");

auto fileprop = new FileProperty("OutputFilename", "", FileProperty::Save);
declareProperty(fileprop, "Name of the output time correction file.");

auto wsprop = new WorkspaceProperty<Workspace2D>("OutpoutWorkspace", "Anonymous", Direction::Output);
declareProperty(wsprop, "Name of the output workspace containing the corrections.");

return;
}


//----------------------------------------------------------------------------------------------
void CreateLogTimeCorrection::exec()
{
// 1. Process input
m_dataWS = getProperty("InputWorkspace");

// 2. Explore geometry
Instrument_const_sptr m_instrument = m_dataWS->getInstrument();

std::vector<detid_t> detids = m_instrument->getDetectorIDs(true);

IObjComponent_const_sptr sample = m_instrument->getSample();
V3D samplepos = sample->getPos();

IObjComponent_const_sptr source = m_instrument->getSource();
V3D sourcepos = source->getPos();
double l1 = sourcepos.distance(samplepos);

g_log.notice() << "Sample position = " << samplepos << ".\n";
g_log.notice() << "Source position = " << sourcepos << ", L1 = " << l1 << ".\n";
g_log.notice() << "Number of detector/pixels = " << detids.size() << ".\n";

// 3. Output
Workspace2D_sptr m_outWS = boost::dynamic_pointer_cast<Workspace2D>
(WorkspaceFactory::Instance().create("Workspace2D", 1, detids.size(), detids.size()));

MantidVec& vecX = m_outWS->dataX(0);
MantidVec& vecY = m_outWS->dataY(0);
for (size_t i = 0; i < detids.size(); ++i)
{
vecX[i] = static_cast<double>(detids[i]);

IDetector_const_sptr detector = m_instrument->getDetector(detids[i]);
V3D detpos = detector->getPos();
vecY[i] = detpos.distance(samplepos);
}

setProperty("OutputWorkspace", m_outWS);

}





} // namespace Algorithms
} // namespace Mantid

0 comments on commit 9fc9818

Please sign in to comment.