Mantid
Loading...
Searching...
No Matches
SaveNexusProcessed.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// SaveNexusProcessed
8// @author Ronald Fowler, based on SaveNexus
23#include <memory>
24#include <utility>
25
26using namespace Mantid::API;
27
28namespace Mantid::DataHandling {
29
30using namespace Kernel;
31using namespace API;
32using namespace DataObjects;
34
36
37// Register the algorithm into the algorithm factory
39
40namespace {
41
57bool makeMappings(const MatrixWorkspace &ws, const std::vector<int> &ws_indices,
58 std::vector<int32_t> &out_detector_index, std::vector<int32_t> &out_detector_count,
59 std::vector<int32_t> &out_detector_list, int &numberSpec, size_t &numberDetectors) {
60
61 // Count the total number of detectors
62 numberDetectors = 0;
63 for (auto index : ws_indices) {
64 numberDetectors += ws.getSpectrum(static_cast<size_t>(index)).getDetectorIDs().size();
65 }
66 if (numberDetectors < 1) {
67 return false;
68 }
69 // Start the detector group
70
71 numberSpec = int(ws_indices.size());
72 // allocate space for the Nexus Muon format of spectra-detector mapping
73 // allow for writing one more than required
74 out_detector_index.resize(numberSpec + 1, 0);
75 out_detector_count.resize(numberSpec, 0);
76 out_detector_list.resize(numberDetectors, 0);
77 int id = 0;
78
79 // get data from map into Nexus Muon format
80 for (int i = 0; i < numberSpec; i++) {
81 // Workspace index
82 const int si = ws_indices[i];
83 // Spectrum there
84 const auto &spectrum = ws.getSpectrum(si);
85
86 // The detectors in this spectrum
87 const auto &detectorgroup = spectrum.getDetectorIDs();
88 const auto ndet1 = static_cast<int>(detectorgroup.size());
89
90 // points to start of detector list for the next spectrum
91 out_detector_index[i + 1] = int32_t(out_detector_index[i] + ndet1);
92 out_detector_count[i] = int32_t(ndet1);
93
94 std::set<detid_t>::const_iterator it;
95 for (it = detectorgroup.begin(); it != detectorgroup.end(); ++it) {
96 out_detector_list[id++] = int32_t(*it);
97 }
98 }
99 // Cut the extra entry at the end of detector_index
100 out_detector_index.resize(numberSpec);
101 return true;
102}
103
104} // namespace
105
110 declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("InputWorkspace", "", Direction::Input),
111 "Name of the workspace to be saved");
112 // Declare required input parameters for algorithm
113 const std::vector<std::string> fileExts{".nxs", ".nx5", ".xml"};
114 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Save, fileExts),
115 "The name of the Nexus file to write, as a full or relative\n"
116 "path");
117
118 // Declare optional parameters (title now optional, was mandatory)
119 declareProperty("Title", "", std::make_shared<NullValidator>(), "A title to describe the saved workspace");
120 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
121 mustBePositive->setLower(0);
122
123 declareProperty("WorkspaceIndexMin", 0, mustBePositive,
124 "Index number of first spectrum to write, only for single\n"
125 "period data.");
126 declareProperty("WorkspaceIndexMax", Mantid::EMPTY_INT(), mustBePositive,
127 "Index of last spectrum to write, only for single period\n"
128 "data.");
129 declareProperty(std::make_unique<ArrayProperty<int>>("WorkspaceIndexList"),
130 "List of spectrum numbers to read, only for single period\n"
131 "data.");
132
133 declareProperty("Append", false,
134 "Determines whether .nxs file needs to be\n"
135 "over written or appended");
136
137 declareProperty("PreserveEvents", true,
138 "For EventWorkspaces, preserve the events when saving (default).\n"
139 "If false, will save the 2D histogram version of the workspace with the "
140 "current binning parameters.");
141 setPropertySettings("PreserveEvents",
142 std::make_unique<EnabledWhenWorkspaceIsType<EventWorkspace>>("InputWorkspace", true));
143
144 declareProperty("CompressNexus", false,
145 "For EventWorkspaces, compress the Nexus data field (default False).\n"
146 "This will make smaller files but takes much longer.");
147 setPropertySettings("CompressNexus",
148 std::make_unique<EnabledWhenWorkspaceIsType<EventWorkspace>>("InputWorkspace", true));
149}
150
156void SaveNexusProcessed::getWSIndexList(std::vector<int> &indices, const MatrixWorkspace_const_sptr &matrixWorkspace) {
157 const std::vector<int> spec_list = getProperty("WorkspaceIndexList");
158 int spec_min = getProperty("WorkspaceIndexMin");
159 int spec_max = getProperty("WorkspaceIndexMax");
160 const bool list = !spec_list.empty();
161 const bool interval = (spec_max != Mantid::EMPTY_INT());
162 if (spec_max == Mantid::EMPTY_INT())
163 spec_max = 0;
164 const auto numberOfHist = static_cast<int>(matrixWorkspace->getNumberHistograms());
165
166 if (interval) {
167 if (spec_max < spec_min || spec_max > numberOfHist - 1) {
168 g_log.error("Invalid WorkspaceIndex min/max properties");
169 throw std::invalid_argument("Inconsistent properties defined");
170 }
171 indices.reserve(1 + spec_max - spec_min);
172 for (int i = spec_min; i <= spec_max; i++)
173 indices.emplace_back(i);
174 if (list) {
175 for (auto s : spec_list) {
176 if (s < 0)
177 continue;
178 if (s < spec_min || s > spec_max)
179 indices.emplace_back(s);
180 }
181 }
182 } else if (list) {
183 spec_max = 0;
184 spec_min = numberOfHist - 1;
185 for (auto s : spec_list) {
186 if (s < 0)
187 continue;
188 indices.emplace_back(s);
189 if (s > spec_max)
190 spec_max = s;
191 if (s < spec_min)
192 spec_min = s;
193 }
194 } else {
195 spec_min = 0;
196 spec_max = numberOfHist - 1;
197 indices.reserve(1 + spec_max - spec_min);
198 for (int i = spec_min; i <= spec_max; i++)
199 indices.emplace_back(i);
200 }
201}
202
204 std::shared_ptr<Mantid::NeXus::NexusFileIO> &nexusFile, const bool keepFile,
205 optional_size_t entryNumber) {
206 // TODO: Remove?
207 NXMEnableErrorReporting();
208
209 // Retrieve the filename from the properties
210 const std::string filename = getPropertyValue("Filename");
211 std::string title = getPropertyValue("Title");
212 // Do we preserve events?
213 const bool PreserveEvents = getProperty("PreserveEvents");
214
215 MatrixWorkspace_const_sptr matrixWorkspace = std::dynamic_pointer_cast<const MatrixWorkspace>(inputWorkspace);
216 ITableWorkspace_const_sptr tableWorkspace = std::dynamic_pointer_cast<const ITableWorkspace>(inputWorkspace);
217 IPeaksWorkspace_const_sptr peaksWorkspace = std::dynamic_pointer_cast<const IPeaksWorkspace>(inputWorkspace);
218 OffsetsWorkspace_const_sptr offsetsWorkspace = std::dynamic_pointer_cast<const OffsetsWorkspace>(inputWorkspace);
219 MaskWorkspace_const_sptr maskWorkspace = std::dynamic_pointer_cast<const MaskWorkspace>(inputWorkspace);
220 if (peaksWorkspace)
221 g_log.debug("We have a peaks workspace");
222 // check if inputWorkspace is something we know how to save
223 if (!matrixWorkspace && !tableWorkspace) {
224 // get the workspace name for the error message
225 const std::string name = getProperty("InputWorkspace");
226
227 // md workspaces should be saved using SaveMD
228 if (bool(std::dynamic_pointer_cast<const IMDEventWorkspace>(inputWorkspace)) ||
229 bool(std::dynamic_pointer_cast<const IMDHistoWorkspace>(inputWorkspace)))
230 g_log.warning() << name << " can be saved using SaveMD\n";
231
232 // standard error message
233 std::stringstream msg;
234 msg << "Workspace \"" << name << "\" not saved because it is not of a type we can presently save.";
235
236 throw std::runtime_error(msg.str());
237 }
238 m_eventWorkspace = std::dynamic_pointer_cast<const EventWorkspace>(matrixWorkspace);
239 const std::string workspaceID = inputWorkspace->id();
240 if ((workspaceID.find("Workspace2D") == std::string::npos) &&
241 (workspaceID.find("RebinnedOutput") == std::string::npos) &&
242 (workspaceID.find("WorkspaceSingleValue") == std::string::npos) && !m_eventWorkspace && !tableWorkspace &&
243 !offsetsWorkspace && !maskWorkspace)
244 throw Exception::NotImplementedError("SaveNexusProcessed passed invalid workspaces. Must be Workspace2D, "
245 "EventWorkspace, ITableWorkspace, OffsetsWorkspace or MaskWorkspace.");
246
247 // Create progress object for initial part - depends on whether events are
248 // processed
249 if (PreserveEvents && m_eventWorkspace) {
250 m_timeProgInit = 0.07; // Events processed 0.05 to 1.0
251 } else {
252 m_timeProgInit = 1.0; // All work is done in the initial part
253 }
254 Progress prog_init(this, 0.0, m_timeProgInit, 7);
255
256 // If no title's been given, use the workspace title field
257 if (title.empty())
258 title = inputWorkspace->getTitle();
259
260 // get the workspace name to write to file
261 const std::string wsName = inputWorkspace->getName();
262
263 // If not append, openNexusWrite will open with _CREATES perm and overwrite
264 const bool append_to_file = getProperty("Append");
265
266 nexusFile->resetProgress(&prog_init);
267 nexusFile->openNexusWrite(filename, std::move(entryNumber), append_to_file || keepFile);
268
269 // Equivalent C++ API handle
270 ::NeXus::File cppFile(nexusFile->fileID);
271
272 prog_init.reportIncrement(1, "Opening file");
273 if (nexusFile->writeNexusProcessedHeader(title, wsName) != 0)
274 throw Exception::FileError("Failed to write to file", filename);
275
276 prog_init.reportIncrement(1, "Writing header");
277
278 // write instrument data, if present and writer enabled
279 if (matrixWorkspace) {
280 // Save the instrument names, ParameterMap, sample, run
281 matrixWorkspace->saveExperimentInfoNexus(&cppFile, saveLegacyInstrument());
282 prog_init.reportIncrement(1, "Writing sample and instrument");
283
284 // check if all X() are in fact the same array
285 const bool uniformSpectra = matrixWorkspace->isCommonBins();
286
287 // Retrieve the workspace indices (from params)
288 std::vector<int> indices;
289 this->getWSIndexList(indices, matrixWorkspace);
290
291 prog_init.reportIncrement(1, "Writing data");
292 // Write out the data (2D or event)
293 if (m_eventWorkspace && PreserveEvents) {
294 this->execEvent(nexusFile.get(), uniformSpectra, indices);
295 } else {
296 std::string workspaceTypeGroupName;
297 if (offsetsWorkspace)
298 workspaceTypeGroupName = "offsets_workspace";
299 else if (maskWorkspace)
300 workspaceTypeGroupName = "mask_workspace";
301 else
302 workspaceTypeGroupName = "workspace";
303
304 nexusFile->writeNexusProcessedData2D(matrixWorkspace, uniformSpectra, indices, workspaceTypeGroupName.c_str(),
305 true);
306 }
307
308 if (saveLegacyInstrument()) {
309 cppFile.openGroup("instrument", "NXinstrument");
310 cppFile.makeGroup("detector", "NXdetector", true);
311
312 cppFile.putAttr("version", 1);
313 saveSpectraDetectorMapNexus(*matrixWorkspace, &cppFile, indices, ::NeXus::LZW);
314 saveSpectrumNumbersNexus(*matrixWorkspace, &cppFile, indices, ::NeXus::LZW);
315 cppFile.closeGroup();
316 cppFile.closeGroup();
317 }
318
319 } // finish matrix workspace specifics
320
321 if (peaksWorkspace) {
322 // Save the instrument names, ParameterMap, sample, run
323 peaksWorkspace->saveExperimentInfoNexus(&cppFile);
324 prog_init.reportIncrement(1, "Writing sample and instrument");
325 peaksWorkspace->saveNexus(&cppFile);
326 } else if (tableWorkspace) {
327 nexusFile->writeNexusTableWorkspace(tableWorkspace, "table_workspace");
328 }
329
330 // Switch to the Cpp API for the algorithm history
331 if (trackingHistory()) {
332 m_history->fillAlgorithmHistory(this, Mantid::Types::Core::DateAndTime::getCurrentTime(), 0,
334 if (!isChild()) {
335 inputWorkspace->history().addHistory(m_history);
336 }
337 // this is a child algorithm, but we still want to keep the history.
339 m_parentHistory->addChildHistory(m_history);
340 }
341 }
342
343 inputWorkspace->history().saveNexus(&cppFile);
344 nexusFile->closeGroup();
345}
346
347//-----------------------------------------------------------------------------------------------
353 Workspace_sptr inputWorkspace = getProperty("InputWorkspace");
354
355 // Then immediately open the file
356 auto nexusFile = std::make_shared<Mantid::NeXus::NexusFileIO>();
357
358 // Perform the execution.
359 doExec(inputWorkspace, nexusFile);
360
361 // nexusFile->closeNexusFile();
362}
363
364//-------------------------------------------------------------------------------------
373template <class T>
374void SaveNexusProcessed::appendEventListData(const std::vector<T> &events, size_t offset, double *tofs, float *weights,
375 float *errorSquareds, int64_t *pulsetimes) {
376 // Do nothing if there are no events.
377 if (events.empty())
378 return;
379
380 const auto it = events.cbegin();
381 const auto it_end = events.cend();
382
383 // Fill the C-arrays with the fields from all the events, as requested.
384 if (tofs) {
385 std::transform(it, it_end, std::next(tofs, offset), [](const T &event) { return event.tof(); });
386 }
387 if (weights) {
388 std::transform(it, it_end, std::next(weights, offset),
389 [](const T &event) { return static_cast<float>(event.weight()); });
390 }
391 if (errorSquareds) {
392 std::transform(it, it_end, std::next(errorSquareds, offset),
393 [](const T &event) { return static_cast<float>(event.errorSquared()); });
394 }
395 if (pulsetimes) {
396 std::transform(it, it_end, std::next(pulsetimes, offset),
397 [](const T &event) { return event.pulseTime().totalNanoseconds(); });
398 }
399}
400
401//-----------------------------------------------------------------------------------------------
405void SaveNexusProcessed::execEvent(Mantid::NeXus::NexusFileIO *nexusFile, const bool uniformSpectra,
406 const std::vector<int> &spec) {
407 m_progress = std::make_unique<Progress>(this, m_timeProgInit, 1.0, m_eventWorkspace->getNumberEvents() * 2);
408
409 // Start by writing out the axes and crap
410 nexusFile->writeNexusProcessedData2D(m_eventWorkspace, uniformSpectra, spec, "event_workspace", false);
411
412 // Make a super long list of tofs, weights, etc.
413 std::vector<int64_t> indices;
414 indices.reserve(m_eventWorkspace->getNumberHistograms() + 1);
415 // First we need to index the events in each spectrum
416 size_t index = 0;
417 for (int wi = 0; wi < static_cast<int>(m_eventWorkspace->getNumberHistograms()); wi++) {
418 indices.emplace_back(index);
419 // Track the total # of events
420 index += m_eventWorkspace->getSpectrum(wi).getNumberEvents();
421 }
422 indices.emplace_back(index);
423
424 // Initialize all the arrays
425 int64_t num = index;
426 double *tofs = nullptr;
427 float *weights = nullptr;
428 float *errorSquareds = nullptr;
429 int64_t *pulsetimes = nullptr;
430
431 // overall event type.
432 EventType type = m_eventWorkspace->getEventType();
433 bool writeTOF = true;
434 bool writePulsetime = false;
435 bool writeWeight = false;
436 bool writeError = false;
437
438 switch (type) {
439 case TOF:
440 writePulsetime = true;
441 break;
442 case WEIGHTED:
443 writePulsetime = true;
444 writeWeight = true;
445 writeError = true;
446 break;
447 case WEIGHTED_NOTIME:
448 writeWeight = true;
449 writeError = true;
450 break;
451 }
452
453 // --- Initialize the combined event arrays ----
454 if (writeTOF)
455 tofs = new double[num];
456 if (writeWeight)
457 weights = new float[num];
458 if (writeError)
459 errorSquareds = new float[num];
460 if (writePulsetime)
461 pulsetimes = new int64_t[num];
462
463 // --- Fill in the combined event arrays ----
465 for (int wi = 0; wi < static_cast<int>(m_eventWorkspace->getNumberHistograms()); wi++) {
467 const DataObjects::EventList &el = m_eventWorkspace->getSpectrum(wi);
468
469 // This is where it will land in the output array.
470 // It is okay to write in parallel since none should step on each other.
471 size_t offset = indices[wi];
472
473 switch (el.getEventType()) {
474 case TOF:
475 appendEventListData(el.getEvents(), offset, tofs, weights, errorSquareds, pulsetimes);
476 break;
477 case WEIGHTED:
478 appendEventListData(el.getWeightedEvents(), offset, tofs, weights, errorSquareds, pulsetimes);
479 break;
480 case WEIGHTED_NOTIME:
481 appendEventListData(el.getWeightedEventsNoTime(), offset, tofs, weights, errorSquareds, pulsetimes);
482 break;
483 }
484 m_progress->reportIncrement(el.getNumberEvents(), "Copying EventList");
485
487 }
489
490 /*Default = DONT compress - much faster*/
491 bool CompressNexus = getProperty("CompressNexus");
492
493 // Write out to the NXS file.
494 nexusFile->writeNexusProcessedDataEventCombined(m_eventWorkspace, indices, tofs, weights, errorSquareds, pulsetimes,
495 CompressNexus);
496
497 // Free mem.
498 delete[] tofs;
499 delete[] weights;
500 delete[] errorSquareds;
501 delete[] pulsetimes;
502}
503
504//-----------------------------------------------------------------------------------------------
511void SaveNexusProcessed::setOtherProperties(IAlgorithm *alg, const std::string &propertyName,
512 const std::string &propertyValue, int perioidNum) {
513 if (propertyName == "Append") {
514 if (perioidNum != 1) {
515 alg->setPropertyValue(propertyName, "1");
516 } else
517 alg->setPropertyValue(propertyName, propertyValue);
518 } else
519 Algorithm::setOtherProperties(alg, propertyName, propertyValue, perioidNum);
520}
521
526 // Then immediately open the file
527 auto nexusFile = std::make_shared<Mantid::NeXus::NexusFileIO>();
528
529 // If we have arrived here then a WorkspaceGroup was passed to the
530 // InputWorkspace property. Pull out the unrolled workspaces and append an
531 // entry for each one. We only have a single input workspace property declared
532 // so there will only be a single list of unrolled workspaces
533 const auto &workspaces = m_unrolledInputWorkspaces[0];
534 if (!workspaces.empty()) {
535 for (size_t entry = 0; entry < workspaces.size(); entry++) {
536 const Workspace_sptr ws = workspaces[entry];
537 if (ws->isGroup()) {
538 throw std::runtime_error("NeXus files do not "
539 "support nested groups of groups");
540 }
541 this->doExec(ws, nexusFile, entry > 0 /*keepFile*/, entry);
542 g_log.information() << "Saving group index " << entry << "\n";
543 }
544 }
545
546 nexusFile->closeNexusFile();
547
548 return true;
549}
550
558 const std::vector<int> &wsIndices,
559 const ::NeXus::NXcompression compression) const {
560
561 std::vector<int32_t> detector_index;
562 std::vector<int32_t> detector_count;
563 std::vector<int32_t> detector_list;
564 int numberSpec = 0;
565 size_t nDetectors = 0;
566 /*Make the mappings needed for writing to disk*/
567 const bool mappingsToWrite =
568 makeMappings(ws, wsIndices, detector_index, detector_count, detector_list, numberSpec, nDetectors);
569 if (!mappingsToWrite)
570 return;
571
572 // write data as Nexus sections detector{index,count,list}
573 std::vector<int> dims(1, numberSpec);
574 file->writeCompData("detector_index", detector_index, dims, compression, dims);
575 file->writeCompData("detector_count", detector_count, dims, compression, dims);
576 dims.front() = static_cast<int>(nDetectors);
577 file->writeCompData("detector_list", detector_list, dims, compression, dims);
578 // Get all the positions
579 try {
580 std::vector<double> detPos(nDetectors * 3);
582 Geometry::IComponent_const_sptr sample = inst->getSample();
583 if (sample) {
584 Kernel::V3D sample_pos = sample->getPos();
585 for (size_t i = 0; i < nDetectors; i++) {
586 double R, Theta, Phi;
587 try {
588 Geometry::IDetector_const_sptr det = inst->getDetector(detector_list[i]);
589 Kernel::V3D pos = det->getPos() - sample_pos;
590 pos.getSpherical(R, Theta, Phi);
591 R = det->getDistance(*sample);
592 Theta = ws.detectorTwoTheta(*det) * Geometry::rad2deg;
593 } catch (...) {
594 R = 0.;
595 Theta = 0.;
596 Phi = 0.;
597 }
598 // Need to get R & Theta through these methods to be correct for grouped
599 // detectors
600 detPos[3 * i] = R;
601 detPos[3 * i + 1] = Theta;
602 detPos[3 * i + 2] = Phi;
603 }
604 } else
605 for (size_t i = 0; i < 3 * nDetectors; i++)
606 detPos[i] = 0.;
607
608 dims.front() = static_cast<int>(nDetectors);
609 dims.emplace_back(3);
610 file->writeCompData("detector_positions", detPos, dims, compression, dims);
611 } catch (...) {
612 g_log.error("Unknown error caught when saving detector positions.");
613 }
614}
615
623 const std::vector<int> &wsIndices,
624 const ::NeXus::NXcompression compression) const {
625 const auto numberSpec = int(wsIndices.size());
626 std::vector<int32_t> spectra;
627 spectra.reserve(static_cast<size_t>(numberSpec));
628 for (const auto index : wsIndices) {
629 const auto &spectrum = ws.getSpectrum(static_cast<size_t>(index));
630 spectra.emplace_back(static_cast<int32_t>(spectrum.getSpectrumNo()));
631 }
632
633 const std::vector<int> dims(1, numberSpec);
634 file->writeCompData("spectra", spectra, dims, compression, dims);
635}
636
637} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
Definition: MultiThreaded.h:94
#define PARALLEL_FOR_NO_WSP_CHECK()
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
std::shared_ptr< AlgorithmHistory > m_parentHistory
Pointer to the parent history object (if set)
Definition: Algorithm.h:454
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
std::shared_ptr< AlgorithmHistory > m_history
Pointer to the history for the algorithm being executed.
Definition: Algorithm.h:447
bool isChild() const override
To query whether algorithm is a child.
Definition: Algorithm.cpp:160
Kernel::Logger & g_log
Definition: Algorithm.h:451
virtual void setOtherProperties(IAlgorithm *alg, const std::string &propertyName, const std::string &propertyValue, int periodNum)
Virtual method to set the non workspace properties for this algorithm.
Definition: Algorithm.cpp:1547
bool trackingHistory()
get whether we are tracking the history for this algorithm,
Definition: Algorithm.cpp:1063
std::vector< WorkspaceVector > m_unrolledInputWorkspaces
One vector of workspaces for each input workspace property.
Definition: Algorithm.h:458
bool isRecordingHistoryForChild()
Definition: Algorithm.h:234
static size_t g_execCount
Counter to keep track of algorithm execution order.
Definition: Algorithm.h:439
Show a property as enabled when the workspace pointed to by another is of a given type.
Geometry::Instrument_const_sptr getInstrument() const
Returns the parameterized instrument.
@ Save
to specify a file to write to, the file may or may not exist
Definition: FileProperty.h:49
IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:45
const std::set< detid_t > & getDetectorIDs() const
Get a const reference to the detector IDs set.
Definition: ISpectrum.cpp:113
Base MatrixWorkspace Abstract Class.
virtual ISpectrum & getSpectrum(const size_t index)=0
Return the underlying ISpectrum ptr at the given workspace index.
double detectorTwoTheta(const Geometry::IDetector &det) const
Returns the 2Theta scattering angle for a detector.
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
A property class for workspaces.
DataHandling/SaveNexusProcessed.h.
static void appendEventListData(const std::vector< T > &events, size_t offset, double *tofs, float *weights, float *errorSquareds, int64_t *pulsetimes)
Append out each field of a vector of events to separate array.
void execEvent(Mantid::NeXus::NexusFileIO *nexusFile, const bool uniformSpectra, const std::vector< int > &spec)
Execute the saving of event data.
DataObjects::EventWorkspace_const_sptr m_eventWorkspace
Pointer to the local workspace, cast to EventWorkspace.
void doExec(const Mantid::API::Workspace_sptr &inputWorkspace, std::shared_ptr< Mantid::NeXus::NexusFileIO > &nexusFile, const bool keepFile=false, boost::optional< size_t > entryNumber=boost::optional< size_t >())
void getWSIndexList(std::vector< int > &indices, const Mantid::API::MatrixWorkspace_const_sptr &matrixWorkspace)
Get the list of workspace indices to use.
void init() override
Overwrites Algorithm method.
double m_timeProgInit
Proportion of progress time expected to write initial part.
bool processGroups() override
Override process groups.
void saveSpectraDetectorMapNexus(const API::MatrixWorkspace &ws, ::NeXus::File *file, const std::vector< int > &wsIndices, const ::NeXus::NXcompression compression=::NeXus::LZW) const
Save the spectra detector map to an open NeXus file.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
void exec() override
Overwrites Algorithm method.
void setOtherProperties(IAlgorithm *alg, const std::string &propertyName, const std::string &propertyValue, int perioidNum) override
sets non workspace properties for the algorithm
void saveSpectrumNumbersNexus(const API::MatrixWorkspace &ws, ::NeXus::File *file, const std::vector< int > &wsIndices, const ::NeXus::NXcompression compression=::NeXus::LZW) const
Save the spectra numbers to an open NeXus file.
std::unique_ptr< API::Progress > m_progress
Progress bar.
A class for holding :
Definition: EventList.h:56
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
Records the filename and the description of failure.
Definition: Exception.h:98
Marks code as not implemented yet.
Definition: Exception.h:138
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
void reportIncrement(int inc, const std::string &msg="")
Sends the progress notification and increment the loop counter by more than one.
Class for 3D vectors.
Definition: V3D.h:34
void getSpherical(double &R, double &theta, double &phi) const noexcept
Return the vector's position in spherical coordinates.
Definition: V3D.cpp:117
Utility method for saving NeXus format of Mantid Workspace This class interfaces to the C Nexus API.
Definition: NexusFileIO.h:38
boost::optional< size_t > optional_size_t
Definition: NexusFileIO.h:42
int writeNexusProcessedDataEventCombined(const DataObjects::EventWorkspace_const_sptr &ws, std::vector< int64_t > &indices, double *tofs, float *weights, float *errorSquareds, int64_t *pulsetimes, bool compress) const
Write out a combined chunk of event data.
int writeNexusProcessedData2D(const API::MatrixWorkspace_const_sptr &localworkspace, const bool &uniformSpectra, const std::vector< int > &indices, const char *group_name, bool write2Ddata) const
write the workspace data
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< const IPeaksWorkspace > IPeaksWorkspace_const_sptr
shared pointer to Mantid::API::IPeaksWorkspace (const version)
EventType
What kind of event list is being stored.
Definition: IEventList.h:18
@ WEIGHTED_NOTIME
Definition: IEventList.h:18
NeXus::NexusFileIO::optional_size_t optional_size_t
std::shared_ptr< const OffsetsWorkspace > OffsetsWorkspace_const_sptr
shared pointer to a const OffsetsWorkspace
std::shared_ptr< const MaskWorkspace > MaskWorkspace_const_sptr
shared pointer to a const MaskWorkspace
Definition: MaskWorkspace.h:67
constexpr double rad2deg
Radians to degrees conversion factor.
Definition: AngleUnits.h:23
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
Definition: IComponent.h:161
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
Definition: IDetector.h:102
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition: EmptyValues.h:25
@ Input
An input workspace.
Definition: Property.h:53