/
UpdateInstrumentFromFile.h
140 lines (113 loc) · 4.95 KB
/
UpdateInstrumentFromFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef MANTID_DATAHANDLING_UPDATEINSTRUMENTFROMFILE_H_
#define MANTID_DATAHANDLING_UPDATEINSTRUMENTFROMFILE_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidGeometry/IDetector.h"
#include <nexus/NeXusFile.hpp>
namespace Mantid {
//----------------------------------------------------------------------
// Forward declarations
//----------------------------------------------------------------------
namespace Geometry {
class Instrument;
}
namespace DataHandling {
/**
Update detector positions initially loaded in from Instrument Defintion File
(IDF) from information in the provided files.
Note doing this will result in a slower performance (likely slightly slower
performance) compared to specifying the
correct detector positions in the IDF in the first place.
Note that this algorithm moves the detectors without subsequent rotation, hence
this means that detectors may not for
example face the sample perfectly after this algorithm has been applied.
Required Properties:
<UL>
<LI> Workspace - The name of the workspace </LI>
<LI> Filename - The name of and path to the input RAW file </LI>
</UL>
@author Martyn Gigg, Tessella plc
Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
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://github.com/mantidproject/mantid>
*/
class DLLExport UpdateInstrumentFromFile : public API::Algorithm {
public:
/// Default constructor
UpdateInstrumentFromFile();
/// Destructor
~UpdateInstrumentFromFile() override {}
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "UpdateInstrumentFromFile"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "Updates detector positions initially loaded in from the Instrument "
"Definition File (IDF) with information from the provided file.";
}
/// Algorithm's alias for the old UpdateInstrumentFromRaw
const std::string alias() const override { return "UpdateInstrumentFromRaw"; }
/// Algorithm's version for identification overriding a virtual method
int version() const override { return 1; };
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override {
return "DataHandling\\Instrument;DataHandling\\Raw";
}
private:
/// Overwrites Algorithm method. Does nothing at present
void init() override;
/// Overwrites Algorithm method
void exec() override;
/// Assumes the file is a raw file
void updateFromRaw(const std::string &filename);
/// Assumes the file is an ISIS NeXus file
void updateFromNeXus(::NeXus::File &nxFile);
/// Updates from a more generic ascii file
void updateFromAscii(const std::string &filename);
/**
* Simple structure to store information about the ASCII file header
*/
struct AsciiFileHeader {
AsciiFileHeader()
: colCount(0), rColIdx(0), thetaColIdx(0), phiColIdx(0) {
} // Zero is invalid as this is reserved for detID
size_t colCount;
size_t rColIdx, thetaColIdx, phiColIdx;
std::set<size_t> detParCols;
std::map<size_t, std::string> colToName;
};
/// Parse the header and fill the headerInfo struct
bool parseAsciiHeader(AsciiFileHeader &headerInfo);
/// Set a new detector parameter
void setDetectorParameter(const Geometry::IDetector_const_sptr &det,
const std::string &name, double value);
/// Set the new detector positions
void setDetectorPositions(const std::vector<int32_t> &detID,
const std::vector<float> &l2,
const std::vector<float> &theta,
const std::vector<float> &phi);
/// Set the new detector position for a single det ID
void setDetectorPosition(const Geometry::IDetector_const_sptr &det,
const float l2, const float theta, const float phi);
/// The input workspace to modify
API::MatrixWorkspace_sptr m_workspace;
/// Cached ignore phi
bool m_ignorePhi;
/// Cached ignore Monitors
bool m_ignoreMonitors;
};
} // namespace DataHandling
} // namespace Mantid
#endif /*MANTID_DATAHANDLING_UPDATEINSTRUMENTFROMFILE_H_*/