Mantid
Loading...
Searching...
No Matches
LoadRawHelper.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#include "LoadRaw/isisraw2.h"
9
10#include "MantidAPI/Axis.h"
18#include "MantidKernel/Glob.h"
23#include <Poco/File.h>
24#include <Poco/Path.h>
25#include <boost/algorithm/string/predicate.hpp>
26#include <cstdio>
27
28namespace {
33inline std::string alternateDataStream(const Poco::Path &filePath) { return filePath.toString() + ":checksum"; }
34
40#ifdef _WIN32
41inline bool hasAlternateDataStream(const Poco::Path &pathToFile) {
42 std::ifstream adsStream(alternateDataStream(pathToFile));
43 if (!adsStream) {
44 return false;
45 }
46 adsStream.close();
47 return true;
48}
49#else
50inline bool hasAlternateDataStream([[maybe_unused]] const Poco::Path &pathToFile) { return false; }
51#endif
52
60std::set<std::string> logFilesFromAlternateDataStream(const Poco::Path &pathToRawFile) {
61 std::set<std::string> logfilesList;
62 std::ifstream adsStream(alternateDataStream(pathToRawFile));
63 if (!adsStream) {
64 return logfilesList;
65 }
66
67 // An example of alternate stream content:
68 // ad0bc56c4c556fa368565000f01e77f7 *IRIS00055132.log
69 // d5ace6dc7ac6c4365d48ee1f2906c6f4 *IRIS00055132.nxs
70 // 9c70ad392023515f775af3d3984882f3 *IRIS00055132.raw
71 // 66f74b6c0cc3eb497b92d4956ed8d6b5 *IRIS00055132_ICPdebug.txt
72 // e200aa65186b61e487175d5263b315aa *IRIS00055132_ICPevent.txt
73 // 91be40aa4f54d050a9eb4abea394720e *IRIS00055132_ICPstatus.txt
74 // 50aa2872110a9b862b01c6c83f8ce9a8 *IRIS00055132_Status.txt
75 Poco::Path dirOfFile(pathToRawFile.parent());
76 std::string line;
77 while (Mantid::Kernel::Strings::extractToEOL(adsStream, line)) {
78 if (boost::algorithm::iends_with(line, ".txt") || boost::algorithm::iends_with(line, ".log")) {
79 const size_t asteriskPos = line.find('*');
80 if (asteriskPos == std::string::npos)
81 continue;
82 Poco::Path logFilePath(dirOfFile);
83 logFilePath.append(line.substr(asteriskPos + 1));
84 if (Poco::File(logFilePath).exists()) {
85 logfilesList.insert(logFilePath.toString());
86 }
87 }
88 }
89 return logfilesList;
90}
91
92} // namespace
93
94namespace Mantid::DataHandling {
95
96using namespace Kernel;
97using namespace API;
98using Types::Core::DateAndTime;
99
102 : m_list(false), m_interval(false), m_spec_list(), m_spec_min(0), m_spec_max(EMPTY_INT()), m_numberOfPeriods(0),
103 m_isis_raw(), m_cache_options(), m_specTimeRegimes(), m_prog(0.0), m_numberOfSpectra(0), m_monitordetectorList(),
104 m_bmspeclist(false), m_total_specs(0), m_logCreator() {}
105
108
111 const std::vector<std::string> exts{".raw", ".s*", ".add"};
112 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Load, exts),
113 "The name of the RAW file to read, including its full or "
114 "relative path. The file extension must be .raw or .RAW "
115 "(N.B. case sensitive if running on Linux).");
116 declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("OutputWorkspace", "", Direction::Output),
117 "The name of the workspace that will be created, filled with "
118 "the read-in data and stored in the Analysis Data Service. "
119 "If the input RAW file contains multiple periods higher "
120 "periods will be stored in separate workspaces called "
121 "OutputWorkspace_PeriodNo.");
122
123 m_cache_options.emplace_back("If Slow");
124 m_cache_options.emplace_back("Always");
125 m_cache_options.emplace_back("Never");
126 declareProperty("Cache", "If Slow", std::make_shared<StringListValidator>(m_cache_options),
127 "An option allowing the algorithm to cache a remote file on "
128 "the local drive before loading. When \"If Slow\" is set the "
129 "download speed is estimated and if is deemed as slow the "
130 "file is cached. \"Always\" means always cache a remote file "
131 "and \"Never\" - never cache.");
132
133 declareProperty("LoadLogFiles", true,
134 "Boolean option to load or skip log files. If this option is "
135 "set all the log files associated with the selected raw file "
136 "are loaded into workspace and can be displayed using right "
137 "click menu item Sample Logs...on the selected "
138 "workspace.\nNote: If the log files contain motor positions, "
139 "etc. that would affect the instrument geometry this option "
140 "must be set to true for these adjustments to be applied to "
141 "the instrument geometry.");
142}
147FILE *LoadRawHelper::openRawFile(const std::string &fileName) {
148 FILE *file = fopen(fileName.c_str(), "rb");
149 if (file == nullptr) {
150 throw Exception::FileError("Unable to open File:", fileName);
151 }
152 // Need to check that the file is not a text file as the ISISRAW routines
153 // don't deal with these very well, i.e
154 // reading continues until a bad_alloc is encountered.
156 fclose(file);
157 std::stringstream os;
158 os << "File \"" << fileName
159 << "\" is not a valid RAW file. The first 256 bytes suggest it is an "
160 "ascii file.\n";
161 throw std::invalid_argument(os.str());
162 }
163
164 return file;
165}
170void LoadRawHelper::readTitle(FILE *file, std::string &title) {
171 ioRaw(file, true);
172 title = std::string(isisRaw().r_title, 80);
173 g_log.information("*** Run title: " + title + " ***");
174}
179void LoadRawHelper::skipData(FILE *file, int hist) { isisRaw().skipData(file, hist); }
180void LoadRawHelper::skipData(FILE *file, int64_t hist) { skipData(file, static_cast<int>(hist)); }
184void LoadRawHelper::ioRaw(FILE *file, bool from_file) { isisRaw().ioRAW(file, from_file); }
186
192 if (!m_isis_raw) {
193 m_isis_raw = std::make_unique<ISISRAW2>();
194 }
195
196 return *m_isis_raw;
197}
198
200
206bool LoadRawHelper::readData(FILE *file, int hist) { return isisRaw().readData(file, hist); }
207bool LoadRawHelper::readData(FILE *file, int64_t hist) { return readData(file, static_cast<int>(hist)); }
208
210
220 std::string run_num = std::to_string(isisRaw().r_number);
221 run.addLogData(new PropertyWithValue<std::string>("run_number", run_num));
222}
229void LoadRawHelper::readworkspaceParameters(specnum_t &numberOfSpectra, int &numberOfPeriods, int64_t &lengthIn,
230 int64_t &noTimeRegimes) {
231 // Read in the number of spectra in the RAW file
232 m_numberOfSpectra = numberOfSpectra = static_cast<specnum_t>(isisRaw().t_nsp1);
233 // Read the number of periods in this file
234 numberOfPeriods = isisRaw().t_nper;
235 // Read the number of time channels (i.e. bins) from the RAW file
236 const int64_t channelsPerSpectrum = isisRaw().t_ntc1;
237 // Read in the time bin boundaries
238 lengthIn = channelsPerSpectrum + 1;
239 // Now check whether there is more than one time regime in use
240 noTimeRegimes = isisRaw().daep.n_tr_shift;
241}
250 int64_t nVectors, int64_t xLengthIn, int64_t yLengthIn) {
252 if (!ws_sptr)
253 return empty;
254 DataObjects::Workspace2D_sptr workspace = std::dynamic_pointer_cast<DataObjects::Workspace2D>(
255 WorkspaceFactory::Instance().create(ws_sptr, nVectors, xLengthIn, yLengthIn));
256 return workspace;
257}
258
268DataObjects::Workspace2D_sptr LoadRawHelper::createWorkspace(int64_t nVectors, int64_t xlengthIn, int64_t ylengthIn,
269 const std::string &title) {
271 if (nVectors > 0) {
272 workspace = std::dynamic_pointer_cast<DataObjects::Workspace2D>(
273 WorkspaceFactory::Instance().create("Workspace2D", nVectors, xlengthIn, ylengthIn));
274 // Set the units
275 workspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
276 workspace->setYUnit("Counts");
277 workspace->setTitle(title);
278 }
279 return workspace;
280}
281
294 const DataObjects::Workspace2D_sptr &normalws_sptr,
295 WorkspaceGroup_sptr &mongrp_sptr, const int64_t mwsSpecs,
296 const int64_t nwsSpecs, const int64_t numberOfPeriods,
297 const int64_t lengthIn, const std::string &title,
298 API::Algorithm *const pAlg) {
299 try {
300 // create monitor group workspace
301 mongrp_sptr = createGroupWorkspace(); // create workspace
302 // create monitor workspace
303 if (mwsSpecs > 0) {
304 if (normalws_sptr) {
305 monws_sptr = createWorkspace(normalws_sptr, mwsSpecs, lengthIn, lengthIn - 1);
306
307 } else {
308 monws_sptr = createWorkspace(mwsSpecs, lengthIn, lengthIn - 1, title);
309 }
310 }
311 if (!monws_sptr)
312 return;
313
314 std::string wsName = pAlg->getPropertyValue("OutputWorkspace");
315 // if the normal output workspace size>0 then set the workspace as
316 // "MonitorWorkspace"
317 // otherwise set the workspace as "OutputWorkspace"
318 if (nwsSpecs > 0) {
319 std::string monitorwsName = wsName + "_monitors";
320 pAlg->declareProperty(
321 std::make_unique<WorkspaceProperty<Workspace>>("MonitorWorkspace", monitorwsName, Direction::Output));
322 setWorkspaceProperty("MonitorWorkspace", title, mongrp_sptr, monws_sptr, numberOfPeriods, true, pAlg);
323 } else {
324 // if only monitors range selected
325 // then set the monitor workspace as the output workspace
326 setWorkspaceProperty("OutputWorkspace", title, mongrp_sptr, monws_sptr, numberOfPeriods, false, pAlg);
327 }
328
329 } catch (std::out_of_range &) {
330 pAlg->getLogger().debug() << "Error in creating monitor workspace\n";
331 } catch (std::runtime_error &) {
332 pAlg->getLogger().debug() << "Error in creating monitor workspace\n";
333 }
334}
335
344
353 const WorkspaceGroup_sptr &grpws_sptr, const int64_t period, bool bmonitors,
354 API::Algorithm *const pAlg) {
355 if (!ws_sptr)
356 return;
357 if (!grpws_sptr)
358 return;
359 std::string wsName;
360 std::string outws;
361 std::string outputWorkspace;
362 std::string localWSName = pAlg->getProperty("OutputWorkspace");
363 std::stringstream suffix;
364 suffix << (period + 1);
365 if (bmonitors) {
366 wsName = localWSName + "_monitors" + "_" + suffix.str();
367 outputWorkspace = "MonitorWorkspace";
368 } else {
369 wsName = localWSName + "_" + suffix.str();
370 outputWorkspace = "OutputWorkspace";
371 }
372 outws = outputWorkspace + "_" + suffix.str();
373 pAlg->declareProperty(std::make_unique<WorkspaceProperty<Workspace>>(outws, wsName, Direction::Output));
374 pAlg->setProperty(outws, std::static_pointer_cast<Workspace>(ws_sptr));
375 grpws_sptr->addWorkspace(ws_sptr);
376}
377
388void LoadRawHelper::setWorkspaceProperty(const std::string &propertyName, const std::string &title,
389 const WorkspaceGroup_sptr &grpws_sptr,
390 const DataObjects::Workspace2D_sptr &ws_sptr, int64_t numberOfPeriods,
391 [[maybe_unused]] bool bMonitor, API::Algorithm *const pAlg) {
392 Property *ws = pAlg->getProperty("OutputWorkspace");
393 if (!ws)
394 return;
395 if (!grpws_sptr)
396 return;
397 if (!ws_sptr)
398 return;
399 ws_sptr->setTitle(title);
400 ws_sptr->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
401 if (numberOfPeriods > 1) {
402 pAlg->setProperty(propertyName, std::dynamic_pointer_cast<Workspace>(grpws_sptr));
403 } else {
404 pAlg->setProperty(propertyName, std::dynamic_pointer_cast<Workspace>(ws_sptr));
405 }
406}
407
418 const std::vector<std::shared_ptr<HistogramData::HistogramX>> &timeChannelsVec,
419 int64_t wsIndex, specnum_t nspecNum, int64_t noTimeRegimes, int64_t lengthIn,
420 int64_t binStart) {
421 if (!newWorkspace)
422 return;
423
424 // But note that the last (overflow) bin is kept
425 auto &Y = newWorkspace->mutableY(wsIndex);
426 Y.assign(isisRaw().dat1 + binStart, isisRaw().dat1 + lengthIn);
427 // Fill the vector for the errors, containing sqrt(count)
428 newWorkspace->setCountVariances(wsIndex, Y.rawData());
429
430 newWorkspace->getSpectrum(wsIndex).setSpectrumNo(nspecNum);
431 // for loadrawbin0
432 if (binStart == 0) {
433 newWorkspace->setX(wsIndex, timeChannelsVec[0]);
434 return;
435 }
436 // for loadrawspectrum 0
437 if (nspecNum == 0) {
438 newWorkspace->setX(wsIndex, timeChannelsVec[0]);
439 return;
440 }
441 // Set the X vector pointer and spectrum number
442 if (noTimeRegimes < 2)
443 newWorkspace->setX(wsIndex, timeChannelsVec[0]);
444 else {
445
446 // Use std::vector::at just incase spectrum missing from spec array
447 newWorkspace->setX(wsIndex, timeChannelsVec.at(m_specTimeRegimes[nspecNum] - 1));
448 }
449}
450
456 std::vector<specnum_t> spectrumIndices;
457
458 if (!m_monitordetectorList.empty()) {
459 const auto &map = mapping.getMapping();
460 for (const auto &SpectrumDetectorPair : map) {
461 auto detIDs = SpectrumDetectorPair.second;
462 // Both m_monitordetectorList & detIDs should be (very) short so the
463 // nested loop shouldn't be too evil
464 for (auto detID : detIDs) {
465 if (std::find(m_monitordetectorList.begin(), m_monitordetectorList.end(), detID) !=
466 m_monitordetectorList.end()) {
467 spectrumIndices.emplace_back(SpectrumDetectorPair.first);
468 }
469 }
470 }
471 } else {
472 g_log.error() << "monitor detector id list is empty for the selected workspace\n";
473 }
474
475 return spectrumIndices;
476}
477
482
490std::vector<std::shared_ptr<HistogramData::HistogramX>> LoadRawHelper::getTimeChannels(const int64_t &regimes,
491 const int64_t &lengthIn) {
492 auto const timeChannels = new float[lengthIn];
493 isisRaw().getTimeChannels(timeChannels, static_cast<int>(lengthIn));
494
495 std::vector<std::shared_ptr<HistogramData::HistogramX>> timeChannelsVec;
496 if (regimes >= 2) {
497 g_log.debug() << "Raw file contains " << regimes << " time regimes\n";
498 // If more than 1 regime, create a timeChannelsVec for each regime
499 auto &isisRawRef = isisRaw();
500 for (int64_t i = 0; i < regimes; ++i) {
501 // Create a vector with the 'base' time channels
502 std::shared_ptr<HistogramData::HistogramX> channelsVec(
503 new HistogramData::HistogramX(timeChannels, timeChannels + lengthIn));
504 const double shift = isisRawRef.daep.tr_shift[i];
505 g_log.debug() << "Time regime " << i + 1 << " shifted by " << shift << " microseconds\n";
506 // Add on the shift for this vector
507 using std::placeholders::_1;
508 std::transform(channelsVec->begin(), channelsVec->end(), channelsVec->begin(),
509 std::bind(std::plus<double>(), _1, shift));
510 timeChannelsVec.emplace_back(channelsVec);
511 }
512 // In this case, also need to populate the map of spectrum-regime
513 // correspondence
514 const auto ndet = static_cast<int64_t>(isisRawRef.i_det);
515 auto hint = m_specTimeRegimes.begin();
516 for (int64_t j = 0; j < ndet; ++j) {
517 // No checking for consistency here - that all detectors for given
518 // spectrum
519 // are declared to use same time regime. Will just use first encountered
520 hint = m_specTimeRegimes.insert(hint, std::make_pair(isisRawRef.spec[j], isisRawRef.timr[j]));
521 }
522 } else // Just need one in this case
523 {
524 std::shared_ptr<HistogramData::HistogramX> channelsVec(
525 new HistogramData::HistogramX(timeChannels, timeChannels + lengthIn));
526 timeChannelsVec.emplace_back(channelsVec);
527 }
528 // Done with the timeChannels C array so clean up
529 delete[] timeChannels;
530 return timeChannelsVec;
531}
532
538void LoadRawHelper::runLoadInstrument(const std::string &fileName, const DataObjects::Workspace2D_sptr &localWorkspace,
539 double progStart, double progEnd) {
540 g_log.debug("Loading the instrument definition...");
541 m_prog = progStart;
542 progress(m_prog, "Loading the instrument geometry...");
543
544 std::string instrumentID = isisRaw().i_inst; // get the instrument name
545 size_t i = instrumentID.find_first_of(' '); // cut trailing spaces
546 if (i != std::string::npos)
547 instrumentID.erase(i);
548
549 auto loadInst = createChildAlgorithm("LoadInstrument");
550 // Enable progress reporting by Child Algorithm -
551 loadInst->addObserver(this->progressObserver());
552 setChildStartProgress(progStart);
553 setChildEndProgress((progStart + progEnd) / 2);
554 // Now execute the Child Algorithm. Catch and log any error, but don't stop.
555 bool executionSuccessful(true);
556 try {
557 loadInst->setPropertyValue("InstrumentName", instrumentID);
558 loadInst->setProperty<MatrixWorkspace_sptr>("Workspace", localWorkspace);
559 loadInst->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false));
560 loadInst->execute();
561 } catch (std::invalid_argument &) {
562 g_log.information("Invalid argument to LoadInstrument Child Algorithm");
563 executionSuccessful = false;
564 } catch (std::runtime_error &) {
565 g_log.information("Unable to successfully run LoadInstrument Child Algorithm");
566 executionSuccessful = false;
567 }
568
569 // If loading instrument definition file fails, run LoadInstrumentFromRaw
570 // instead
571 if (!executionSuccessful) {
572 g_log.information() << "Instrument definition file "
573 << " not found. Attempt to load information about \n"
574 << "the instrument from raw data file.\n";
575 runLoadInstrumentFromRaw(fileName, localWorkspace);
576 } else {
577 // If requested update the instrument to positions in the raw file
578 const auto &pmap = localWorkspace->constInstrumentParameters();
579 if (pmap.contains(localWorkspace->getInstrument()->getComponentID(), "det-pos-source")) {
580 std::shared_ptr<Geometry::Parameter> updateDets =
581 pmap.get(localWorkspace->getInstrument()->getComponentID(), "det-pos-source");
582 std::string value = updateDets->value<std::string>();
583 if (value.substr(0, 8) == "datafile") {
584 auto updateInst = createChildAlgorithm("UpdateInstrumentFromFile");
585 updateInst->setProperty<MatrixWorkspace_sptr>("Workspace", localWorkspace);
586 updateInst->setPropertyValue("Filename", fileName);
587 updateInst->addObserver(this->progressObserver()); // Enable progress
588 // reporting by
589 // ChildAlgorithm
590 setChildStartProgress((progStart + progEnd) / 2);
591 setChildEndProgress(progEnd);
592 if (value == "datafile-ignore-phi") {
593 updateInst->setProperty("IgnorePhi", true);
594 g_log.information("Detector positions in IDF updated with positions "
595 "in the data file except for the phi values");
596 } else {
597 g_log.information("Detector positions in IDF updated with positions "
598 "in the data file");
599 }
600 // We want this to throw if it fails to warn the user that the
601 // information is not correct.
602 updateInst->execute();
603 }
604 }
605 // Debugging code??
606 m_monitordetectorList = loadInst->getProperty("MonitorList");
607 std::vector<specnum_t>::const_iterator itr;
608 for (itr = m_monitordetectorList.begin(); itr != m_monitordetectorList.end(); ++itr) {
609 g_log.debug() << "Monitor detector id is " << (*itr) << '\n';
610 }
611 }
612}
613
618void LoadRawHelper::runLoadInstrumentFromRaw(const std::string &fileName,
619 const DataObjects::Workspace2D_sptr &localWorkspace) {
620 auto loadInst = createChildAlgorithm("LoadInstrumentFromRaw");
621 loadInst->setPropertyValue("Filename", fileName);
622 // Set the workspace property to be the same one filled above
623 loadInst->setProperty<MatrixWorkspace_sptr>("Workspace", localWorkspace);
624
625 // Now execute the Child Algorithm. Catch and log any error, but don't stop.
626 try {
627 loadInst->execute();
628 } catch (std::runtime_error &) {
629 g_log.error("Unable to successfully run LoadInstrumentFromRaw Child Algorithm");
630 }
631 m_monitordetectorList = loadInst->getProperty("MonitorList");
632 std::vector<specnum_t>::const_iterator itr;
633 for (itr = m_monitordetectorList.begin(); itr != m_monitordetectorList.end(); ++itr) {
634 g_log.debug() << "Monitor dtector id is " << (*itr) << '\n';
635 }
636 if (!loadInst->isExecuted()) {
637 g_log.error("No instrument definition loaded");
638 }
639}
640
644void LoadRawHelper::runLoadMappingTable(const std::string &fileName,
645 const DataObjects::Workspace2D_sptr &localWorkspace) {
646 g_log.debug("Loading the spectra-detector mapping...");
647 progress(m_prog, "Loading the spectra-detector mapping...");
648 // Now determine the spectra to detector map calling Child Algorithm
649 // LoadMappingTable
650 // There is a small penalty in re-opening the raw file but nothing major.
651 auto loadmap = createChildAlgorithm("LoadMappingTable");
652 loadmap->setPropertyValue("Filename", fileName);
653 loadmap->setProperty<MatrixWorkspace_sptr>("Workspace", localWorkspace);
654 try {
655 loadmap->execute();
656 } catch (std::runtime_error &) {
657 g_log.error("Unable to successfully execute LoadMappingTable Child Algorithm");
658 }
659
660 if (!loadmap->isExecuted()) {
661 g_log.error("LoadMappingTable Child Algorithm is not executed");
662 }
663}
664
670void LoadRawHelper::runLoadLog(const std::string &fileName, const DataObjects::Workspace2D_sptr &localWorkspace,
671 double progStart, double progEnd) {
672 // search for the log file to load, and save their names in a list.
673 std::list<std::string> logFiles = searchForLogFiles(Poco::Path(fileName));
674
675 g_log.debug("Loading the log files...");
676 if (progStart < progEnd) {
677 m_prog = progStart;
678 }
679
680 progress(m_prog, "Reading log files...");
681
682 // Iterate over and load each log file into the localWorkspace.
683 std::list<std::string>::const_iterator logPath;
684 for (logPath = logFiles.begin(); logPath != logFiles.end(); ++logPath) {
685 // check for log files we should just ignore
686 std::string statusSuffix = "ICPstatus.txt";
687 if (boost::algorithm::iends_with(*logPath, statusSuffix)) {
688 g_log.information("Skipping log file: " + *logPath);
689 continue;
690 }
691
692 std::string debugSuffix = "ICPdebug.txt";
693 if (boost::algorithm::iends_with(*logPath, debugSuffix)) {
694 g_log.information("Skipping log file: " + *logPath);
695 continue;
696 }
697
698 std::string alarmSuffix = "ICPalarm.txt";
699 if (boost::algorithm::iends_with(*logPath, alarmSuffix)) {
701 g_log.information("Skipping empty log file: " + *logPath);
702 continue;
703 }
704 }
705
706 // Create a new object for each log file.
707 auto loadLog = createChildAlgorithm("LoadLog");
708
709 // Pass through the same input filename
710 loadLog->setPropertyValue("Filename", *logPath);
711 // Set the workspace property to be the same one filled above
712 loadLog->setProperty<MatrixWorkspace_sptr>("Workspace", localWorkspace);
713 // Pass the name of the log file explicitly to LoadLog.
714 loadLog->setPropertyValue("Names", extractLogName(*logPath));
715
716 // Force loading two column file if it's an ISIS ICPevent log
717 if (boost::algorithm::ends_with(*logPath, "ICPevent.txt")) {
718 loadLog->setPropertyValue("NumberOfColumns", "2");
719 }
720
721 // Enable progress reporting by Child Algorithm - if progress range has
722 // duration
723 if (progStart < progEnd) {
724 loadLog->addObserver(this->progressObserver());
725 setChildStartProgress(progStart);
726 setChildEndProgress(progEnd);
727 }
728 // Now execute the Child Algorithm. Catch any error, but don't stop.
729 try {
730 loadLog->setLogging(false);
731 loadLog->execute();
732 if (!loadLog->isExecuted())
733 g_log.warning("Unable to successfully run LoadLog Child Algorithm");
734
735 } catch (std::exception &ex) {
736 g_log.warning("Unable to successfully run LoadLog Child Algorithm: ");
737 g_log.warning(ex.what());
738 }
739 }
740 // Make log creator object and add the run status log if we have the
741 // appropriate ICP log
742 m_logCreator.reset(new ISISRunLogs(localWorkspace->run()));
743 m_logCreator->addStatusLog(localWorkspace->mutableRun());
744}
745
751std::string LoadRawHelper::extractLogName(const std::string &path) {
752 // The log file's name, including workspace (e.g. CSP78173_ICPevent)
753 std::string fileName = Poco::Path(Poco::Path(path).getFileName()).getBaseName();
754 // Return only the log name (excluding workspace, e.g. ICPevent)
755 return (fileName.substr(fileName.find('_') + 1));
756}
757
763void LoadRawHelper::createPeriodLogs(int64_t period, const DataObjects::Workspace2D_sptr &local_workspace) {
764 m_logCreator->addPeriodLogs(static_cast<int>(period), local_workspace->mutableRun());
765}
766
774void LoadRawHelper::loadRunParameters(const API::MatrixWorkspace_sptr &localWorkspace, ISISRAW *const rawFile) const {
775 ISISRAW &localISISRaw = [this, rawFile]() -> ISISRAW & {
776 if (rawFile)
777 return *rawFile;
778 else
779 return this->isisRaw();
780 }();
781
782 API::Run &runDetails = localWorkspace->mutableRun();
783
784 runDetails.addProperty("run_header", RawFileInfo::runHeader(localISISRaw));
785 // Run title is stored in a different attribute
786 runDetails.addProperty("run_title", RawFileInfo::runTitle(localISISRaw), true);
787
788 runDetails.addProperty("user_name", std::string(localISISRaw.hdr.hd_user, 20));
789 runDetails.addProperty("inst_abrv", std::string(localISISRaw.hdr.inst_abrv, 3));
790 runDetails.addProperty("hd_dur", std::string(localISISRaw.hdr.hd_dur, 8));
791
792 // Data details on run not the workspace
793 runDetails.addProperty("nspectra", static_cast<int>(localISISRaw.t_nsp1));
794 runDetails.addProperty("nchannels", static_cast<int>(localISISRaw.t_ntc1));
795 runDetails.addProperty("nperiods", static_cast<int>(localISISRaw.t_nper));
796
797 // RPB struct info
798 runDetails.addProperty("dur", localISISRaw.rpb.r_dur); // actual run duration
799 runDetails.addProperty("durunits", localISISRaw.rpb.r_durunits); // scaler for above (1=seconds)
800 runDetails.addProperty("dur_freq",
801 localISISRaw.rpb.r_dur_freq); // testinterval for above (seconds)
802 runDetails.addProperty("dmp", localISISRaw.rpb.r_dmp); // dump interval
803 runDetails.addProperty("dmp_units",
804 localISISRaw.rpb.r_dmp_units); // scaler for above
805 runDetails.addProperty("dmp_freq",
806 localISISRaw.rpb.r_dmp_freq); // interval for above
807 runDetails.addProperty("freq",
808 localISISRaw.rpb.r_freq); // 2**k where source frequency = 50 / 2**k
809 runDetails.addProperty("gd_prtn_chrg",
810 static_cast<double>(localISISRaw.rpb.r_gd_prtn_chrg)); // good proton charge (uA.hour)
811 runDetails.addProperty("tot_prtn_chrg",
812 static_cast<double>(localISISRaw.rpb.r_tot_prtn_chrg)); // total proton charge (uA.hour)
813 runDetails.addProperty("goodfrm", localISISRaw.rpb.r_goodfrm); // good frames
814 runDetails.addProperty("rawfrm", localISISRaw.rpb.r_rawfrm); // raw frames
815 runDetails.addProperty("dur_wanted", localISISRaw.rpb.r_dur_wanted); // requested run duration
816 // (units as for "duration"
817 // above)
818 runDetails.addProperty("dur_secs",
819 localISISRaw.rpb.r_dur_secs); // actual run duration in seconds
820 runDetails.addProperty("mon_sum1",
821 localISISRaw.rpb.r_mon_sum1); // monitor sum 1
822 runDetails.addProperty("mon_sum2",
823 localISISRaw.rpb.r_mon_sum2); // monitor sum 2
824 runDetails.addProperty("mon_sum3",
825 localISISRaw.rpb.r_mon_sum3); // monitor sum 3
826 runDetails.addProperty("rb_proposal",
827 localISISRaw.rpb.r_prop); // RB (proposal) number
828
829 // Note isis raw date format which is stored in DD-MMM-YYYY. Store dates in
830 // ISO 8601
831 auto endTime = extractEndTime(localISISRaw);
832 runDetails.addProperty("run_end", endTime.toISO8601String());
833
834 auto startTime = extractStartTime(localISISRaw);
835 runDetails.addProperty("run_start", startTime.toISO8601String());
836}
837
843Types::Core::DateAndTime LoadRawHelper::extractEndTime(ISISRAW &isisRaw) {
844 std::string isisDate = std::string(isisRaw.rpb.r_enddate, 11);
845 if (isisDate[0] == ' ')
846 isisDate[0] = '0';
847 return DateAndTime(isisDate.substr(7, 4) + "-" + convertMonthLabelToIntStr(isisDate.substr(3, 3)) + "-" +
848 isisDate.substr(0, 2) + "T" + std::string(isisRaw.rpb.r_endtime, 8));
849}
850
856Types::Core::DateAndTime LoadRawHelper::extractStartTime(ISISRAW &isisRaw) {
857 auto isisDate = std::string(isisRaw.hdr.hd_date, 11);
858 if (isisDate[0] == ' ')
859 isisDate[0] = '0';
860 return DateAndTime(isisDate.substr(7, 4) + "-" + convertMonthLabelToIntStr(isisDate.substr(3, 3)) + "-" +
861 isisDate.substr(0, 2) + "T" + std::string(isisRaw.hdr.hd_time, 8));
862}
863
867std::string LoadRawHelper::convertMonthLabelToIntStr(std::string month) {
868 std::transform(month.begin(), month.end(), month.begin(), toupper);
869
870 if (month == "JAN")
871 return "01";
872 if (month == "FEB")
873 return "02";
874 if (month == "MAR")
875 return "03";
876 if (month == "APR")
877 return "04";
878 if (month == "MAY")
879 return "05";
880 if (month == "JUN")
881 return "06";
882 if (month == "JUL")
883 return "07";
884 if (month == "AUG")
885 return "08";
886 if (month == "SEP")
887 return "09";
888 if (month == "OCT")
889 return "10";
890 if (month == "NOV")
891 return "11";
892 if (month == "DEC")
893 return "12";
894
895 throw std::runtime_error("LoadRawHelper::convertMonthLabelToIntStr(): Invalid month label found.");
896}
897
902void LoadRawHelper::setOptionalProperties(const int &spec_min, const int &spec_max, const std::vector<int> &spec_list) {
903 m_spec_min = spec_min;
904 m_spec_max = spec_max;
905 m_spec_list.assign(spec_list.begin(), spec_list.end());
906}
907
910 // read in the settings passed to the algorithm
911 /*m_spec_list = getProperty("SpectrumList");
912 m_spec_max = getProperty("SpectrumMax");
913 m_spec_min = getProperty("SpectrumMin");*/
914
915 m_list = !m_spec_list.empty();
916 m_bmspeclist = !m_spec_list.empty();
917 m_interval = (m_spec_max != EMPTY_INT()) || (m_spec_min != 1);
918 if (m_spec_max == EMPTY_INT())
919 m_spec_max = 1;
920 // Check validity of spectra list property, if set
921 if (m_list) {
922 m_list = true;
923 if (m_spec_list.empty()) {
924 m_list = false;
925 } else {
926 const int64_t minlist = *min_element(m_spec_list.begin(), m_spec_list.end());
927 const int64_t maxlist = *max_element(m_spec_list.begin(), m_spec_list.end());
928 if (maxlist > m_numberOfSpectra || minlist <= 0) {
929 g_log.error("Invalid list of spectra");
930 throw std::invalid_argument("Inconsistent properties defined");
931 }
932 }
933 }
934 // Check validity of spectra range, if set
935 if (m_interval) {
936 m_interval = true;
937 // m_spec_min = getProperty("SpectrumMin");
938 if (m_spec_min != 1 && m_spec_max == 1)
940 if (m_spec_max < m_spec_min || m_spec_max > m_numberOfSpectra) {
941 g_log.error("Invalid Spectrum min/max properties");
942 throw std::invalid_argument("Inconsistent properties defined");
943 }
944 }
945}
952 specnum_t total_specs(0);
953 if (m_interval || m_list) {
954 if (m_interval) {
955 if (m_spec_min != 1 && m_spec_max == 1)
957
958 m_total_specs = total_specs = (m_spec_max - m_spec_min + 1);
959 m_spec_max += 1;
960 } else
961 total_specs = 0;
962
963 if (m_list) {
964 if (m_interval) {
965 for (auto it = m_spec_list.begin(); it != m_spec_list.end();)
966 if (*it >= m_spec_min && *it < m_spec_max) {
967 it = m_spec_list.erase(it);
968 } else
969 ++it;
970 }
971 if (m_spec_list.empty())
972 m_list = false;
973 total_specs += static_cast<specnum_t>(m_spec_list.size());
974 m_total_specs = total_specs;
975 }
976 } else {
977 total_specs = m_numberOfSpectra;
978 m_total_specs = total_specs;
979 // In this case want all the spectra, but zeroth spectrum is garbage so go
980 // from 1 to NSP1
981 m_spec_min = 1;
983 }
984 return total_specs;
985}
986
991void LoadRawHelper::calculateWorkspacesizes(const std::vector<specnum_t> &monitorSpecList, specnum_t &normalwsSpecs,
992 specnum_t &monitorwsSpecs) {
993 if (!m_interval && !m_bmspeclist) {
994 monitorwsSpecs = static_cast<specnum_t>(monitorSpecList.size());
995 normalwsSpecs = m_total_specs - monitorwsSpecs;
996 g_log.debug() << "normalwsSpecs when m_interval & m_bmspeclist are false is " << normalwsSpecs
997 << " monitorwsSpecs is " << monitorwsSpecs << '\n';
998 } else if (m_interval || m_bmspeclist) {
999 if (m_interval) {
1000 int msize = 0;
1001 std::vector<specnum_t>::const_iterator itr1;
1002 for (itr1 = monitorSpecList.begin(); itr1 != monitorSpecList.end(); ++itr1) {
1003 if (*itr1 >= m_spec_min && *itr1 < m_spec_max)
1004 ++msize;
1005 }
1006 monitorwsSpecs = msize;
1007 normalwsSpecs = m_total_specs - monitorwsSpecs;
1008 g_log.debug() << "normalwsSpecs when m_interval true is " << normalwsSpecs << " monitorwsSpecs is "
1009 << monitorwsSpecs << '\n';
1010 }
1011 if (m_bmspeclist) {
1012 if (m_interval) {
1013 for (auto itr = m_spec_list.begin(); itr != m_spec_list.end();) { // if the m_spec_list elements are in
1014 // the range between m_spec_min &
1015 // m_spec_max
1016 if (*itr >= m_spec_min && *itr < m_spec_max)
1017 itr = m_spec_list.erase(itr);
1018 else
1019 ++itr;
1020 }
1021 if (m_spec_list.empty()) {
1022 g_log.debug() << "normalwsSpecs is " << normalwsSpecs << " monitorwsSpecs is " << monitorwsSpecs << '\n';
1023 } else { // at this point there are monitors in the list which are not
1024 // in the min& max range
1025 // so find those monitors count and calculate the workspace specs
1026 specnum_t monCounter = 0;
1027 for (auto itr = m_spec_list.begin(); itr != m_spec_list.end(); ++itr) {
1028 const auto monitr = find(monitorSpecList.begin(), monitorSpecList.end(), *itr);
1029 if (monitr != monitorSpecList.end())
1030 ++monCounter;
1031 }
1032 monitorwsSpecs += monCounter;
1033 normalwsSpecs = m_total_specs - monitorwsSpecs;
1034 g_log.debug() << "normalwsSpecs is " << normalwsSpecs << " monitorwsSpecs is " << monitorwsSpecs << '\n';
1035 }
1036 } // end if loop for m_interval
1037 else { // if only List true
1038 specnum_t mSize = 0;
1039 std::vector<specnum_t>::const_iterator itr;
1040 std::vector<specnum_t>::const_iterator monitr;
1041 for (itr = m_spec_list.begin(); itr != m_spec_list.end(); ++itr) {
1042 monitr = find(monitorSpecList.begin(), monitorSpecList.end(), *itr);
1043 if (monitr != monitorSpecList.end()) {
1044 ++mSize;
1045 }
1046 }
1047 monitorwsSpecs = mSize;
1048 normalwsSpecs = m_total_specs - monitorwsSpecs;
1049 }
1050 } // end of if loop for m_bmspeclist
1051 }
1052}
1053
1054void LoadRawHelper::loadSpectra(FILE *file, const int &period, const int &total_specs,
1055 const DataObjects::Workspace2D_sptr &ws_sptr,
1056 const std::vector<std::shared_ptr<HistogramData::HistogramX>> &timeChannelsVec) {
1057 double progStart = m_prog;
1058 double progEnd = 1.0; // Assume this function is called last
1059
1060 int64_t histCurrent = -1;
1061 int64_t wsIndex = 0;
1062 auto &isisRawRef = isisRaw();
1063 auto numberOfPeriods = static_cast<int64_t>(isisRawRef.t_nper);
1064 auto histTotal = static_cast<double>(total_specs * numberOfPeriods);
1065 int64_t noTimeRegimes = getNumberofTimeRegimes();
1066 auto lengthIn = static_cast<int64_t>(isisRawRef.t_ntc1 + 1);
1067
1068 const int64_t periodTimesNSpectraP1 = period * (static_cast<int64_t>(m_numberOfSpectra) + 1);
1069 // loop through spectra
1070 for (specnum_t i = 1; i <= m_numberOfSpectra; ++i) {
1071 int64_t histToRead = i + periodTimesNSpectraP1;
1072 if ((i >= m_spec_min && i < m_spec_max) ||
1073 (m_list && find(m_spec_list.begin(), m_spec_list.end(), i) != m_spec_list.end())) {
1074 progress(m_prog, "Reading raw file data...");
1075
1076 // read spectrum from raw file
1077 if (!readData(file, histToRead))
1078 throw std::runtime_error("Error reading raw file, in "
1079 "LoadRawHelper::loadSpectra, readData failed");
1080 // set workspace data
1081 setWorkspaceData(ws_sptr, timeChannelsVec, wsIndex, i, noTimeRegimes, lengthIn, 1);
1082 ++wsIndex;
1083
1084 if (numberOfPeriods == 1) {
1085 if (++histCurrent % 100 == 0) {
1086 m_prog = progStart + (progEnd - progStart) * (static_cast<double>(histCurrent) / histTotal);
1087 }
1089 }
1090 } else {
1091 skipData(file, histToRead);
1092 }
1093 }
1094}
1095
1103 auto &stream = descriptor.data();
1104 // 85th character is a space & 89th character is a ~
1105 stream.seekg(84, std::ios::beg);
1106 int c = stream.get();
1107 int confidence(0);
1108 if (c == 32) {
1109 stream.seekg(3, std::ios::cur);
1110 c = stream.get();
1111 if (c == 126)
1112 confidence = 80;
1113 }
1114 return confidence;
1115}
1116
1122std::list<std::string> LoadRawHelper::searchForLogFiles(const Poco::Path &pathToRawFile) {
1123 // If pathToRawFile is the filename of a raw datafile then search for
1124 // potential log files
1125 // in the directory of this raw datafile. Otherwise check if it is a potential
1126 // log file. Add the filename of these potential log files to:
1127 // potentialLogFiles.
1128 std::set<std::string> potentialLogFiles;
1129 // Using a list instead of a set to preserve order. The three column names
1130 // will
1131 // be added to the end of the list. This means if a column exists in the two
1132 // and three column file then it will be overridden correctly.
1133 std::list<std::string> potentialLogFilesList;
1134
1135 // File property checks whether the given path exists, just check that is
1136 // actually a file
1137 if (Poco::File(pathToRawFile).isDirectory()) {
1138 throw Exception::FileError("Filename is a directory:", pathToRawFile.toString());
1139 }
1140
1141 // start the process or populating potential log files into the container:
1142 // potentialLogFiles
1143 // have we been given what looks like a log file
1144 const auto fileExt = pathToRawFile.getExtension();
1145 if (boost::algorithm::iequals(fileExt, "log") || boost::algorithm::iequals(fileExt, "txt")) {
1146 // then we will assume that the file is an ISIS log file
1147 potentialLogFiles.insert(pathToRawFile.toString());
1148 } else {
1149 // then we will assume that the file is an ISIS raw file. The file validator
1150 // will have warned the user if the extension is not one of the suggested
1151 // ones.
1152 if (hasAlternateDataStream(pathToRawFile)) {
1154 potentialLogFiles = logFilesFromAlternateDataStream(pathToRawFile);
1155 } else {
1156 // look for log files in the directory of the raw datafile
1157 Poco::Path pattern = pathToRawFile;
1158 pattern.setFileName(pathToRawFile.getBaseName() + "_*.txt");
1159 try {
1160 Kernel::Glob::glob(pattern, potentialLogFiles);
1161 } catch (std::exception &) {
1162 }
1163 // Check for .log
1164 const Poco::File combinedLogPath(Poco::Path(pathToRawFile).setExtension("log"));
1165 if (combinedLogPath.exists()) {
1166 // Push three column filename to end of list.
1167 potentialLogFilesList.insert(potentialLogFilesList.end(), combinedLogPath.path());
1168 }
1169 }
1170
1171 // push potential log files from set to list.
1172 potentialLogFilesList.insert(potentialLogFilesList.begin(), potentialLogFiles.begin(), potentialLogFiles.end());
1173 }
1174 return potentialLogFilesList;
1175}
1176
1181bool LoadRawHelper::isExcludeMonitors(const std::string &monitorOption) { return (monitorOption == "Exclude"); }
1182
1187bool LoadRawHelper::isIncludeMonitors(const std::string &monitorOption) { return (monitorOption == "Include"); }
1188
1193bool LoadRawHelper::isSeparateMonitors(const std::string &monitorOption) { return (monitorOption == "Separate"); }
1204void LoadRawHelper::ProcessLoadMonitorOptions(bool &bincludeMonitors, bool &bseparateMonitors, bool &bexcludeMonitors,
1205 API::Algorithm *pAlgo) {
1206 // process monitor option
1207 std::string monitorOption = pAlgo->getProperty("LoadMonitors");
1208 if (monitorOption == "1")
1209 monitorOption = "Separate";
1210 if (monitorOption == "0")
1211 monitorOption = "Exclude";
1212
1213 bincludeMonitors = LoadRawHelper::isIncludeMonitors(monitorOption);
1214 bseparateMonitors = false;
1215 bexcludeMonitors = false;
1216 if (!bincludeMonitors) {
1217 bseparateMonitors = LoadRawHelper::isSeparateMonitors(monitorOption);
1218 bexcludeMonitors = LoadRawHelper::isExcludeMonitors(monitorOption);
1219 }
1220 //
1221}
1222
1223} // namespace Mantid::DataHandling
double value
The value of the point.
Definition: FitMW.cpp:51
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
isis raw file.
Definition: isisraw2.h:13
void skipData(FILE *file, int i)
Skip data.
Definition: isisraw2.cpp:133
int ioRAW(FILE *file, bool from_file, bool read_data=true) override
Loads the headers of the file, leaves the file pointer at a specific position.
Definition: isisraw2.cpp:43
bool readData(FILE *file, int i)
Read data.
Definition: isisraw2.cpp:146
isis raw file.
Definition: isisraw.h:272
HDR_STRUCT hdr
header block (80 bytes)
Definition: isisraw.h:282
int getTimeChannels(float *rtcb1, int n)
rtcb1 is of size t_ntc1+1
Definition: isisraw.cpp:989
char i_inst[8]
instrument name
Definition: isisraw.h:294
DAEP_STRUCT daep
DAE parameter block (size 64*4 bytes)
Definition: isisraw.h:316
int t_nper
number of periods
Definition: isisraw.h:327
int t_nsp1
number of spectra in time regime 1
Definition: isisraw.h:329
RPB_STRUCT rpb
run parameter block (32*4 bytes)
Definition: isisraw.h:291
int t_ntc1
number of time channels in time regime 1
Definition: isisraw.h:330
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
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
void setChildEndProgress(const double endProgress) const override
setting the child end progress
Definition: Algorithm.h:265
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
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
void setChildStartProgress(const double startProgress) const override
setting the child start progress
Definition: Algorithm.h:263
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
Definition: Algorithm.cpp:1687
Kernel::Logger & getLogger() const
Returns a reference to the logger.
Definition: Algorithm.cpp:1660
const Poco::AbstractObserver & progressObserver() const
Return a reference to the algorithm's object that is reporting progress.
Definition: Algorithm.cpp:1632
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
void addLogData(Kernel::Property *p)
Add a log entry.
Definition: LogManager.h:115
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
Definition: LogManager.h:79
This class stores information regarding an experimental run as a series of log entries.
Definition: Run.h:38
void setProtonCharge(const double charge)
Set the proton charge.
Definition: Run.cpp:165
A minimal class to hold the mapping between the spectrum number and its related detector ID numbers f...
Class to hold a set of workspaces.
A property class for workspaces.
Defines a class to aid in creating ISIS specific run logs for periods, status etc.
Definition: ISISRunLogs.h:28
int confidence(Kernel::FileDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
void ioRaw(FILE *file, bool from_file)
calls isisRaw ioraw
bool m_interval
Have the spectrum_min/max properties been set?
std::vector< std::shared_ptr< HistogramData::HistogramX > > getTimeChannels(const int64_t &regimes, const int64_t &lengthIn)
Constructs the time channel (X) vector(s)
void reset()
resets the isisraw shared pointer
void calculateWorkspacesizes(const std::vector< specnum_t > &monitorSpecList, specnum_t &normalwsSpecs, specnum_t &monitorwsSpecs)
calculate workspace sizes if separate or exclude monitors are selected
void readTitle(FILE *file, std::string &title)
Reads title from the isisraw class.
void skipData(FILE *file, int hist)
skips histrogram data from raw file.
static void setWorkspaceProperty(const std::string &propertyName, const std::string &title, const API::WorkspaceGroup_sptr &grpws_sptr, const DataObjects::Workspace2D_sptr &ws_sptr, int64_t numberOfPeriods, bool bMonitor, API::Algorithm *const pAlg)
sets the workspace property
static void ProcessLoadMonitorOptions(bool &bincludeMonitors, bool &bseparateMonitors, bool &bexcludeMonitors, API::Algorithm *const pAlgo)
The method to interpret LoadMonitors property options and convert then into boolean values.
specnum_t m_total_specs
the total nuumber of spectra
std::string extractLogName(const std::string &path)
Extract the log name from the path to the specific log file.
static DataObjects::Workspace2D_sptr createWorkspace(const DataObjects::Workspace2D_sptr &ws_sptr, int64_t nVectors=-1, int64_t xLengthIn=-1, int64_t yLengthIn=-1)
creates shared pointer to workspace from parent workspace
std::map< specnum_t, specnum_t > m_specTimeRegimes
A map for storing the time regime for each spectrum.
static Types::Core::DateAndTime extractEndTime(ISISRAW &isisRaw)
Extract the end time from a raw file.
static bool isSeparateMonitors(const std::string &monitorOption)
returns true if the Separate Monitor Option selected
static void createMonitorWorkspace(DataObjects::Workspace2D_sptr &monws_sptr, const DataObjects::Workspace2D_sptr &normalws_sptr, API::WorkspaceGroup_sptr &mongrp_sptr, const int64_t mwsSpecs, const int64_t nwsSpecs, const int64_t numberOfPeriods, const int64_t lengthIn, const std::string &title, API::Algorithm *const pAlg)
creates monitor workspace
ISISRAW2 & isisRaw() const
return an reference to the ISISRAW2 reader
void init() override
Overwrites Algorithm method.
specnum_t m_spec_max
The value of the spectrum_max property.
bool m_bmspeclist
boolean for list spectra options
double m_prog
The current value of the progress counter.
void exec() override
Overwrites Algorithm method.
std::vector< specnum_t > m_spec_list
The value of the spectrum_list property.
std::vector< std::string > m_cache_options
Allowed values for the cache property.
std::unique_ptr< ISISRAW2 > m_isis_raw
ISISRAW class instance which does raw file reading.
bool readData(FILE *file, int hist)
reads data
void createPeriodLogs(int64_t period, const DataObjects::Workspace2D_sptr &local_workspace)
Create the period specific logs.
int getNumberofTimeRegimes()
number of time regimes
std::unique_ptr< ISISRunLogs > m_logCreator
A ptr to the log creator.
void runLoadMappingTable(const std::string &fileName, const DataObjects::Workspace2D_sptr &)
loadinstrumentfromraw Child Algorithm
specnum_t m_spec_min
The value of the spectrum_min property.
void runLoadLog(const std::string &fileName, const DataObjects::Workspace2D_sptr &, double, double)
load log algorithm
static Types::Core::DateAndTime extractStartTime(ISISRAW &isisRaw)
Extract the start time from a raw file.
static bool isExcludeMonitors(const std::string &monitorOption)
returns true if the Exclude Monitor option(property) selected
void setRunNumber(API::Run &run)
Stores the run number in the sample's logs.
void loadRunParameters(const API::MatrixWorkspace_sptr &localWorkspace, ISISRAW *const =nullptr) const
Read in run parameters Public so that LoadRaw2 can use it.
void runLoadInstrument(const std::string &fileName, const DataObjects::Workspace2D_sptr &, double, double)
loadinstrument Child Algorithm
FILE * openRawFile(const std::string &fileName)
Opens Raw File.
void setOptionalProperties(const int &spec_min, const int &spec_max, const std::vector< int > &spec_list)
sets optional properties like spec_min,spec_max etc
void runLoadInstrumentFromRaw(const std::string &fileName, const DataObjects::Workspace2D_sptr &)
loadinstrumentfromraw algorithm
specnum_t m_numberOfSpectra
number of spectra
static std::list< std::string > searchForLogFiles(const Poco::Path &pathToRawFile)
Search for the log files in the workspace, and output their names as a list.
float getProtonCharge() const
get proton charge from raw file
static bool isIncludeMonitors(const std::string &monitorOption)
returns true if the Include Monitor Option selected
void readworkspaceParameters(specnum_t &numberOfSpectra, int &numberOfPeriods, int64_t &lengthIn, int64_t &noTimeRegimes)
reads workspace parameters like number of histograms,size of vectors etc
bool m_list
Has the spectrum_list property been set?
void loadSpectra(FILE *file, const int &period, const int &total_specs, const DataObjects::Workspace2D_sptr &ws_sptr, const std::vector< std::shared_ptr< HistogramData::HistogramX > > &)
load the spectra
void setProtonCharge(API::Run &run)
set proton charge
static API::WorkspaceGroup_sptr createGroupWorkspace()
creates shared pointer to group workspace
specnum_t calculateWorkspaceSize()
calculate workspace size
static std::string convertMonthLabelToIntStr(std::string month)
convert month label to int string
void setWorkspaceData(const DataObjects::Workspace2D_sptr &newWorkspace, const std::vector< std::shared_ptr< HistogramData::HistogramX > > &timeChannelsVec, int64_t wsIndex, specnum_t nspecNum, int64_t noTimeRegimes, int64_t lengthIn, int64_t binStart)
This method sets the raw file data to workspace vectors.
void checkOptionalProperties()
Validates the optional 'spectra to read' properties, if they have been set.
std::vector< specnum_t > getmonitorSpectrumList(const API::SpectrumDetectorMapping &mapping)
gets the monitor spectrum list from the workspace
std::vector< specnum_t > m_monitordetectorList
a vector holding the indexes of monitors
static const std::string runTitle(const ISISRAW &isisRaw)
Return the run title from the raw data structure.
Definition: RawFileInfo.cpp:32
static const std::string runHeader(const ISISRAW &isisRaw)
Return the run header from the raw data structure.
Definition: RawFileInfo.cpp:39
Records the filename and the description of failure.
Definition: Exception.h:98
Defines a wrapper around an open file.
bool isAscii() const
Returns true if the descriptor is looking at an ascii file.
static bool isEmpty(const std::string &filename)
Returns true if the file is empty.
std::istream & data()
Access the open file stream.
static void glob(const Poco::Path &pathPattern, std::set< std::string > &files, int options=0)
Creates a set of files that match the given pathPattern.
Definition: Glob.cpp:33
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
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
OptionalBool : Tri-state bool.
Definition: OptionalBool.h:25
The concrete, templated class for properties.
Base class for properties.
Definition: Property.h:94
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
bool exists(::NeXus::File &file, const std::string &name)
Based on the current group in the file, does the named sub-entry exist?
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
MANTID_KERNEL_DLL std::istream & extractToEOL(std::istream &is, std::string &str)
Extract a line from input stream, discarding any EOL characters encountered.
Definition: Strings.cpp:1137
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition: EmptyValues.h:25
int32_t specnum_t
Typedef for a spectrum Number.
Definition: IDTypes.h:16
Generate a tableworkspace to store the calibration results.
std::string to_string(const wide_integer< Bits, Signed > &n)
int n_tr_shift
en)
Definition: isisraw.h:219
char hd_date[12]
start date
Definition: isisraw.h:27
char hd_time[8]
start time
Definition: isisraw.h:28
char inst_abrv[3]
instrument abbreviated name
Definition: isisraw.h:23
char hd_dur[8]
run duration (uA.hour) constructor
Definition: isisraw.h:29
char hd_user[20]
user name
Definition: isisraw.h:25
@ Output
An output workspace.
Definition: Property.h:54
int r_dur_secs
actual run duration in seconds
Definition: isisraw.h:75
int r_freq
2**k where source frequency = 50 / 2**k
Definition: isisraw.h:69
int r_dur_freq
test interval for above (seconds)
Definition: isisraw.h:65
int r_dmp
dump interval
Definition: isisraw.h:66
int r_mon_sum2
monitor sum 2
Definition: isisraw.h:77
char r_endtime[8]
format HH-MM-SS
Definition: isisraw.h:80
int r_dmp_units
scaler for above
Definition: isisraw.h:67
char r_enddate[12]
format DD-MMM-YYYY
Definition: isisraw.h:79
int r_goodfrm
good frames
Definition: isisraw.h:72
int r_dur_wanted
requested run duration (units as for "duration" above)
Definition: isisraw.h:74
int r_rawfrm
raw frames
Definition: isisraw.h:73
float r_gd_prtn_chrg
good proton charge (uA.hour)
Definition: isisraw.h:70
int r_durunits
scaler for above (1=seconds)
Definition: isisraw.h:64
int r_mon_sum1
monitor sum 1
Definition: isisraw.h:76
int r_dmp_freq
test interval for above
Definition: isisraw.h:68
int r_mon_sum3
monitor sum 3
Definition: isisraw.h:78
int r_dur
actual run duration
Definition: isisraw.h:63
int r_prop
RB (proposal) number.
Definition: isisraw.h:81
float r_tot_prtn_chrg
total proton charge (uA.hour)
Definition: isisraw.h:71