Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #11747 MDhisto to MDevent for integration
- Loading branch information
1 parent
5b15be5
commit a6a8efc
Showing
5 changed files
with
622 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/ConvertMDHistoToMDEventWorkspace.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef MANTID_MDALGORITHMS_ConvertMDHistoToMDEventWorkspace_H_ | ||
#define MANTID_MDALGORITHMS_ConvertMDHistoToMDEventWorkspace_H_ | ||
|
||
#include "MantidAPI/Algorithm.h" | ||
#include "MantidDataObjects/MDEventWorkspace.h" | ||
#include <deque> | ||
|
||
namespace Mantid { | ||
namespace MDAlgorithms { | ||
|
||
/** ConvertMDHistoToMDEventWorkspace : Loads a file containing dimensionality and data for | ||
an MDEventWorkspace. Handles either full mdevents for mdleanevents as input | ||
data types. | ||
@date 2012-07-11 | ||
Copyright © 2012 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge | ||
National Laboratory & European Spallation Source | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport ConvertMDHistoToMDEventWorkspace : public API::Algorithm { | ||
public: | ||
ConvertMDHistoToMDEventWorkspace(); | ||
virtual ~ConvertMDHistoToMDEventWorkspace(); | ||
|
||
virtual const std::string name() const; | ||
/// Summary of algorithms purpose | ||
virtual const std::string summary() const { | ||
return "Reads an ASCII file containing MDEvent data and constructs an " | ||
"MDEventWorkspace."; | ||
} | ||
|
||
virtual int version() const; | ||
virtual const std::string category() const; | ||
|
||
private: | ||
|
||
/// Actual number of dimensions specified | ||
size_t m_nDimensions; | ||
/// Actual number of md events provided. | ||
size_t m_nDataObjects; | ||
/// call back to add event data | ||
template <typename MDE, size_t nd> | ||
void addEventsData(typename DataObjects::MDEventWorkspace<MDE, nd>::sptr outWs); | ||
DataObjects::MDHistoWorkspace_sptr ws; | ||
|
||
void init(); | ||
void exec(); | ||
}; | ||
|
||
} // namespace MDAlgorithms | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_MDALGORITHMS_ConvertMDHistoToMDEventWorkspace_H_ */ |
134 changes: 134 additions & 0 deletions
134
Code/Mantid/Framework/MDAlgorithms/src/ConvertMDHistoToMDEventWorkspace.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#include "MantidMDAlgorithms/ConvertMDHistoToMDEventWorkspace.h" | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
|
||
#include "MantidDataObjects/MDEventFactory.h" | ||
#include "MantidDataObjects/MDEventInserter.h" | ||
#include "MantidGeometry/MDGeometry/MDHistoDimension.h" | ||
|
||
#include <boost/algorithm/string.hpp> | ||
#include <boost/algorithm/string/split.hpp> | ||
|
||
|
||
|
||
namespace Mantid { | ||
namespace MDAlgorithms { | ||
|
||
using namespace API; | ||
using namespace DataObjects; | ||
using namespace Geometry; | ||
using namespace Kernel; | ||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(ConvertMDHistoToMDEventWorkspace) | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
ConvertMDHistoToMDEventWorkspace::ConvertMDHistoToMDEventWorkspace() {} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
ConvertMDHistoToMDEventWorkspace::~ConvertMDHistoToMDEventWorkspace() {} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Algorithm's name for identification. @see Algorithm::name | ||
const std::string ConvertMDHistoToMDEventWorkspace::name() const { | ||
return "ConvertMDHistoToMDEventWorkspace"; | ||
} | ||
|
||
/// Algorithm's version for identification. @see Algorithm::version | ||
int ConvertMDHistoToMDEventWorkspace::version() const { return 1; } | ||
|
||
/// Algorithm's category for identification. @see Algorithm::category | ||
const std::string ConvertMDHistoToMDEventWorkspace::category() const { | ||
return "MDAlgorithms"; | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void ConvertMDHistoToMDEventWorkspace::init() { | ||
declareProperty(new WorkspaceProperty<API::IMDHistoWorkspace>( | ||
"InputWorkspace", "", Direction::Input), | ||
"An input IMDHistoWorkspace."); | ||
declareProperty(new WorkspaceProperty<IMDEventWorkspace>( | ||
"OutputWorkspace", "", Direction::Output), | ||
"An output workspace."); | ||
} | ||
|
||
/** | ||
Extracts mdevent information from the histo data and directs the creation of new | ||
DataObjects on the workspace. | ||
@param ws: Workspace to add the events to. | ||
*/ | ||
template <typename MDE, size_t nd> | ||
void ConvertMDHistoToMDEventWorkspace::addEventsData( | ||
typename MDEventWorkspace<MDE, nd>::sptr outWs) { | ||
/// Creates a new instance of the MDEventInserter. | ||
MDEventInserter<typename MDEventWorkspace<MDE, nd>::sptr> inserter(outWs); | ||
std::vector<Mantid::coord_t> centers(nd); | ||
|
||
for (size_t i = 0; i < m_nDataObjects; ++i) { | ||
float signal = static_cast<float>(ws->getSignalAt(i)); | ||
float error = static_cast<float>(ws->getErrorAt(i)); | ||
uint16_t run_no = 0; | ||
int32_t detector_no = 0; | ||
VMD boxCenter = ws->getCenter(i); | ||
for (size_t j = 0; j < m_nDimensions; ++j) { | ||
centers[j] = static_cast<float>(boxCenter[j]); | ||
} | ||
// Actually add the mdevent. | ||
inserter.insertMDEvent(signal, error * error, run_no, detector_no, | ||
centers.data()); | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void ConvertMDHistoToMDEventWorkspace::exec() { | ||
IMDHistoWorkspace_sptr inWS = getProperty("InputWorkspace"); | ||
|
||
ws = boost::dynamic_pointer_cast<MDHistoWorkspace>(inWS); | ||
if (!ws) | ||
throw std::runtime_error("InputWorkspace is not a MDHistoWorkspace"); | ||
|
||
// Calculate the dimensionality | ||
m_nDimensions = ws->getNumDims(); | ||
// Calculate the actual number of columns in the MDEvent data. | ||
uint64_t numPoints = ws->getNPoints(); | ||
m_nDataObjects = static_cast<size_t>(numPoints); | ||
|
||
// Create a target output workspace. | ||
IMDEventWorkspace_sptr outWs = MDEventFactory::CreateMDWorkspace( | ||
m_nDimensions, "MDLeanEvent"); | ||
if (ws->getNumExperimentInfo() > 0) { | ||
ExperimentInfo_sptr ei = ws->getExperimentInfo(0); | ||
outWs->addExperimentInfo(ei); | ||
} | ||
outWs->setCoordinateSystem(ws->getSpecialCoordinateSystem()); | ||
// Extract Dimensions and add to the output workspace. | ||
for (size_t i = 0; i < m_nDimensions; ++i) { | ||
IMDDimension_const_sptr dim = ws->getDimension(i); | ||
std::string id = dim->getDimensionId(); | ||
std::string name = dim->getName(); | ||
std::string units = dim->getUnits(); | ||
size_t nbins = dim->getNBins(); | ||
|
||
outWs->addDimension(MDHistoDimension_sptr(new MDHistoDimension( | ||
id, name, units, dim->getMinimum(), | ||
dim->getMaximum(), nbins))); | ||
} | ||
|
||
CALL_MDEVENT_FUNCTION(this->addEventsData, outWs) | ||
|
||
// set output | ||
this->setProperty("OutputWorkspace", outWs); | ||
} | ||
|
||
} // namespace Mantid | ||
} // namespace MDAlgorithms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.