Mantid
Loading...
Searching...
No Matches
GroupingWorkspace.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#include <utility>
8
13#include "MantidKernel/System.h"
14
15using std::size_t;
16using namespace Mantid::API;
17
18namespace Mantid::DataObjects {
19// Register the workspace
21
22
27GroupingWorkspace::GroupingWorkspace(size_t numvectors) { this->init(numvectors, 1, 1); }
28
29//----------------------------------------------------------------------------------------------
36
37//----------------------------------------------------------------------------------------------
46void GroupingWorkspace::makeDetectorIDToGroupMap(std::map<detid_t, int> &detIDToGroup, int64_t &ngroups) const {
47 ngroups = 0;
48 for (size_t wi = 0; wi < getNumberHistograms(); ++wi) {
49 // Convert the Y value to a group number
50 auto group = static_cast<int>(this->readY(wi)[0]);
51 if (group == 0)
52 group = -1;
53 auto detIDs = this->getDetectorIDs(wi);
54 for (auto detID : detIDs) {
55 detIDToGroup[detID] = group;
56 if (group > ngroups)
57 ngroups = group;
58 }
59 }
60}
61
71void GroupingWorkspace::makeDetectorIDToGroupVector(std::vector<int> &detIDToGroup, int64_t &ngroups) const {
72 ngroups = 0;
73 for (size_t wi = 0; wi < getNumberHistograms(); ++wi) {
74 // Convert the Y value to a group number
75 auto group = static_cast<int>(this->y(wi).front());
76 if (group == 0)
77 group = -1;
78 auto detIDs = this->getDetectorIDs(wi);
79 for (auto detID : detIDs) {
80 // if you need negative detector ids, use the other function
81 if (detID < 0)
82 continue;
83 if (detIDToGroup.size() < static_cast<size_t>(detID + 1))
84 detIDToGroup.resize(detID + 1);
85 detIDToGroup[detID] = group;
86 if (group > ngroups)
87 ngroups = group;
88 }
89 }
90}
91
92} // namespace Mantid::DataObjects
93
95
96namespace Mantid::Kernel {
97
98template <>
100IPropertyManager::getValue<Mantid::DataObjects::GroupingWorkspace_sptr>(const std::string &name) const {
101 auto *prop =
102 dynamic_cast<PropertyWithValue<Mantid::DataObjects::GroupingWorkspace_sptr> *>(getPointerToProperty(name));
103 if (prop) {
104 return *prop;
105 } else {
106 std::string message =
107 "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<GroupingWorkspace>.";
108 throw std::runtime_error(message);
109 }
110}
111
112template <>
114IPropertyManager::getValue<Mantid::DataObjects::GroupingWorkspace_const_sptr>(const std::string &name) const {
115 auto *prop =
116 dynamic_cast<PropertyWithValue<Mantid::DataObjects::GroupingWorkspace_sptr> *>(getPointerToProperty(name));
117 if (prop) {
118 return prop->operator()();
119 } else {
120 std::string message =
121 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<GroupingWorkspace>.";
122 throw std::runtime_error(message);
123 }
124}
125
126} // namespace Mantid::Kernel
127
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
#define DECLARE_WORKSPACE(classname)
const MantidVec & readY(std::size_t const index) const
Deprecated, use y() instead.
A GroupingWorkspace is a subclass of Workspace2D where each spectrum has a single number entry,...
void makeDetectorIDToGroupVector(std::vector< int > &detIDToGroup, int64_t &ngroups) const
Fill a map where the index is detector ID and the value is the group number by using the values in Y.
void makeDetectorIDToGroupMap(std::map< detid_t, int > &detIDToGroup, int64_t &ngroups) const
Fill a map with key = detector ID, value = group number by using the values in Y.
std::set< detid_t > getDetectorIDs(const std::size_t workspaceIndex) const
Return the detector ID at the given workspace index (i.e., spectrum/histogram index)
std::size_t getNumberHistograms() const override
Returns the histogram number.
The concrete, templated class for properties.
std::shared_ptr< const GroupingWorkspace > GroupingWorkspace_const_sptr
shared pointer to a const GroupingWorkspace
std::shared_ptr< GroupingWorkspace > GroupingWorkspace_sptr
shared pointer to the GroupingWorkspace class
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.