Newer
Older
Gigg, Martyn Anthony
committed
#include "MantidDataObjects/GroupingWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/SpectraAxis.h"
using Mantid::API::SpectraAxis;
using namespace Mantid::API;
Gigg, Martyn Anthony
committed
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
namespace Mantid {
namespace DataObjects {
// Register the workspace
DECLARE_WORKSPACE(GroupingWorkspace)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
GroupingWorkspace::GroupingWorkspace() {}
/** Constructor, buiding with give dimensions
* @param numvectors: input size of the vector/histogram number for this
* workspace
* @return created GroupingWorkspace
*/
GroupingWorkspace::GroupingWorkspace(size_t numvectors) {
this->init(numvectors, 1, 1);
}
//----------------------------------------------------------------------------------------------
/** Constructor, building from an instrument
*
* @param inst :: input instrument that is the base for this workspace
* @return created GroupingWorkspace
*/
GroupingWorkspace::GroupingWorkspace(Geometry::Instrument_const_sptr inst)
: SpecialWorkspace2D(inst) {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
GroupingWorkspace::~GroupingWorkspace() {}
//----------------------------------------------------------------------------------------------
/** Fill a map with key = detector ID, value = group number
* by using the values in Y.
* Group values of 0 are converted to -1.
*
* @param detIDToGroup :: ref. to map to fill
* @param[out] ngroups :: the number of groups found (equal to the largest group
*number found)
*/
void GroupingWorkspace::makeDetectorIDToGroupMap(
std::map<detid_t, int> &detIDToGroup, int64_t &ngroups) const {
ngroups = 0;
for (size_t wi = 0; wi < this->m_noVectors; ++wi) {
// Convert the Y value to a group number
int group = static_cast<int>(this->readY(wi)[0]);
if (group == 0)
group = -1;
std::set<detid_t> detIDs = this->getDetectorIDs(wi);
for (auto detID = detIDs.begin(); detID != detIDs.end(); ++detID) {
detIDToGroup[*detID] = group;
if (group > ngroups)
ngroups = group;
Janik Zikovsky
committed
}
}
}
/**
* Fill a map where the index is detector ID and the value is the
* group number by using the values in Y.
* Group values of 0 are converted to -1.
*
* @param detIDToGroup :: ref. to map to fill
* @param[out] ngroups :: the number of groups found (equal to the largest group
*number found)
*/
void
GroupingWorkspace::makeDetectorIDToGroupVector(std::vector<int> &detIDToGroup,
int64_t &ngroups) const {
ngroups = 0;
for (size_t wi = 0; wi < this->m_noVectors; ++wi) {
// Convert the Y value to a group number
int group = static_cast<int>(this->readY(wi)[0]);
if (group == 0)
group = -1;
std::set<detid_t> detIDs = this->getDetectorIDs(wi);
for (auto detID = detIDs.begin(); detID != detIDs.end(); ++detID) {
if ((*detID) <
0) // if you need negative detector ids, use the other function
continue;
if (detIDToGroup.size() < static_cast<size_t>((*detID) + 1))
detIDToGroup.resize((*detID) + 1);
detIDToGroup[*detID] = group;
if (group > ngroups)
ngroups = group;
Gigg, Martyn Anthony
committed
} // namespace Mantid
} // namespace DataObjects
Janik Zikovsky
committed
///\cond TEMPLATE
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
141
142
143
namespace Mantid {
namespace Kernel {
template <>
DLLExport Mantid::DataObjects::GroupingWorkspace_sptr
IPropertyManager::getValue<Mantid::DataObjects::GroupingWorkspace_sptr>(
const std::string &name) const {
PropertyWithValue<Mantid::DataObjects::GroupingWorkspace_sptr> *prop =
dynamic_cast<
PropertyWithValue<Mantid::DataObjects::GroupingWorkspace_sptr> *>(
getPointerToProperty(name));
if (prop) {
return *prop;
} else {
std::string message = "Attempt to assign property " + name +
" to incorrect type. Expected GroupingWorkspace.";
throw std::runtime_error(message);
}
}
template <>
DLLExport Mantid::DataObjects::GroupingWorkspace_const_sptr
IPropertyManager::getValue<Mantid::DataObjects::GroupingWorkspace_const_sptr>(
const std::string &name) const {
PropertyWithValue<Mantid::DataObjects::GroupingWorkspace_sptr> *prop =
dynamic_cast<
PropertyWithValue<Mantid::DataObjects::GroupingWorkspace_sptr> *>(
getPointerToProperty(name));
if (prop) {
return prop->operator()();
} else {
std::string message =
"Attempt to assign property " + name +
" to incorrect type. Expected const GroupingWorkspace.";
throw std::runtime_error(message);
}
}
Janik Zikovsky
committed
Janik Zikovsky
committed
} // namespace Mantid
///\endcond TEMPLATE