Mantid
Loading...
Searching...
No Matches
ConvToMDSelector.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 +
8
14
15namespace Mantid::MDAlgorithms {
16// workspaces which currently can be converted to md workspaces:
17enum wsType {
18 Matrix2DWS, //< Workspace2D
19 EventWS, //< event workspace
20 Undefined //< unknown initial state
21};
22
24
33std::shared_ptr<ConvToMDBase> ConvToMDSelector::convSelector(const API::MatrixWorkspace_sptr &inputWS,
34 std::shared_ptr<ConvToMDBase> &currentSolver) const {
35 // identify what kind of workspace we expect to process
36 wsType inputWSType = Undefined;
37 if (std::dynamic_pointer_cast<DataObjects::EventWorkspace>(inputWS))
38 inputWSType = EventWS;
39 if (std::dynamic_pointer_cast<DataObjects::Workspace2D>(inputWS))
40 inputWSType = Matrix2DWS;
41
42 if (inputWSType == Undefined)
43 throw(std::invalid_argument("ConvToDataObjectsSelector::got a workspace which "
44 "is neither matrix nor event workspace; Can "
45 "not deal with it"));
46
47 // identify what converter (if any) is currently initialized;
48 wsType existingWsConvType(Undefined);
49 ConvToMDBase *pSolver = currentSolver.get();
50 if (pSolver) {
51 if (dynamic_cast<ConvToMDEventsWS *>(pSolver))
52 existingWsConvType = EventWS;
53 if (dynamic_cast<ConvToMDHistoWS *>(pSolver))
54 existingWsConvType = Matrix2DWS;
55 }
56
57 std::shared_ptr<ConvToMDBase> res;
58 // select a converter, which corresponds to the workspace type
59 if ((existingWsConvType == Undefined) || (existingWsConvType != inputWSType)) {
60 switch (inputWSType) {
61 case (EventWS):
62 // check if user set a property to use indexing
64 res = std::make_shared<ConvToMDEventsWS>();
65 else
66 res = std::make_shared<ConvToMDEventsWSIndexing>();
67 break;
68 case (Matrix2DWS):
69 res = std::make_shared<ConvToMDHistoWS>();
70 break;
71 default:
72 throw(std::logic_error("ConvToDataObjectsSelector: requested converter "
73 "for unknown ws type"));
74 }
75 } else {
76 // existing converter is suitable for the workspace
77 // in case of Event workspace check if user set a property to use indexing
78 if (inputWSType == EventWS) {
80 res = std::make_shared<ConvToMDEventsWS>();
81 else
82 res = std::make_shared<ConvToMDEventsWSIndexing>();
83 } else {
84 res = std::make_shared<ConvToMDHistoWS>();
85 }
86 }
87
88 return res;
89}
90} // namespace Mantid::MDAlgorithms
static std::unique_ptr< QThreadPool > tp
Class describes the interface to the methods, which perform conversion from usual workspaces to MDEve...
Definition: ConvToMDBase.h:34
The class specializes ConvToDataObjectsBase for the case when the conversion occurs from Events WS to...
The class to transform matrix workspace into MDEvent workspace when matrix workspace is ragged 2D wor...
std::shared_ptr< ConvToMDBase > convSelector(const API::MatrixWorkspace_sptr &inputWS, std::shared_ptr< ConvToMDBase > &currentSolver) const
function which selects the convertor depending on workspace type and (possibly, in a future) some wor...
ConvToMDSelector(ConverterType tp=DEFAULT)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class