-
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.
Add SaveDetectorMasks() to XML file. Code not finished. Refs #3622.
- Loading branch information
Showing
3 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveDetectorMasks.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,65 @@ | ||
#ifndef MANTID_DATAHANDLING_SAVEMASKINGTOFILE_H_ | ||
#define MANTID_DATAHANDLING_SAVEMASKINGTOFILE_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace DataHandling | ||
{ | ||
|
||
/** SaveMaskingToFile : TODO: DESCRIPTION | ||
@date 2011-11-09 | ||
Copyright © 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
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://svn.mantidproject.org/mantid/trunk/Code/Mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport SaveDetectorMasks : public API::Algorithm | ||
{ | ||
public: | ||
SaveDetectorMasks(); | ||
virtual ~SaveDetectorMasks(); | ||
|
||
/// Algorithm's name for identification | ||
virtual const std::string name() const { return "SaveDetectorMasks";}; | ||
/// Algorithm's version for identification | ||
virtual int version() const { return 1;}; | ||
/// Algorithm's category for identification | ||
virtual const std::string category() const { return "DataHandling";} | ||
|
||
private: | ||
|
||
virtual void initDocs(); | ||
|
||
/// Define input parameters | ||
void init(); | ||
|
||
/// Main body to execute algorithm | ||
void exec(); | ||
|
||
}; | ||
|
||
|
||
} // namespace DataHandling | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_DATAHANDLING_SAVEMASKINGTOFILE_H_ */ |
90 changes: 90 additions & 0 deletions
90
Code/Mantid/Framework/DataHandling/src/SaveDetectorMasks.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,90 @@ | ||
/*WIKI* | ||
This algorithm saves a SpecialWorkspace2D/MaskWorkspace to an XML file. | ||
*WIKI*/ | ||
|
||
#include "MantidDataHandling/SaveDetectorMasks.h" | ||
#include "MantidKernel/System.h" | ||
#include "MantidDataObjects/SpecialWorkspace2D.h" | ||
#include "MantidAPI/FileProperty.h" | ||
|
||
|
||
#include "Poco/DOM/Document.h" | ||
#include "Poco/DOM/Element.h" | ||
#include "Poco/DOM/Text.h" | ||
#include "Poco/DOM/AutoPtr.h" | ||
#include "Poco/DOM/DOMWriter.h" | ||
#include "Poco/XML/XMLWriter.h" | ||
|
||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
|
||
using namespace Poco::XML; | ||
|
||
namespace Mantid | ||
{ | ||
namespace DataHandling | ||
{ | ||
|
||
DECLARE_ALGORITHM(SaveDetectorMasks) | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
SaveDetectorMasks::SaveDetectorMasks() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
SaveDetectorMasks::~SaveDetectorMasks() | ||
{ | ||
} | ||
|
||
/// Sets documentation strings for this algorithm | ||
void SaveDetectorMasks::initDocs(){ | ||
this->setWikiSummary("Save a MaskWorkspace/SpecialWorkspace2D to an XML file."); | ||
this->setOptionalMessage("Save a MaskWorkspace/SpecialWorkspace2D to an XML file."); | ||
} | ||
|
||
/// Define input parameters | ||
void SaveDetectorMasks::init(){ | ||
|
||
declareProperty(new API::WorkspaceProperty<DataObjects::SpecialWorkspace2D>("InputWorkspace", "", Direction::Input), | ||
"MaskingWorkspace to output to XML file (SpecialWorkspace2D)"); | ||
declareProperty(new FileProperty("OutputFile", "", FileProperty::Save, ".xml"), | ||
"File to save the detectors mask in XML format"); | ||
|
||
} | ||
|
||
/// Main body to execute algorithm | ||
void SaveDetectorMasks::exec(){ | ||
// TODO This is a dummy prototype | ||
|
||
// 1. Create document and root node | ||
AutoPtr<Document> pDoc = new Document; | ||
AutoPtr<Element> pRoot = pDoc->createElement("root"); | ||
pDoc->appendChild(pRoot); | ||
|
||
// 2. Append child | ||
AutoPtr<Element> pChild1 = pDoc->createElement("child1"); | ||
AutoPtr<Text> pText1 = pDoc->createTextNode("text1"); | ||
pChild1->appendChild(pText1); | ||
pRoot->appendChild(pChild1); | ||
|
||
// 3. Write | ||
DOMWriter writer; | ||
writer.setNewLine("\n"); | ||
writer.setOptions(XMLWriter::PRETTY_PRINT); | ||
writer.writeNode(std::cout, pDoc); | ||
|
||
} | ||
|
||
|
||
} // namespace DataHandling | ||
} // namespace Mantid |
33 changes: 33 additions & 0 deletions
33
Code/Mantid/Framework/DataHandling/test/SaveDetectorMasksTest.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,33 @@ | ||
#ifndef MANTID_DATAHANDLING_SAVEMASKINGTOFILETEST_H_ | ||
#define MANTID_DATAHANDLING_SAVEMASKINGTOFILETEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
#include "MantidKernel/Timer.h" | ||
#include "MantidKernel/System.h" | ||
#include <iostream> | ||
#include <iomanip> | ||
|
||
#include "MantidDataHandling/SaveDetectorMasks.h" | ||
|
||
using namespace Mantid; | ||
using namespace Mantid::DataHandling; | ||
using namespace Mantid::API; | ||
|
||
class SaveDetectorMasksTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
// This pair of boilerplate methods prevent the suite being created statically | ||
// This means the constructor isn't called when running other tests | ||
static SaveDetectorMasks *createSuite() { return new SaveDetectorMasksTest(); } | ||
|
||
static void destroySuite( SaveMaskingToFileTest *suite ) { delete suite; } | ||
|
||
void test_Something() | ||
{ | ||
} | ||
|
||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_DATAHANDLING_SAVEMASKINGTOFILETEST_H_ */ |