Skip to content

Commit

Permalink
Python export checkGroups. Refs #9353
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici committed Apr 22, 2014
1 parent 36c860d commit 495cb1a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h
Expand Up @@ -273,6 +273,8 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag
boost::shared_ptr<Algorithm> createChildAlgorithm(const std::string& name, const double startProgress = -1.,
const double endProgress = -1., const bool enableLogging=true, const int& version = -1);

virtual bool checkGroups();

protected:

/// Virtual method - must be overridden by concrete algorithm
Expand Down Expand Up @@ -322,7 +324,7 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag
static size_t g_execCount; ///< Counter to keep track of algorithm execution order

// ------------------ For WorkspaceGroups ------------------------------------
virtual bool checkGroups();

virtual bool processGroups();
virtual void setOtherProperties(IAlgorithm * alg, const std::string & propertyName, const std::string & propertyValue, int periodNum);
typedef std::vector<boost::shared_ptr<Workspace> > WorkspaceVector;
Expand Down
Expand Up @@ -67,6 +67,8 @@ namespace Mantid
virtual bool isRunning() const;
/// Allow the cancel method to be overridden
virtual void cancel();
virtual bool checkGroups();
bool checkGroupsDefault();
/// Returns the validateInputs result of the algorithm.
std::map<std::string, std::string> validateInputs();
///@}
Expand Down
Expand Up @@ -51,6 +51,7 @@ void export_leaf_classes()
.def("fromString", &Algorithm::fromString, "Initialize the algorithm from a string representation")
.staticmethod("fromString")

.def("checkGroups",&PythonAlgorithm::checkGroups,"process groups ")
.def("setOptionalMessage", &Algorithm::setOptionalMessage)
.def("createChildAlgorithm", &Algorithm::createChildAlgorithm,
(arg("name"),arg("startProgress")=-1.0,arg("endProgress")=-1.0,
Expand Down
Expand Up @@ -66,6 +66,26 @@ namespace Mantid
return 1;
}

/**
* Returns the version of the algorithm. If not overridden
* it returns 1
*/
template<typename BaseAlgorithm>
bool AlgorithmAdapter<BaseAlgorithm>::checkGroups()
{
return CallMethod0<bool>::dispatchWithDefaultReturn(getSelf(), "checkGroups", checkGroupsDefault());
}

/**
* Returns the default version of the algorithm. If not overridden
* it returns 1
*/
template<typename BaseAlgorithm>
bool AlgorithmAdapter<BaseAlgorithm>::checkGroupsDefault()
{
return true;
}

/**
* Returns the category of the algorithm. If not overridden
* it returns "AlgorithmAdapter"
Expand Down
Expand Up @@ -16,6 +16,9 @@ def name(self):
""" Algorithm name
"""
return "SavePlot1D"

def checkGroups(self):
return False

def PyInit(self):
self.setWikiSummary("Save 1D plots to a file")
Expand All @@ -30,10 +33,11 @@ def PyExec(self):
self._wksp = self.getProperty("InputWorkspace").value
if type(self._wksp)==mantid.api._api.WorkspaceGroup:
for i in range(self._wksp.getNumberOfEntries()):
plt.subplot(self._wksp.getNumberOfEntries(),1,i)
plt.subplot(self._wksp.getNumberOfEntries(),1,i+1)
self.DoPlot(self._wksp.getItem(i))
else:
self.DoPlot(self._wksp)
plt.tight_layout(1.08)
plt.show()
filename = self.getProperty("OutputFilename").value
plt.savefig(filename,bbox_inches='tight')
Expand Down

0 comments on commit 495cb1a

Please sign in to comment.