Mantid
Loading...
Searching...
No Matches
LoadSQW2.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 +
9
11#include "MantidAPI/Progress.h"
13#include "MantidAPI/Run.h"
14#include "MantidAPI/Sample.h"
21#include "MantidKernel/Matrix.h"
22#include "MantidKernel/Memory.h"
24#include "MantidKernel/Timer.h"
25#include "MantidKernel/V3D.h"
27
28namespace Mantid::MDAlgorithms {
29
30using API::ExperimentInfo;
31using Geometry::Goniometer;
32using Geometry::MDHistoDimensionBuilder;
33using Geometry::OrientedLattice;
34using Kernel::BinaryStreamReader;
36using Kernel::Logger;
37using Kernel::V3D;
38
39namespace {
43constexpr int64_t NPIX_CHUNK = 150000;
46constexpr int64_t NCHUNKS_SPLIT = 125;
48constexpr int32_t FIELDS_PER_PIXEL = 9;
50constexpr double INV_TWO_PI = 0.5 / M_PI;
51} // namespace
52
53// Register the algorithm into the AlgorithmFactory
55
56
57const std::string LoadSQW2::name() const { return "LoadSQW"; }
58
60int LoadSQW2::version() const { return 2; }
61
63const std::string LoadSQW2::category() const { return "DataHandling\\SQW;MDAlgorithms\\DataHandling"; }
64
67const std::string LoadSQW2::summary() const {
68 return "Load an N-dimensional workspace from a .sqw file produced by "
69 "Horace.";
70}
71
79 // only .sqw can be considered
80 const std::string &extn = descriptor.extension();
81 if (extn != ".sqw")
82 return 0;
83
84 if (descriptor.isAscii()) {
85 // Low so that others may try
86 return 10;
87 }
88 // Beat v1
89 return 81;
90}
91
94 using namespace API;
97 using StringInitializerList = std::initializer_list<std::string>;
98
99 // Inputs
100 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Load, StringInitializerList({".sqw"})),
101 "File of type SQW format");
102 declareProperty(std::make_unique<PropertyWithValue<bool>>("MetadataOnly", false), "Load Metadata without events.");
104 std::make_unique<FileProperty>("OutputFilename", "", FileProperty::OptionalSave, StringInitializerList({".nxs"})),
105 "If specified, the output workspace will be a file-backed "
106 "MDEventWorkspace");
107 std::vector<std::string> allowed = {"Q_sample", "HKL"};
108 declareProperty("Q3DFrames", allowed[0], std::make_shared<StringListValidator>(allowed),
109 "The required frame for the output workspace");
110
111 // Outputs
113 std::make_unique<WorkspaceProperty<IMDEventWorkspace>>("OutputWorkspace", "", Kernel::Direction::Output),
114 "Output IMDEventWorkspace reflecting SQW data");
115}
116
119 cacheInputs();
121 auto sqwType = readMainHeader();
127 finalize();
128}
129
132
135 using API::Progress;
136
137 m_file = std::make_unique<std::ifstream>(getPropertyValue("Filename"), std::ios_base::binary);
138 m_reader = std::make_unique<BinaryStreamReader>(*m_file);
139}
140
148 std::string appName, filename, filepath, title;
149 double appVersion(0.0);
150 int32_t sqwType(-1), numDims(-1), nspe(-1);
151 *m_reader >> appName >> appVersion >> sqwType >> numDims >> filename >> filepath >> title >> nspe;
152 m_nspe = static_cast<uint16_t>(nspe);
153 if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
154 std::ostringstream os;
155 os << "Main header:\n"
156 << " app_name: " << appName << "\n"
157 << " app_version: " << appVersion << "\n"
158 << " sqw_type: " << sqwType << "\n"
159 << " ndims: " << numDims << "\n"
160 << " filename: " << filename << "\n"
161 << " filepath: " << filepath << "\n"
162 << " title: " << title << "\n"
163 << " nfiles: " << m_nspe << "\n";
164 g_log.debug(os.str());
165 }
166 return sqwType;
167}
168
174 if (sqwType != 1) {
175 throw std::runtime_error("Unsupported SQW type: " + std::to_string(sqwType) +
176 "\nOnly files containing the full pixel "
177 "information are currently supported");
178 }
179}
180
182void LoadSQW2::createOutputWorkspace() { m_outputWS = std::make_shared<SQWWorkspace>(); }
183
191 for (uint16_t i = 0; i < m_nspe; ++i) {
192 auto expt = readSingleSPEHeader();
193 m_outputWS->addExperimentInfo(expt);
194 }
195 auto expt0 = m_outputWS->getExperimentInfo(0);
196 cacheFrameTransforms(expt0->sample().getOrientedLattice());
197}
198
205std::shared_ptr<API::ExperimentInfo> LoadSQW2::readSingleSPEHeader() {
206 auto experiment = std::make_shared<ExperimentInfo>();
207 auto &sample = experiment->mutableSample();
208 auto &run = experiment->mutableRun();
209
210 std::string chars;
211 // skip filename, filepath
212 *m_reader >> chars >> chars;
213 float efix(1.0f);
214 int32_t emode(0);
215 // add ei as log but skip emode
216 *m_reader >> efix >> emode;
217 run.addProperty("Ei", static_cast<double>(efix), true);
218
219 // lattice - alatt, angdeg, cu, cv = 12 values
220 std::vector<float> floats;
221 m_reader->read(floats, 12);
222 auto lattice = std::make_unique<OrientedLattice>(floats[0], floats[1], floats[2], floats[3], floats[4], floats[5]);
223 V3D uVec(floats[6], floats[7], floats[8]), vVec(floats[9], floats[10], floats[11]);
224 lattice->setUFromVectors(uVec, vVec);
225 if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
226 std::stringstream os;
227 os << "Lattice:"
228 << " alatt: " << lattice->a1() << " " << lattice->a2() << " " << lattice->a3() << "\n"
229 << " angdeg: " << lattice->alpha() << " " << lattice->beta() << " " << lattice->gamma() << "\n"
230 << " cu: " << floats[6] << " " << floats[7] << " " << floats[8] << "\n"
231 << " cv: " << floats[9] << " " << floats[10] << " " << floats[11] << "\n"
232 << "B matrix (calculated): " << lattice->getB() << "\n"
233 << "Inverse B matrix (calculated): " << lattice->getBinv() << "\n";
234 g_log.debug(os.str());
235 }
236 sample.setOrientedLattice(std::move(lattice));
237
238 // goniometer angles
239 float psi(0.0f), omega(0.0f), dpsi(0.0f), gl(0.0f), gs(0.0f);
240 *m_reader >> psi >> omega >> dpsi >> gl >> gs;
241 V3D uvCross = uVec.cross_prod(vVec);
242 Goniometer goniometer;
243 goniometer.pushAxis("psi", uvCross[0], uvCross[1], uvCross[2], psi);
244 goniometer.pushAxis("omega", uvCross[0], uvCross[1], uvCross[2], omega);
245 goniometer.pushAxis("gl", 1.0, 0.0, 0.0, gl);
246 goniometer.pushAxis("gs", 0.0, 0.0, 1.0, gs);
247 goniometer.pushAxis("dpsi", 0.0, 1.0, 0.0, dpsi);
248 run.setGoniometer(goniometer, false);
249 if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
250 std::stringstream os;
251 os << "Goniometer angles:\n"
252 << " psi: " << psi << "\n"
253 << " omega: " << omega << "\n"
254 << " gl: " << gl << "\n"
255 << " gs: " << gs << "\n"
256 << " dpsi: " << dpsi << "\n"
257 << " goniometer matrix: " << goniometer.getR() << "\n";
258 g_log.debug(os.str());
259 }
260 // energy bins
261 int32_t nbounds(0);
262 *m_reader >> nbounds;
263 std::vector<float> enBins(nbounds);
264 m_reader->read(enBins, nbounds);
265 run.storeHistogramBinBoundaries(std::vector<double>(enBins.begin(), enBins.end()));
266
267 // Skip the per-spe file projection information. We only use the
268 // information from the data section
269 m_file->seekg(96, std::ios_base::cur);
270 std::vector<int32_t> ulabel_shape(2);
271 m_reader->read(ulabel_shape, 2);
272 // shape[0]*shape[1]*sizeof(char)
273 m_file->seekg(ulabel_shape[0] * ulabel_shape[1], std::ios_base::cur);
274
275 return experiment;
276}
277
283 m_uToRLU = lattice.getBinv() * INV_TWO_PI;
284}
285
291 std::string filename, filepath;
292 *m_reader >> filename >> filepath;
293 int32_t ndet(0);
294 *m_reader >> ndet;
295 if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
296 std::stringstream os;
297 os << "Skipping " << ndet << " detector parameters from '" << filename << "'\n";
298 g_log.debug(os.str());
299 }
300 // 6 float fields all ndet long - group, x2, phi, azim, width, height
301 m_file->seekg(6 * 4 * ndet, std::ios_base::cur);
302}
303
307 bool metadataOnly = getProperty("MetadataOnly");
308 if (!metadataOnly)
310}
311
318 std::string dropped;
319 *m_reader >> dropped >> dropped >> dropped;
320 // skip alatt, angdeg, uoffset, u_to_rlu, ulen
321 m_file->seekg(120, std::ios_base::cur);
322
323 // dimension labels
324 std::vector<int32_t> ulabelShape(2);
325 m_reader->read(ulabelShape, 2);
326 m_file->seekg(ulabelShape[0] * ulabelShape[1], std::ios_base::cur);
327}
328
336 auto nbins = readProjection();
337 if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
338 std::stringstream os;
339 os << "nbins: (";
340 for (const auto &val : nbins) {
341 os << val << ",";
342 }
343 os << ")";
344 g_log.debug(os.str());
345 }
346 auto dimLimits = calculateDimLimitsFromData();
347 if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
348 std::stringstream os;
349 os << "data extents (in output frame): ";
350 for (size_t i = 0; i < 4; ++i) {
351 os << "(" << dimLimits[2 * i] << "," << dimLimits[2 * i + 1] << ") ";
352 }
353 os << "\n";
354 g_log.debug(os.str());
355 }
356
357 // The lattice is assumed to be the same in all contributing files so use
358 // the first B matrix to create the axis information (only needed in HKL
359 // frame)
360 const auto &bmat0 = m_outputWS->getExperimentInfo(0)->sample().getOrientedLattice().getB();
361 for (size_t i = 0; i < 4; ++i) {
362 // To ensure that we capture all of the data from the file we initially
363 // set the dimension limits to arbitrarily large values and reset them later
364 float umin(dimLimits[2 * i]), umax(dimLimits[2 * i + 1]);
365 if (i < 3) {
366 m_outputWS->addDimension(createQDimension(i, umin, umax, static_cast<size_t>(nbins[i]), bmat0));
367 } else {
368 m_outputWS->addDimension(createEnDimension(umin, umax, static_cast<size_t>(nbins[i])));
369 }
370 }
372}
373
380std::vector<int32_t> LoadSQW2::readProjection() {
381 int32_t nProjAxes(0);
382 *m_reader >> nProjAxes;
383 int32_t nIntAxes(4 - nProjAxes);
384 if (nIntAxes > 0) {
385 // n indices + 2*n limits
386 m_file->seekg(nIntAxes * sizeof(int32_t) + 2 * nIntAxes * sizeof(float), std::ios_base::cur);
387 }
388 std::vector<int32_t> nbins(4, 1);
389 if (nProjAxes > 0) {
390 // 1-based indices of the non-integrated axes
391 std::vector<int32_t> projAxIdx;
392 int32_t signalLength(1);
393 m_reader->read(projAxIdx, nProjAxes);
394 for (int32_t i = 0; i < nProjAxes; ++i) {
395 int32_t nbounds(0);
396 *m_reader >> nbounds;
397 m_file->seekg(nbounds * sizeof(float), std::ios_base::cur);
398 nbins[projAxIdx[i] - 1] = nbounds - 1;
399 signalLength *= nbounds - 1;
400 }
401 // skip display axes
402 m_file->seekg(nProjAxes * sizeof(int32_t), std::ios_base::cur);
403 // skip data+error+npix(binned)
404 m_file->seekg(2 * signalLength * sizeof(float) + signalLength * sizeof(int64_t), std::ios_base::cur);
405 }
406 return nbins;
407}
408
420 // skip urange
421 m_file->seekg(8 * sizeof(float), std::ios_base::cur);
422
423 auto filePosAfterURange = m_file->tellg();
424 // Redundnant int32 field
425 m_file->seekg(sizeof(int32_t), std::ios_base::cur);
426
427 int64_t npixtot(0);
428 *m_reader >> npixtot;
429 API::Progress status(this, 0.0, 0.5, npixtot);
430 status.setNotifyStep(0.01);
431
432 constexpr int64_t bufferSize(FIELDS_PER_PIXEL * NPIX_CHUNK);
433 std::vector<float> pixBuffer(bufferSize);
434 int64_t pixelsLeftToRead(npixtot);
435 std::vector<float> dimLimits(8);
436 dimLimits[0] = dimLimits[2] = dimLimits[4] = dimLimits[6] = FLT_MAX;
437 dimLimits[1] = dimLimits[3] = dimLimits[5] = dimLimits[7] = -FLT_MAX;
438 while (pixelsLeftToRead > 0) {
439 int64_t chunkSize(pixelsLeftToRead);
440 if (chunkSize > NPIX_CHUNK) {
441 chunkSize = NPIX_CHUNK;
442 }
443 m_reader->read(pixBuffer, FIELDS_PER_PIXEL * chunkSize);
444 for (int64_t i = 0; i < chunkSize; ++i) {
445 float *pixel = pixBuffer.data() + i * 9;
446 toOutputFrame(pixel);
447 for (size_t j = 0; j < 4; ++j) {
448 auto uj(pixel[j]);
449 if (uj < dimLimits[2 * j])
450 dimLimits[2 * j] = uj;
451 else if (uj > dimLimits[2 * j + 1])
452 dimLimits[2 * j + 1] = uj;
453 }
454 status.report("Calculating data extents");
455 }
456 pixelsLeftToRead -= chunkSize;
457 }
458 m_file->seekg(filePosAfterURange);
459 return dimLimits;
460}
461
462// The missing braces warning is a false positive -
463// https://llvm.org/bugs/show_bug.cgi?id=21629
464GNU_DIAG_OFF("missing-braces")
476Geometry::IMDDimension_sptr LoadSQW2::createQDimension(size_t index, float dimMin, float dimMax, size_t nbins,
477 const Kernel::DblMatrix &bmat) {
478 if (index > 2) {
479 throw std::logic_error("LoadSQW2::createQDimension - Expected a dimension "
480 "index between 0 & 2. Found: " +
482 }
483 static std::array<const char *, 3> indexToDim{"x", "y", "z"};
485 builder.setId(std::string("q") + indexToDim[index]);
487 builder.setMin(dimMin);
488 builder.setMax(dimMax);
489 builder.setNumBins(nbins);
490
491 std::string name, unit, frameName;
492 if (m_outputFrame == "Q_sample") {
493 name = m_outputFrame + "_" + indexToDim[index];
494 unit = "A^-1";
495 frameName = "QSample";
496 } else if (m_outputFrame == "HKL") {
497 static std::array<const char *, 3> indexToHKL{"[H,0,0]", "[0,K,0]", "[0,0,L]"};
498 name = indexToHKL[index];
499 V3D dimDir;
500 dimDir[index] = 1;
501 const V3D x = bmat * dimDir;
502 double length = 2. * M_PI * x.norm();
503 unit = "in " + MDAlgorithms::sprintfd(length, 1.e-3) + " A^-1";
504 frameName = "HKL";
505 } else {
506 throw std::logic_error("LoadSQW2::createQDimension - Unknown output frame: " + m_outputFrame);
507 }
508 builder.setUnits(unit);
509 builder.setName(name);
510 builder.setFrameName(frameName);
511
512 return builder.create();
513}
514
515GNU_DIAG_ON("missing-braces")
516
517
524Geometry::IMDDimension_sptr LoadSQW2::createEnDimension(float dimMin, float dimMax, size_t nbins) {
526 builder.setId("en");
527 builder.setUnits("meV");
528 builder.setName("en");
529 builder.setFrameName("meV");
531 builder.setMin(dimMin);
532 builder.setMax(dimMax);
533 builder.setNumBins(nbins);
534 return builder.create();
535}
536
541 using Kernel::Timer;
542 Timer timer;
543
544 auto boxController = m_outputWS->getBoxController();
545 for (size_t i = 0; i < 4; i++) {
546 boxController->setSplitInto(i, m_outputWS->getDimension(i)->getNBins());
547 }
548 boxController->setMaxDepth(1);
549 m_outputWS->initialize();
550 // Start with a MDGridBox.
551 m_outputWS->splitBox();
552
553 g_log.debug() << "Time to setup box structure: " << timer.elapsed() << "s\n";
554
555 std::string fileback = getProperty("OutputFilename");
556 if (!fileback.empty()) {
557 setupFileBackend(fileback);
558 }
559}
560
566void LoadSQW2::setupFileBackend(const std::string &filebackPath) {
568 auto savemd = this->createChildAlgorithm("SaveMD", 0.01, 0.05, true);
569 savemd->setProperty("InputWorkspace", m_outputWS);
570 savemd->setPropertyValue("Filename", filebackPath);
571 savemd->setProperty("UpdateFileBackEnd", false);
572 savemd->setProperty("MakeFileBacked", false);
573 savemd->executeAsChildAlg();
574
575 // create file-backed box controller
576 auto boxControllerMem = m_outputWS->getBoxController();
577 auto boxControllerIO = std::make_shared<BoxControllerNeXusIO>(boxControllerMem.get());
578 boxControllerMem->setFileBacked(boxControllerIO, filebackPath);
579 m_outputWS->getBox()->setFileBacked();
580 boxControllerMem->getFileIO()->setWriteBufferSize(1000000);
581}
582
587 using Kernel::Timer;
588 Timer timer;
589
590 // skip redundant field
591 m_file->seekg(sizeof(int32_t), std::ios_base::cur);
592 int64_t npixtot(0);
593 *m_reader >> npixtot;
594 g_log.debug() << " npixtot: " << npixtot << "\n";
596 API::Progress status(this, 0.5, 1.0, npixtot);
597 status.setNotifyStep(0.01);
598
599 // Each pixel has 9 float fields. Do a chunked read to avoid
600 // using too much memory for the buffer and also split the
601 // boxes regularly to ensure that larger workspaces can be loaded
602 // without blowing the memory requirements.
603 constexpr int64_t bufferSize(FIELDS_PER_PIXEL * NPIX_CHUNK);
604 std::vector<float> pixBuffer(bufferSize);
605 int64_t pixelsLeftToRead(npixtot), chunksRead(0);
606 size_t pixelsAdded(0);
607 while (pixelsLeftToRead > 0) {
608 int64_t chunkSize(pixelsLeftToRead);
609 if (chunkSize > NPIX_CHUNK) {
610 chunkSize = NPIX_CHUNK;
611 }
612 m_reader->read(pixBuffer, FIELDS_PER_PIXEL * chunkSize);
613 for (int64_t i = 0; i < chunkSize; ++i) {
614 pixelsAdded += addEventFromBuffer(pixBuffer.data() + i * 9);
615 status.report("Reading pixel data to workspace");
616 }
617 pixelsLeftToRead -= chunkSize;
618 ++chunksRead;
619 if ((chunksRead % NCHUNKS_SPLIT) == 0) {
621 }
622 }
623 assert(pixelsLeftToRead == 0);
624 if (pixelsAdded == 0) {
625 throw std::runtime_error("No pixels could be added from the source file. "
626 "Please check the irun fields of all pixels are valid.");
627 } else if (pixelsAdded != static_cast<size_t>(npixtot)) {
628 g_log.warning("Some pixels within the source file had an invalid irun "
629 "field. They have been ignored.");
630 }
631
632 g_log.debug() << "Time to read all pixels: " << timer.elapsed() << "s\n";
633}
634
639 using Kernel::ThreadPool;
641 auto *ts = new ThreadSchedulerFIFO();
642 ThreadPool tp(ts);
643 m_outputWS->splitAllIfNeeded(ts);
644 tp.joinAll();
645}
646
657 if (m_outputWS->isFileBacked())
658 return;
659 MemoryStats stat;
660 size_t reqdMemory = (npixtot * sizeof(MDEvent<4>) + NPIX_CHUNK * FIELDS_PER_PIXEL) / 1024;
661 if (reqdMemory > stat.availMem()) {
662 g_log.warning() << "It looks as if there is insufficient memory to load the "
663 << "entire file. It is recommended to cancel the algorithm and "
664 "specify "
665 "the OutputFilename option to create a file-backed workspace.\n";
666 }
667}
668
676size_t LoadSQW2::addEventFromBuffer(const float *pixel) {
677 // TODO can goniometerIndex be read from the buffer?
678 // TODO Was the produced with SaveMD?
679 uint16_t goniometerIndex(0);
681 // Is the pixel field valid? Older versions of Horace produced files with
682 // an invalid field and we can't use this. It should be between 1 && nfiles
683 auto irun = static_cast<uint16_t>(pixel[4]);
684 if (irun < 1 || irun > m_nspe) {
685 return 0;
686 }
687 coord_t centers[4] = {pixel[0], pixel[1], pixel[2], pixel[3]};
688 toOutputFrame(centers);
689 auto error = pixel[8];
690 auto added = m_outputWS->addEvent(MDEvent<4>(pixel[7], error * error, static_cast<uint16_t>(irun - 1),
691 goniometerIndex, static_cast<detid_t>(pixel[5]), centers));
692 // At this point the workspace should be setup so that we always add the
693 // event so only do a runtime check in debug mode
694 assert(added == 1);
695 return added;
696}
697
706 if (m_outputFrame == "Q_sample")
707 return;
708 V3D qout = m_uToRLU * V3D(centers[0], centers[1], centers[2]);
709 centers[0] = static_cast<float>(qout[0]);
710 centers[1] = static_cast<float>(qout[1]);
711 centers[2] = static_cast<float>(qout[2]);
712}
713
720 m_outputWS->refreshCache();
721 if (m_outputWS->isFileBacked()) {
722 auto savemd = this->createChildAlgorithm("SaveMD", 0.76, 1.00);
723 savemd->setProperty("InputWorkspace", m_outputWS);
724 savemd->setProperty("UpdateFileBackEnd", true);
725 savemd->executeAsChildAlg();
726 }
727 setProperty("OutputWorkspace", m_outputWS);
728}
729
730} // namespace Mantid::MDAlgorithms
static std::unique_ptr< QThreadPool > tp
double error
Definition: IndexPeaks.cpp:133
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define DECLARE_FILELOADER_ALGORITHM(classname)
DECLARE_FILELOADER_ALGORITHM should be used in place of the standard DECLARE_ALGORITHM macro when wri...
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
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
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Definition: Algorithm.cpp:842
@ OptionalSave
to specify a file to write to but an empty string is
Definition: FileProperty.h:50
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
A property class for workspaces.
The class responsible for saving events into nexus file using generic box controller interface Expect...
Templated class holding data about a neutron detection event in N-dimensions (for example,...
Definition: MDEvent.h:36
Class to represent a particular goniometer setting, which is described by the rotation matrix.
Definition: Goniometer.h:55
void pushAxis(const std::string &name, double axisx, double axisy, double axisz, double angle=0., int sense=CCW, int angUnit=angDegrees)
Add an additional axis to the goniometer, closer to the sample.
Definition: Goniometer.cpp:133
const Kernel::DblMatrix & getR() const
Return global rotation matrix.
Definition: Goniometer.cpp:80
void setFrameName(std::string frameName)
Setter for the frame name.
static void resizeToFitMDBox(CoordT &min, CoordT &max)
Push the min/max values out by a defined amount.
void setUnits(const Kernel::UnitLabel &units)
Class to implement UB matrix.
const Kernel::DblMatrix & getBinv() const
Get the inverse of the B-matrix.
Definition: UnitCell.cpp:762
Defines a wrapper around an open file.
static bool isAscii(const std::string &filename, const size_t nbytes=256)
Returns true if the file is considered ascii.
const std::string & extension() const
Access the file extension.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
Definition: ListValidator.h:29
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
bool is(int level) const
Returns true if at least the given log level is set.
Definition: Logger.cpp:146
This class is responsible for memory statistics.
Definition: Memory.h:28
std::size_t availMem() const
Returns the available memory of the system in kiB.
Definition: Memory.cpp:398
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Definition: ProgressBase.h:51
void setNotifyStep(double notifyStepPct)
Override the frequency at which notifications are sent out.
The concrete, templated class for properties.
A Thread Pool implementation that keeps a certain number of threads running (normally,...
Definition: ThreadPool.h:36
A First-In-First-Out Thread Scheduler.
A simple class that provides a wall-clock (not processor time) timer.
Definition: Timer.h:27
float elapsed(bool reset=true)
Returns the wall-clock time elapsed in seconds since the Timer object's creation, or the last call to...
Definition: Timer.cpp:28
Class for 3D vectors.
Definition: V3D.h:34
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
Definition: V3D.h:278
void setupFileBackend(const std::string &filebackPath)
Setup the filebackend for the output workspace.
Definition: LoadSQW2.cpp:566
void exec() override
Execute the algorithm.
Definition: LoadSQW2.cpp:118
void skipDetectorSection()
Skip the data in the detector section.
Definition: LoadSQW2.cpp:290
int32_t readMainHeader()
Reads the initial header section.
Definition: LoadSQW2.cpp:147
std::unique_ptr< Kernel::BinaryStreamReader > m_reader
Definition: LoadSQW2.h:71
std::shared_ptr< API::ExperimentInfo > readSingleSPEHeader()
Read single SPE header from the file.
Definition: LoadSQW2.cpp:205
void initFileReader()
Opens the file given to the algorithm and initializes the reader.
Definition: LoadSQW2.cpp:134
void readSQWDimensions()
Read and create the SQW dimensions on the output.
Definition: LoadSQW2.cpp:335
size_t addEventFromBuffer(const float *pixel)
Assume the given pointer points to the start of a full pixel and create an MDEvent based on it iff it...
Definition: LoadSQW2.cpp:676
std::unique_ptr< std::ifstream > m_file
Definition: LoadSQW2.h:70
void setupBoxController()
Setup the box controller based on the bin structure.
Definition: LoadSQW2.cpp:540
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
Definition: LoadSQW2.cpp:67
Kernel::DblMatrix m_uToRLU
Definition: LoadSQW2.h:74
Geometry::IMDDimension_sptr createEnDimension(float umin, float umax, size_t nbins)
Create an energy dimension.
Definition: LoadSQW2.cpp:524
void finalize()
Assumed to be the last step in the algorithm.
Definition: LoadSQW2.cpp:718
int version() const override
Algorithm's version for identification.
Definition: LoadSQW2.cpp:60
void init() override
Initialize the algorithm's properties.
Definition: LoadSQW2.cpp:93
std::vector< float > calculateDimLimitsFromData()
Find the dimension limits for each dimension in the target frame.
Definition: LoadSQW2.cpp:419
void skipDataSectionMetadata()
Skip metadata in data section.
Definition: LoadSQW2.cpp:317
Geometry::IMDDimension_sptr createQDimension(size_t index, float dimMin, float dimMax, size_t nbins, const Kernel::DblMatrix &bmat)
Create the Q MDHistoDimension for the output frame and given information from the file.
Definition: LoadSQW2.cpp:476
void warnIfMemoryInsufficient(int64_t npixtot)
If the output is not file backed and the machine appears to have insufficient memory to read the data...
Definition: LoadSQW2.cpp:654
void throwIfUnsupportedFileType(int32_t sqwType)
Throw std::runtime_error if the sqw type of the file is unsupported.
Definition: LoadSQW2.cpp:173
void cacheFrameTransforms(const Geometry::OrientedLattice &lattice)
Cache the transforms between the Q_sample & HKL frames from the given lattice.
Definition: LoadSQW2.cpp:282
void readAllSPEHeadersToWorkspace()
Read all of the SPE headers and fill in the experiment details on the output workspace.
Definition: LoadSQW2.cpp:190
void createOutputWorkspace()
Create the output workspace object.
Definition: LoadSQW2.cpp:182
void readPixelDataIntoWorkspace()
Read the pixel data into the workspace.
Definition: LoadSQW2.cpp:586
int confidence(Kernel::FileDescriptor &descriptor) const override
Return the confidence with this algorithm can load the file.
Definition: LoadSQW2.cpp:78
std::shared_ptr< SQWWorkspace > m_outputWS
Definition: LoadSQW2.h:72
void toOutputFrame(coord_t *centers)
Transform the given coordinates to the requested output frame if necessary.
Definition: LoadSQW2.cpp:705
void splitAllBoxes()
Split boxes in the output workspace if required.
Definition: LoadSQW2.cpp:638
const std::string category() const override
Algorithm's category for identification.
Definition: LoadSQW2.cpp:63
void cacheInputs()
Cache any user input to avoid repeated lookups.
Definition: LoadSQW2.cpp:131
std::vector< int32_t > readProjection()
Read the required parts of the projection information from the data section The file pointer is assum...
Definition: LoadSQW2.cpp:380
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< IMDDimension > IMDDimension_sptr
Shared Pointer for IMDDimension. Frequently used type in framework.
Definition: IMDDimension.h:98
Mantid::Kernel::Matrix< double > DblMatrix
Definition: Matrix.h:206
std::string DLLExport sprintfd(const double data, const double eps)
creates string representation of the number with accuracy, cpecified by eps
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Definition: MDTypes.h:27
int32_t detid_t
Typedef for a detector ID.
Definition: SpectrumInfo.h:21
STL namespace.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Output
An output workspace.
Definition: Property.h:54