-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #4333. Export FileFinder and Sample classes to Python.
- Loading branch information
1 parent
ae614cc
commit 683b65a
Showing
8 changed files
with
97 additions
and
7 deletions.
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
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
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
23 changes: 23 additions & 0 deletions
23
Code/Mantid/Framework/PythonInterface/mantid/api/src/FileFinder.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,23 @@ | ||
#include "MantidAPI/FileFinder.h" | ||
#include <boost/python/class.hpp> | ||
#include <boost/python/reference_existing_object.hpp> | ||
|
||
using Mantid::API::FileFinder; | ||
using Mantid::API::FileFinderImpl; | ||
using namespace boost::python; | ||
|
||
void export_FileFinder() | ||
{ | ||
class_<FileFinderImpl, boost::noncopyable>("FileFinder", no_init) | ||
.def("Instance", &FileFinder::Instance, return_value_policy<reference_existing_object>(), | ||
"Returns a reference to the FileFinder singleton instance") | ||
.staticmethod("Instance") | ||
.def("getFullPath", &FileFinderImpl::getFullPath, | ||
"Return a full path to the given file if it can be found within datasearch.directories paths. " | ||
"An empty string is returned otherwise.") | ||
.def("findRuns", &FileFinderImpl::findRuns, "Find a list of files file given a hint. " | ||
"The hint can be a comma separated list of run numbers and can also include ranges of runs, e.g. 123-135 or equivalently 123-35" | ||
"If no instrument prefix is given then the current default is used.") | ||
; | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
Code/Mantid/Framework/PythonInterface/mantid/api/src/Sample.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,33 @@ | ||
#include "MantidAPI/Sample.h" | ||
#include "MantidGeometry/Crystal/OrientedLattice.h" | ||
#include <boost/python/class.hpp> | ||
#include <boost/python/copy_const_reference.hpp> | ||
#include <boost/python/register_ptr_to_python.hpp> | ||
|
||
using Mantid::API::Sample; | ||
using Mantid::Geometry::OrientedLattice; | ||
using namespace boost::python; | ||
|
||
void export_Sample() | ||
{ | ||
register_ptr_to_python<Sample*>(); | ||
register_ptr_to_python<boost::shared_ptr<Sample> >(); | ||
|
||
|
||
class_< Sample, boost::noncopyable >("Sample", no_init) | ||
.def("getName", &Sample::getName, return_value_policy<copy_const_reference>(), "Returns the string name of the sample") | ||
.def("getOrientedLattice", (const OrientedLattice & (Sample::*)() const)&Sample::getOrientedLattice, | ||
return_value_policy<copy_const_reference>(), "Get the oriented lattice for this sample") | ||
.def("hasOrientedLattice", &Sample::hasOrientedLattice, "Returns True if this sample has an oriented lattice, false otherwise") | ||
.def("size", &Sample::size, "Return the number of samples contained within this sample") | ||
// Required for ISIS SANS reduction until the full sample geometry is defined on loading | ||
.def("getGeometryFlag", &Sample::getGeometryFlag, "Return the geometry flag.") | ||
.def("getThickness", &Sample::getThickness, "Return the thickness in mm") | ||
.def("getHeight", &Sample::getHeight, "Return the height in mm") | ||
.def("getWidth", &Sample::getWidth, "Return the width in mm") | ||
// -------------------------Operators ------------------------------------- | ||
.def("__len__", &Sample::size) | ||
.def("__getitem__", &Sample::operator[], return_internal_reference<>()) | ||
; | ||
} | ||
|
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
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
17 changes: 17 additions & 0 deletions
17
Code/Mantid/Framework/PythonInterface/test/python/FileFinderTest.py
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,17 @@ | ||
import unittest | ||
from mantid.api import FileFinder | ||
import os | ||
|
||
class FileFinderTest(unittest.TestCase): | ||
|
||
def test_full_path_returns_an_absolute_path_and_the_files_exists(self): | ||
path = FileFinder.Instance().getFullPath("CNCS_7860_event.nxs") | ||
self.assertTrue(len(path) > 0) | ||
# We can't be sure what the full path is in general but it should certainly exist! | ||
self.assertTrue(os.path.exists(path)) | ||
|
||
def test_find_runs_returns_absolute_paths_of_given_runs(self): | ||
runs = FileFinder.Instance().findRuns("CNCS7860") | ||
self.assertTrue(len(runs) == 1) | ||
# We can't be sure what the full path is in general but it should certainly exist! | ||
self.assertTrue(os.path.exists(runs[0])) |