-
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.
Merge remote-tracking branch 'origin/feature/6212_grouping_functions_…
…in_mask_tab' Refs #6212 Conflicts: Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp
- Loading branch information
Showing
19 changed files
with
605 additions
and
401 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
102 changes: 102 additions & 0 deletions
102
Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/DetXMLFile.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,102 @@ | ||
#include "DetXMLFile.h" | ||
|
||
#include <QTemporaryFile> | ||
#include <QDir> | ||
|
||
#include <fstream> | ||
|
||
/** | ||
* Create a grouping file to extract all detectors in detector_list excluding those in exclude. | ||
* @param detector_list :: List of detector ids to include in the grouping file. | ||
* @param exclude :: List of detector ids which if founfd in detector_list to be excluded from grouping. | ||
* @param fname :: Name of the file to save the grouping to. | ||
*/ | ||
DetXMLFile::DetXMLFile(const std::vector<int>& detector_list, const QList<int>& exclude, const QString& fname) | ||
{ | ||
m_fileName = fname; | ||
m_delete = false; | ||
std::ofstream out(m_fileName.toStdString().c_str()); | ||
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping> \n"; | ||
out << "<group name=\"sum\"> <detids val=\""; | ||
std::vector<int>::const_iterator idet = detector_list.begin(); | ||
for(; idet != detector_list.end(); ++idet) | ||
{ | ||
if (!exclude.contains(*idet)) | ||
{ | ||
out << *idet << ','; | ||
} | ||
} | ||
out << "\"/> </group> \n</detector-grouping>\n"; | ||
} | ||
|
||
/** | ||
* Create a grouping file to extract detectors in dets. Option List - one group - one detector, | ||
* Option Sum - one group which is a sum of the detectors | ||
* If fname is empty create a temporary file | ||
*/ | ||
DetXMLFile::DetXMLFile(const QList<int>& dets, Option opt, const QString& fname) | ||
{ | ||
if (dets.empty()) | ||
{ | ||
m_fileName = ""; | ||
return; | ||
} | ||
|
||
if (fname.isEmpty()) | ||
{ | ||
QTemporaryFile mapFile; | ||
mapFile.open(); | ||
m_fileName = mapFile.fileName() + ".xml"; | ||
mapFile.close(); | ||
m_delete = true; | ||
} | ||
else | ||
{ | ||
m_fileName = fname; | ||
m_delete = false; | ||
} | ||
|
||
switch(opt) | ||
{ | ||
case Sum: makeSumFile(dets); break; | ||
case List: makeListFile(dets); break; | ||
} | ||
} | ||
|
||
/// Make grouping file where each detector is put into its own group | ||
void DetXMLFile::makeListFile(const QList<int>& dets) | ||
{ | ||
std::ofstream out(m_fileName.toStdString().c_str()); | ||
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping> \n"; | ||
foreach(int det,dets) | ||
{ | ||
out << "<group name=\"" << det << "\"> <detids val=\"" << det << "\"/> </group> \n"; | ||
} | ||
out << "</detector-grouping>\n"; | ||
} | ||
|
||
/// Make grouping file for putting the detectors into one group (summing the detectors) | ||
void DetXMLFile::makeSumFile(const QList<int>& dets) | ||
{ | ||
std::ofstream out(m_fileName.toStdString().c_str()); | ||
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping> \n"; | ||
out << "<group name=\"sum\"> <detids val=\""; | ||
foreach(int det,dets) | ||
{ | ||
out << det << ','; | ||
} | ||
out << "\"/> </group> \n</detector-grouping>\n"; | ||
} | ||
|
||
/** | ||
* Destructor. Removes the temporary file. | ||
*/ | ||
DetXMLFile::~DetXMLFile() | ||
{ | ||
if (m_delete) | ||
{ | ||
QDir dir; | ||
dir.remove(m_fileName); | ||
} | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/DetXMLFile.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,43 @@ | ||
#ifndef DETXMLFILE_H | ||
#define DETXMLFILE_H | ||
|
||
#include <QString> | ||
#include <QList> | ||
|
||
#include <vector> | ||
|
||
/** | ||
A class for creating grouping xml files | ||
*/ | ||
class DetXMLFile | ||
{ | ||
public: | ||
enum Option {List,Sum}; | ||
/// Create a grouping file to extract all detectors in detector_list excluding those in exclude | ||
DetXMLFile(const std::vector<int>& detector_list, const QList<int>& exclude, const QString& fname); | ||
|
||
/// Create a grouping file to extract detectors in dets. Option List - one group - one detector, | ||
/// Option Sum - one group which is a sum of the detectors | ||
/// If fname is empty create a temporary file | ||
DetXMLFile(const QList<int>& dets, Option opt = List, const QString& fname = ""); | ||
|
||
/// Destructor | ||
~DetXMLFile(); | ||
|
||
/// Make grouping file where each detector is put into its own group | ||
void makeListFile(const QList<int>& dets); | ||
|
||
/// Make grouping file for putting the detectors into one group (summing the detectors) | ||
void makeSumFile(const QList<int>& dets); | ||
|
||
/// Return the name of the created grouping file | ||
const std::string operator()()const{return m_fileName.toStdString();} | ||
|
||
private: | ||
QString m_fileName; ///< holds the grouping file name | ||
bool m_delete; ///< if true delete the file on destruction | ||
}; | ||
|
||
#endif // DETXMLFILE_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
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
Oops, something went wrong.