From 28366ec96cf9a7e8f508206aab71b17431129fc0 Mon Sep 17 00:00:00 2001 From: Janik Zikovsky <zikovskyjl@ornl.gov> Date: Thu, 31 Mar 2011 18:08:22 +0000 Subject: [PATCH] Refs #2660: Exposed more methods of EventWorkspace and EventList. Also threw PeaksWorkspace in there for later. --- .../Mantid/Framework/PythonAPI/CMakeLists.txt | 4 +- .../Framework/PythonAPI/MantidFramework.py | 12 ++++ .../MantidPythonAPI/FrameworkManagerProxy.h | 6 ++ .../PythonAPI/src/FrameworkManagerProxy.cpp | 37 ++++++++++ .../Framework/PythonAPI/src/api_exports.cpp | 70 ++++++++++++++++--- 5 files changed, 118 insertions(+), 11 deletions(-) diff --git a/Code/Mantid/Framework/PythonAPI/CMakeLists.txt b/Code/Mantid/Framework/PythonAPI/CMakeLists.txt index 0aa08611b0b..b6ba4cc2c3b 100644 --- a/Code/Mantid/Framework/PythonAPI/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonAPI/CMakeLists.txt @@ -106,9 +106,9 @@ endif () # to ensure that the stdc++ library appears as early in the link list as possible so that it # is loaded first, hence the hard coding of it here rather than leaving it to be implicitly defined. if ( UNIX ) - set ( PYTHON_DEPS stdc++ ${MANTIDLIBS} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ) + set ( PYTHON_DEPS stdc++ ${MANTIDLIBS} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} DataObjects ) else () - set ( PYTHON_DEPS ${MANTIDLIBS} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ) + set ( PYTHON_DEPS ${MANTIDLIBS} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} DataObjects ) endif () ########################################################################### diff --git a/Code/Mantid/Framework/PythonAPI/MantidFramework.py b/Code/Mantid/Framework/PythonAPI/MantidFramework.py index 5c0cf30bca7..4f666ac82a6 100644 --- a/Code/Mantid/Framework/PythonAPI/MantidFramework.py +++ b/Code/Mantid/Framework/PythonAPI/MantidFramework.py @@ -893,6 +893,13 @@ class MantidPyFramework(FrameworkManager): # 99% of the time people are using matrix workspaces but we still need to check # Try each workspace type in order, from more specialised to less specialised. + + # Try each workspace type in order, from more specialised to less specialised. + try: + return self._getRawEventWorkspacePointer(name) + except RuntimeError: + pass + try: return self._getRawIEventWorkspacePointer(name) except RuntimeError: @@ -919,6 +926,11 @@ class MantidPyFramework(FrameworkManager): except RuntimeError: pass + try: + return self._getRawPeaksWorkspacePointer(name) + except RuntimeError: + return None + try: return self._getRawTableWorkspacePointer(name) except RuntimeError: diff --git a/Code/Mantid/Framework/PythonAPI/inc/MantidPythonAPI/FrameworkManagerProxy.h b/Code/Mantid/Framework/PythonAPI/inc/MantidPythonAPI/FrameworkManagerProxy.h index 4a5071c1681..99491fe8c29 100644 --- a/Code/Mantid/Framework/PythonAPI/inc/MantidPythonAPI/FrameworkManagerProxy.h +++ b/Code/Mantid/Framework/PythonAPI/inc/MantidPythonAPI/FrameworkManagerProxy.h @@ -14,6 +14,8 @@ #include <MantidAPI/AnalysisDataService.h> #include <MantidAPI/AlgorithmFactory.h> #include <MantidAPI/IEventWorkspace.h> +#include <MantidDataObjects/EventWorkspace.h> +#include <MantidDataObjects/PeaksWorkspace.h> #include <MantidAPI/IMDWorkspace.h> #include <MantidAPI/IMDEventWorkspace.h> @@ -110,6 +112,10 @@ public: boost::shared_ptr<API::MatrixWorkspace> retrieveMatrixWorkspace(const std::string& wsName); /// Returns a pointer to the IEventWorkpace requested boost::shared_ptr<API::IEventWorkspace> retrieveIEventWorkspace(const std::string& wsName); + /// Returns a pointer to the Workpace requested + boost::shared_ptr<DataObjects::PeaksWorkspace> retrievePeaksWorkspace(const std::string& wsName); + /// Returns a pointer to the IEventWorkpace requested + boost::shared_ptr<DataObjects::EventWorkspace> retrieveEventWorkspace(const std::string& wsName); /// Returns a pointer to the IMDWorkspace requested boost::shared_ptr<API::IMDWorkspace> retrieveIMDWorkspace(const std::string& wsName); /// Returns a pointer to the IMDEventWorkspace requested diff --git a/Code/Mantid/Framework/PythonAPI/src/FrameworkManagerProxy.cpp b/Code/Mantid/Framework/PythonAPI/src/FrameworkManagerProxy.cpp index 3cca0377be4..fb6b8e03654 100644 --- a/Code/Mantid/Framework/PythonAPI/src/FrameworkManagerProxy.cpp +++ b/Code/Mantid/Framework/PythonAPI/src/FrameworkManagerProxy.cpp @@ -7,6 +7,7 @@ #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/MemoryManager.h" +#include "MantidDataObjects/EventWorkspace.h" #include "MantidKernel/ConfigService.h" #include "MantidKernel/Strings.h" #include "MantidPythonAPI/FrameworkManagerProxy.h" @@ -251,6 +252,42 @@ boost::shared_ptr<API::IEventWorkspace> FrameworkManagerProxy::retrieveIEventWor } } +/** Return pointer to PeaksWorkspace + * @param wsName :: The name of the workspace to retrieve. + * @return Shared pointer to workspace. + * @throw runtime_error if not of the right type + */ +boost::shared_ptr<DataObjects::PeaksWorkspace> FrameworkManagerProxy::retrievePeaksWorkspace(const std::string& wsName) +{ + DataObjects::PeaksWorkspace_sptr event = boost::dynamic_pointer_cast<DataObjects::PeaksWorkspace>(retrieveWorkspace(wsName)); + if (event != NULL) + { + return event; + } + else + { + throw std::runtime_error("\"" + wsName + "\" is not an peaks workspace. "); + } +} + +/** Return pointer to EventWorkspace + * @param wsName :: The name of the workspace to retrieve. + * @return Shared pointer to workspace. + * @throw runtime_error if not of the right type + */ +boost::shared_ptr<DataObjects::EventWorkspace> FrameworkManagerProxy::retrieveEventWorkspace(const std::string& wsName) +{ + DataObjects::EventWorkspace_sptr event = boost::dynamic_pointer_cast<DataObjects::EventWorkspace>(retrieveWorkspace(wsName)); + if (event != NULL) + { + return event; + } + else + { + throw std::runtime_error("\"" + wsName + "\" is not an event workspace. "); + } +} + /** Return pointer to IMDWorkspace * @param wsName :: The name of the workspace to retrieve. * @return Shared pointer to workspace. diff --git a/Code/Mantid/Framework/PythonAPI/src/api_exports.cpp b/Code/Mantid/Framework/PythonAPI/src/api_exports.cpp index 399bfaad1fd..e9e820db98c 100644 --- a/Code/Mantid/Framework/PythonAPI/src/api_exports.cpp +++ b/Code/Mantid/Framework/PythonAPI/src/api_exports.cpp @@ -18,6 +18,8 @@ #include <MantidAPI/WorkspaceProperty.h> #include <MantidAPI/WorkspaceValidators.h> #include <MantidGeometry/MDGeometry/IMDDimension.h> +#include <MantidDataObjects/EventWorkspace.h> +#include <MantidDataObjects/EventList.h> #include <MantidPythonAPI/PyAlgorithmWrapper.h> @@ -25,6 +27,7 @@ namespace Mantid { namespace PythonAPI { +using namespace DataObjects; using namespace API; using namespace Geometry; using namespace boost::python; @@ -65,6 +68,8 @@ using namespace boost::python; .def("getConfigProperty", &FrameworkManagerProxy::getConfigProperty) .def("releaseFreeMemory", &FrameworkManagerProxy::releaseFreeMemory) .def("_getRawIEventWorkspacePointer", &FrameworkManagerProxy::retrieveIEventWorkspace) + .def("_getRawEventWorkspacePointer", &FrameworkManagerProxy::retrieveEventWorkspace) + .def("_getRawPeaksWorkspacePointer", &FrameworkManagerProxy::retrievePeaksWorkspace) .def("_getRawIMDWorkspacePointer", &FrameworkManagerProxy::retrieveIMDWorkspace) .def("_getRawIMDEventWorkspacePointer", &FrameworkManagerProxy::retrieveIMDEventWorkspace) .def("_getRawMatrixWorkspacePointer", &FrameworkManagerProxy::retrieveMatrixWorkspace) @@ -254,15 +259,6 @@ using namespace boost::python; } - void export_eventworkspace() - { - register_ptr_to_python<API::IEventWorkspace_sptr>(); - - // EventWorkspace class - class_< IEventWorkspace, bases<API::MatrixWorkspace>, boost::noncopyable >("IEventWorkspace", no_init) - .def("getNumberEvents", &IEventWorkspace::getNumberEvents) - ; - } void export_IMDWorkspace() { @@ -292,6 +288,60 @@ using namespace boost::python; ; } + void export_PeaksWorkspace() + { + register_ptr_to_python<PeaksWorkspace_sptr>(); + + // PeaksWorkspace class + class_< PeaksWorkspace, bases<Workspace>, boost::noncopyable >("PeaksWorkspace", no_init) + ; + } + + void export_eventworkspace() + { + register_ptr_to_python<EventWorkspace_sptr>(); + + // EventWorkspace class + class_< EventWorkspace, bases<API::MatrixWorkspace>, boost::noncopyable >("EventWorkspace", no_init) + .def("getNumberEvents", &EventWorkspace::getNumberEvents) + .def("getEventList", (EventList&(EventWorkspace::*)(const int) ) &EventWorkspace::getEventList, return_internal_reference<>()) + ; + } + + void export_EventList() + { + register_ptr_to_python<EventList *>(); + + class_< EventList, boost::noncopyable >("EventList", no_init) + .def("getEventType", &EventList::getEventType) + .def("addDetectorID", &EventList::addDetectorID) + .def("hasDetectorID", &EventList::hasDetectorID) + .def("clear", &EventList::clear) + .def("reserve", &EventList::reserve) + .def("sort", &EventList::sort) + .def("isSortedByTof", &EventList::isSortedByTof) + .def("getSortType", &EventList::getSortType) + .def("getNumberEvents", &EventList::getNumberEvents) + .def("getMemorySize", &EventList::getMemorySize) + .def("compressEvents", &EventList::compressEvents) + .def("integrate", &EventList::integrate) + .def("convertTof", &EventList::convertTof) + .def("scaleTof", &EventList::scaleTof) + .def("addTof", &EventList::addTof) + .def("addPulsetime", &EventList::addPulsetime) + .def("maskTof", &EventList::maskTof) + .def("getTofs", &EventList::getTofs) + .def("getTofMin", &EventList::getTofMin) + .def("getTofMax", &EventList::getTofMax) + .def("setTofs", &EventList::setTofs) + .def("filterByPulseTime", &EventList::filterByPulseTime) + .def("multiply", (void(EventList::*)(const double,const double)) &EventList::multiply) + .def("divide", (void(EventList::*)(const double,const double)) &EventList::multiply) + .def("switchTo", &EventList::switchTo) +// .def("add", (EventList&(EventList::*)(const EventList&))&EventList::operator+=) + ; + } + void export_mdeventworkspace() { register_ptr_to_python<API::IMDEventWorkspace_sptr>(); @@ -515,6 +565,8 @@ using namespace boost::python; export_apivalidators(); export_file_finder(); export_IMDDimension(); + export_EventList(); + export_PeaksWorkspace(); } //@endcond -- GitLab