Skip to content

Commit

Permalink
refs #6856 Cloned initial algorithm into version 2
Browse files Browse the repository at this point in the history
and verified that everything (unit tests) works fine, so we have two identical versions of the same algorithm with only the version number different
  • Loading branch information
abuts committed May 20, 2013
1 parent 7d40f47 commit 036d14b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 74 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set ( SRC_FILES
src/CompareMDWorkspaces.cpp
src/ConvertToDetectorFaceMD.cpp
src/ConvertToDiffractionMDWorkspace.cpp
# src/ConvertToDiffractionMDWorkspace2.cpp
src/ConvertToDiffractionMDWorkspace2.cpp
src/ConvertToMD.cpp
src/CreateMDHistoWorkspace.cpp
src/CreateMDWorkspace.cpp
Expand Down Expand Up @@ -82,7 +82,7 @@ set ( INC_FILES
inc/MantidMDAlgorithms/CompareMDWorkspaces.h
inc/MantidMDAlgorithms/ConvertToDetectorFaceMD.h
inc/MantidMDAlgorithms/ConvertToDiffractionMDWorkspace.h
# inc/MantidMDAlgorithms/ConvertToDiffractionMDWorkspace2.h
inc/MantidMDAlgorithms/ConvertToDiffractionMDWorkspace2.h
inc/MantidMDAlgorithms/ConvertToMD.h
inc/MantidMDAlgorithms/CreateMDHistoWorkspace.h
inc/MantidMDAlgorithms/CreateMDWorkspace.h
Expand Down Expand Up @@ -153,7 +153,7 @@ set ( TEST_FILES
ConvertEventsToMDTest.h
ConvertToDetectorFaceMDTest.h
ConvertToDiffractionMDWorkspaceTest.h
# ConvertToDiffractionMDWorkspace2Test.h
ConvertToDiffractionMDWorkspace2Test.h
ConvertToMDComponentsTest.h
ConvertToMDTest.h
ConvertToQ3DdETest.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "MantidKernel/System.h"
#include "MantidKernel/V3D.h"
#include "MantidMDEvents/BoxControllerSettingsAlgorithm.h"
#include "MantidMDEvents/ConvertToDiffractionMDWorkspace.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDEvents/MDEventWorkspace.h"

Expand All @@ -26,11 +25,11 @@ namespace MDAlgorithms
* @author Janik Zikovsky, SNS
* @date 2011-03-01 13:14:48.236513
*/
class DLLExport ConvertToDiffractionMDWorkspace : public BoxControllerSettingsAlgorithm
class DLLExport ConvertToDiffractionMDWorkspace : public MDEvents::BoxControllerSettingsAlgorithm
{
public:
ConvertToDiffractionMDWorkspace();
~ConvertToDiffractionMDWorkspace();
~ConvertToDiffractionMDWorkspace(){};

/// Algorithm's name for identification
virtual const std::string name() const { return "ConvertToDiffractionMDWorkspace";};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MANTID_MDEVENTS_CONVERTTODIFFRACTIONMDWORKSPACE_H_
#define MANTID_MDEVENTS_CONVERTTODIFFRACTIONMDWORKSPACE_H_
#ifndef MANTID_MDEVENTS_CONVERTTODIFFRACTIONMDWORKSPACE2_H_
#define MANTID_MDEVENTS_CONVERTTODIFFRACTIONMDWORKSPACE2_H_

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IMDEventWorkspace.h"
Expand All @@ -11,31 +11,31 @@
#include "MantidKernel/System.h"
#include "MantidKernel/V3D.h"
#include "MantidMDEvents/BoxControllerSettingsAlgorithm.h"
#include "MantidMDEvents/ConvertToDiffractionMDWorkspace.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDEvents/MDEventWorkspace.h"

namespace Mantid
{
namespace MDEvents
namespace MDAlgorithms
{

/** ConvertToDiffractionMDWorkspace :
/** ConvertToDiffractionMDWorkspace2 :
* Create a MDEventWorkspace with events in reciprocal space (Qx, Qy, Qz) from an input EventWorkspace.
*
* @author Janik Zikovsky, SNS
* @date 2011-03-01 13:14:48.236513
*
* @date 2013-05-20
*/
class DLLExport ConvertToDiffractionMDWorkspace : public BoxControllerSettingsAlgorithm
class DLLExport ConvertToDiffractionMDWorkspace2 : public MDEvents::BoxControllerSettingsAlgorithm
{
public:
ConvertToDiffractionMDWorkspace();
~ConvertToDiffractionMDWorkspace();
/** Constructor */
ConvertToDiffractionMDWorkspace2(){};
/** Destructor */
virtual ~ConvertToDiffractionMDWorkspace2(){};

/// Algorithm's name for identification
virtual const std::string name() const { return "ConvertToDiffractionMDWorkspace";};
/// Algorithm's version for identification
virtual int version() const { return 1;};
virtual int version() const { return 2;};
/// Algorithm's category for identification
virtual const std::string category() const { return "MDAlgorithms";}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ namespace MDAlgorithms
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
ConvertToDiffractionMDWorkspace::~ConvertToDiffractionMDWorkspace()
{
}



//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -174,7 +170,7 @@ namespace MDAlgorithms


/// Our MDLeanEvent dimension
typedef MDLeanEvent<3> MDE;
typedef MDEvents::MDLeanEvent<3> MDE;

//----------------------------------------------------------------------------------------------
/** Convert one spectrum to MDEvents.
Expand Down Expand Up @@ -237,7 +233,7 @@ namespace MDAlgorithms
void ConvertToDiffractionMDWorkspace::convertEventList(int workspaceIndex, EventList & el)
{
size_t numEvents = el.getNumberEvents();
MDBoxBase<MDLeanEvent<3>,3> * box = ws->getBox();
MDEvents::MDBoxBase<MDEvents::MDLeanEvent<3>,3> * box = ws->getBox();

// Get the position of the detector there.
const std::set<detid_t>& detectors = el.getDetectorIDs();
Expand Down Expand Up @@ -392,7 +388,7 @@ namespace MDAlgorithms

// Try to get the output workspace
IMDEventWorkspace_sptr i_out = getProperty("OutputWorkspace");
ws = boost::dynamic_pointer_cast<MDEventWorkspace<MDLeanEvent<3>,3> >( i_out );
ws = boost::dynamic_pointer_cast<MDEvents::MDEventWorkspace<MDEvents::MDLeanEvent<3>,3> >( i_out );

// Initalize the matrix to 3x3 identity
mat = Kernel::Matrix<double>(3,3, true);
Expand Down Expand Up @@ -447,8 +443,8 @@ namespace MDAlgorithms
{
// Create an output workspace with 3 dimensions.
size_t nd = 3;
i_out = MDEventFactory::CreateMDWorkspace(nd, "MDLeanEvent");
ws = boost::dynamic_pointer_cast<MDEventWorkspace3Lean>(i_out);
i_out = MDEvents::MDEventFactory::CreateMDWorkspace(nd, "MDLeanEvent");
ws = boost::dynamic_pointer_cast<MDEvents::MDEventWorkspace3Lean>(i_out);

// ---------------- Get the extents -------------
std::vector<double> extents = getProperty("Extents");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ to an [[EventWorkspace]] but with no events for empty bins.
#include "MantidKernel/ProgressText.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include "MantidMDEvents/ConvertToDiffractionMDWorkspace.h"
#include "MantidMDAlgorithms/ConvertToDiffractionMDWorkspace2.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDEvents/MDEventWorkspace.h"
#include "MantidAPI/MemoryManager.h"
Expand All @@ -85,41 +85,27 @@ using namespace Mantid::Geometry;

namespace Mantid
{
namespace MDEvents
namespace MDAlgorithms
{

bool DODEBUG = true;
bool DODEBUG2 = true;


// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ConvertToDiffractionMDWorkspace)
DECLARE_ALGORITHM(ConvertToDiffractionMDWorkspace2)

/// Sets documentation strings for this algorithm
void ConvertToDiffractionMDWorkspace::initDocs()
void ConvertToDiffractionMDWorkspace2::initDocs()
{
this->setWikiSummary("Create a MDEventWorkspace with events in reciprocal space (Qx, Qy, Qz) for an elastic diffraction experiment.");
this->setOptionalMessage("Create a MDEventWorkspace with events in reciprocal space (Qx, Qy, Qz) for an elastic diffraction experiment.");
}

//----------------------------------------------------------------------------------------------
/** Constructor
*/
ConvertToDiffractionMDWorkspace::ConvertToDiffractionMDWorkspace()
{
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
ConvertToDiffractionMDWorkspace::~ConvertToDiffractionMDWorkspace()
{
}



//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void ConvertToDiffractionMDWorkspace::init()
void ConvertToDiffractionMDWorkspace2::init()
{
// Input units must be TOF
auto validator = boost::make_shared<API::WorkspaceUnitValidator>("TOF");
Expand Down Expand Up @@ -174,7 +160,7 @@ namespace MDEvents


/// Our MDLeanEvent dimension
typedef MDLeanEvent<3> MDE;
typedef MDEvents::MDLeanEvent<3> MDE;

//----------------------------------------------------------------------------------------------
/** Convert one spectrum to MDEvents.
Expand All @@ -184,7 +170,7 @@ namespace MDEvents
*
* @param workspaceIndex :: index into the workspace
*/
void ConvertToDiffractionMDWorkspace::convertSpectrum(int workspaceIndex)
void ConvertToDiffractionMDWorkspace2::convertSpectrum(int workspaceIndex)
{
if (m_inEventWS && !OneEventPerBin)
{
Expand Down Expand Up @@ -234,10 +220,10 @@ namespace MDEvents
* @param el :: reference to the event list
*/
template <class T>
void ConvertToDiffractionMDWorkspace::convertEventList(int workspaceIndex, EventList & el)
void ConvertToDiffractionMDWorkspace2::convertEventList(int workspaceIndex, EventList & el)
{
size_t numEvents = el.getNumberEvents();
MDBoxBase<MDLeanEvent<3>,3> * box = ws->getBox();
MDEvents::MDBoxBase<MDEvents::MDLeanEvent<3>,3> * box = ws->getBox();

// Get the position of the detector there.
const std::set<detid_t>& detectors = el.getDetectorIDs();
Expand Down Expand Up @@ -354,7 +340,7 @@ namespace MDEvents
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void ConvertToDiffractionMDWorkspace::exec()
void ConvertToDiffractionMDWorkspace2::exec()
{
Timer tim, timtotal;
CPUTimer cputim, cputimtotal;
Expand Down Expand Up @@ -392,7 +378,7 @@ namespace MDEvents

// Try to get the output workspace
IMDEventWorkspace_sptr i_out = getProperty("OutputWorkspace");
ws = boost::dynamic_pointer_cast<MDEventWorkspace<MDLeanEvent<3>,3> >( i_out );
ws = boost::dynamic_pointer_cast<MDEvents::MDEventWorkspace<MDEvents::MDLeanEvent<3>,3> >( i_out );

// Initalize the matrix to 3x3 identity
mat = Kernel::Matrix<double>(3,3, true);
Expand Down Expand Up @@ -447,8 +433,8 @@ namespace MDEvents
{
// Create an output workspace with 3 dimensions.
size_t nd = 3;
i_out = MDEventFactory::CreateMDWorkspace(nd, "MDLeanEvent");
ws = boost::dynamic_pointer_cast<MDEventWorkspace3Lean>(i_out);
i_out = MDEvents::MDEventFactory::CreateMDWorkspace(nd, "MDLeanEvent");
ws = boost::dynamic_pointer_cast<MDEvents::MDEventWorkspace3Lean>(i_out);

// ---------------- Get the extents -------------
std::vector<double> extents = getProperty("Extents");
Expand Down Expand Up @@ -535,7 +521,7 @@ namespace MDEvents
size_t eventsAdded = 0;
size_t approxEventsInOutput = 0;
size_t lastNumBoxes = ws->getBoxController()->getTotalNumMDBoxes();
if (DODEBUG) g_log.information() << cputim << ": initial setup. There are " << lastNumBoxes << " MDBoxes.\n";
if (DODEBUG2) g_log.information() << cputim << ": initial setup. There are " << lastNumBoxes << " MDBoxes.\n";

for (size_t wi=0; wi < m_inWS->getNumberHistograms(); wi++)
{
Expand All @@ -547,7 +533,7 @@ namespace MDEvents
if (MultiThreadedAdding)
{
// Equivalent to calling "this->convertSpectrum(wi)"
boost::function<void ()> func = boost::bind(&ConvertToDiffractionMDWorkspace::convertSpectrum, &*this, static_cast<int>(wi));
boost::function<void ()> func = boost::bind(&ConvertToDiffractionMDWorkspace2::convertSpectrum, &*this, static_cast<int>(wi));
// Give this task to the scheduler
double cost = static_cast<double>(eventsAdding);
ts->push( new FunctionTask( func, cost) );
Expand All @@ -564,10 +550,10 @@ namespace MDEvents

if (bc->shouldSplitBoxes(approxEventsInOutput,eventsAdded, lastNumBoxes))
{
if (DODEBUG) g_log.information() << cputim << ": Added tasks worth " << eventsAdded << " events. WorkspaceIndex " << wi << std::endl;
if (DODEBUG2) g_log.information() << cputim << ": Added tasks worth " << eventsAdded << " events. WorkspaceIndex " << wi << std::endl;
// Do all the adding tasks
tp.joinAll();
if (DODEBUG) g_log.information() << cputim << ": Performing the addition of these events.\n";
if (DODEBUG2) g_log.information() << cputim << ": Performing the addition of these events.\n";

// Now do all the splitting tasks
ws->splitAllIfNeeded(ts);
Expand All @@ -577,7 +563,7 @@ namespace MDEvents

// Count the new # of boxes.
lastNumBoxes = ws->getBoxController()->getTotalNumMDBoxes();
if (DODEBUG) g_log.information() << cputim << ": Performing the splitting. There are now " << lastNumBoxes << " boxes.\n";
if (DODEBUG2) g_log.information() << cputim << ": Performing the splitting. There are now " << lastNumBoxes << " boxes.\n";
eventsAdded = 0;
}
}
Expand All @@ -590,28 +576,28 @@ namespace MDEvents
g_log.warning()<<"Unable to find detectors for " << this->failedDetectorLookupCount << " spectra. They have been skipped." << std::endl;
}

if (DODEBUG) g_log.information() << cputim << ": We've added tasks worth " << eventsAdded << " events.\n";
if (DODEBUG2) g_log.information() << cputim << ": We've added tasks worth " << eventsAdded << " events.\n";

tp.joinAll();
if (DODEBUG) g_log.information() << cputim << ": Performing the FINAL addition of these events.\n";
if (DODEBUG2) g_log.information() << cputim << ": Performing the FINAL addition of these events.\n";

// Do a final splitting of everything
ws->splitAllIfNeeded(ts);
tp.joinAll();
if (DODEBUG) g_log.information() << cputim << ": Performing the FINAL splitting of boxes. There are now " << ws->getBoxController()->getTotalNumMDBoxes() <<" boxes\n";
if (DODEBUG2) g_log.information() << cputim << ": Performing the FINAL splitting of boxes. There are now " << ws->getBoxController()->getTotalNumMDBoxes() <<" boxes\n";


// Recount totals at the end.
cputim.reset();
ws->refreshCache();
if (DODEBUG) g_log.information() << cputim << ": Performing the refreshCache().\n";
if (DODEBUG2) g_log.information() << cputim << ": Performing the refreshCache().\n";

//TODO: Centroid in parallel, maybe?
//ws->getBox()->refreshCentroid(NULL);
//if (DODEBUG) g_log.information() << cputim << ": Performing the refreshCentroid().\n";
//if (DODEBUG2) g_log.information() << cputim << ": Performing the refreshCentroid().\n";


if (DODEBUG)
if (DODEBUG2)
{
g_log.information() << "Workspace has " << ws->getNPoints() << " events. This took " << cputimtotal << " in total.\n";
std::vector<std::string> stats = ws->getBoxControllerStats();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef MANTID_MDEVENTS_MAKEDIFFRACTIONMDEVENTWORKSPACETEST_H_
#define MANTID_MDEVENTS_MAKEDIFFRACTIONMDEVENTWORKSPACETEST_H_
#ifndef MANTID_MDEVENTS_MAKEDIFFRACTIONMDEVENTWORKSPACETEST2_H_
#define MANTID_MDEVENTS_MAKEDIFFRACTIONMDEVENTWORKSPACETEST2_H_

#include "MantidDataObjects/EventWorkspace.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include "MantidMDEvents/ConvertToDiffractionMDWorkspace.h"
#include "MantidMDAlgorithms/ConvertToDiffractionMDWorkspace2.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
Expand All @@ -19,14 +19,15 @@ using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::MDEvents;
using namespace Mantid::MDAlgorithms;

class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
class ConvertToDiffractionMDWorkspace2Test : public CxxTest::TestSuite
{
public:

void test_Init()
{
ConvertToDiffractionMDWorkspace alg;
ConvertToDiffractionMDWorkspace2 alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}
Expand Down Expand Up @@ -124,7 +125,7 @@ class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
"Params", "0, 500, 16e3",
"PreserveEvents", MakeWorkspace2D ? "0" : "1" );

ConvertToDiffractionMDWorkspace alg;
ConvertToDiffractionMDWorkspace2 alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
alg.setPropertyValue("InputWorkspace", "inputWS");
Expand Down

0 comments on commit 036d14b

Please sign in to comment.