Mantid
Loading...
Searching...
No Matches
ExperimentInfo.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 +
11#include "MantidAPI/Run.h"
12#include "MantidAPI/Sample.h"
14
27
28#include "MantidBeamline/ComponentInfo.h"
29#include "MantidBeamline/DetectorInfo.h"
30#include "MantidBeamline/SpectrumInfo.h"
31
41
42#include "MantidTypes/SpectrumDefinition.h"
43
44#include <boost/algorithm/string.hpp>
45#include <boost/lexical_cast.hpp>
46#include <boost/regex.hpp>
47
48#include <Poco/Path.h>
49
50#include <algorithm>
51#include <memory>
52#include <tuple>
53
54using namespace Mantid::Geometry;
55using namespace Mantid::Kernel;
56using namespace Mantid::Types::Core;
57
58namespace Mantid::API {
59namespace {
61Kernel::Logger g_log("ExperimentInfo");
62
63} // namespace
64
67ExperimentInfo::ExperimentInfo() : m_parmap(new ParameterMap()), sptr_instrument(new Instrument()) {
68 m_parmap->setInstrument(sptr_instrument.get());
69}
70
76ExperimentInfo::ExperimentInfo(const ExperimentInfo &source) { *this = source; }
77
86
87// Defined as default in source for forward declaration with std::unique_ptr.
89
95 m_sample = other->m_sample;
96 m_run = other->m_run;
97 this->setInstrument(other->getInstrument());
98 // We do not copy Beamline::SpectrumInfo (which contains detector grouping
99 // information) for now:
100 // - For MatrixWorkspace, grouping information is still stored in ISpectrum
101 // and should not be overridden (copy is done in ExperimentInfo ctor, but
102 // not here since we just copy the experiment data).
103 // - For cached groupings (for MDWorkspaces), grouping was not copied in the
104 // old implementation either.
105}
106
110
112const std::string ExperimentInfo::toString() const {
113 try {
115 } catch (std::exception &) {
116 // Catch any errors so that the string returned has as much information
117 // as possible
118 }
119
120 std::ostringstream out;
121
123 const auto instName = inst->getName();
124 out << "Instrument: ";
125 if (!instName.empty()) {
126 out << instName << " (" << inst->getValidFromDate().toFormattedString("%Y-%b-%d") << " to "
127 << inst->getValidToDate().toFormattedString("%Y-%b-%d") << ")";
128 const auto instFilename = inst->getFilename();
129 if (!instFilename.empty()) {
130 out << "Instrument from: " << instFilename;
131 out << "\n";
132 }
133 } else {
134 out << "None";
135 }
136 out << "\n";
137
138 // parameter files loaded
139 auto paramFileVector = this->constInstrumentParameters().getParameterFilenames();
140 for (auto const &itFilename : paramFileVector) {
141 out << "Parameters from: " << itFilename;
142 out << "\n";
143 }
144
145 std::string runStart = getAvailableWorkspaceStartDate();
146 std::string runEnd = getAvailableWorkspaceEndDate();
147 std::string msgNA = "not available";
148 if (runStart.empty())
149 runStart = msgNA;
150 if (runEnd.empty())
151 runEnd = msgNA;
152 out << "Run start: " << runStart << "\n";
153 out << "Run end: " << runEnd << "\n"; // note extra space for pseudo/approx-alignment
154
155 if (this->sample().hasOrientedLattice()) {
157 out << "Sample: a " << std::fixed << std::setprecision(1) << latt.a() << ", b " << latt.b() << ", c " << latt.c();
158 out << "; alpha " << std::fixed << std::setprecision(0) << latt.alpha() << ", beta " << latt.beta() << ", gamma "
159 << latt.gamma();
160 out << "\n";
161 }
162 return out.str();
163}
164
165// Helpers for setInstrument and getInstrument
166namespace {
167void checkDetectorInfoSize(const Instrument &instr, const Geometry::DetectorInfo &detInfo) {
168 const auto numDets = instr.getNumberDetectors();
169 if (numDets != detInfo.size())
170 throw std::runtime_error("ExperimentInfo: size mismatch between "
171 "DetectorInfo and number of detectors in "
172 "instrument: " +
173 std::to_string(detInfo.size()) + " vs " + std::to_string(numDets));
174}
175} // namespace
176
181 m_spectrumInfoWrapper = nullptr;
182
183 // Detector IDs that were previously dropped because they were not part of the
184 // instrument may now suddenly be valid, so we have to reinitialize the
185 // detector grouping. Also the index corresponding to specific IDs may have
186 // changed.
187 if (sptr_instrument != (instr->isParametrized() ? instr->baseInstrument() : instr)) {
189 }
190 if (instr->isParametrized()) {
191 sptr_instrument = instr->baseInstrument();
192 // We take a *copy* of the ParameterMap since we are modifying it by setting
193 // a pointer to our DetectorInfo, and in case it contains legacy parameters
194 // such as positions or rotations.
195 m_parmap = std::make_shared<ParameterMap>(*instr->getParameterMap());
196 } else {
197 sptr_instrument = instr;
198 m_parmap = std::make_shared<ParameterMap>();
199 }
200 m_parmap->setInstrument(sptr_instrument.get());
201}
202
213
221
229
237
238namespace {
240
244struct RTP {
245 RTP() : radius(0.0), haveRadius(false), theta(0.0), phi(0.0) {}
246 double radius;
247 bool haveRadius;
248 double theta;
249 double phi;
250};
251
252struct ParameterValue {
253 ParameterValue(const Geometry::XMLInstrumentParameter &paramInfo, const API::Run &run)
254 : info(paramInfo), runData(run) {}
255
256 operator double() {
257 if (info.m_logfileID.empty())
258 return boost::lexical_cast<double>(info.m_value);
259 else {
260 const TimeROI *roi = &runData.getTimeROI();
261 return info.createParamValue(runData.getTimeSeriesProperty<double>(info.m_logfileID), roi);
262 }
263 }
264 operator int() { return boost::lexical_cast<int>(info.m_value); }
265 operator bool() {
266 if (boost::iequals(info.m_value, "true"))
267 return true;
268 else if (boost::iequals(info.m_value, "yes"))
269 return true;
270 else
271 return false;
272 }
274 const Run &runData;
275};
277} // namespace
278
279namespace {
280bool isPositionParameter(const std::string &name) { return ParameterMap::pos() == name; }
281
282bool isRotationParameter(const std::string &name) { return ParameterMap::rot() == name; }
283
284bool isScaleParameter(const std::string &name) { return (name == "scalex" || name == "scaley"); }
285
286bool isRedundantPosOrRot(const std::string &name) {
287 // Check size first as a small optimization.
288 return (name.size() == 4) &&
289 (name == "posx" || name == "posy" || name == "posz" || name == "rotx" || name == "roty" || name == "rotz");
290}
291
292template <class T> T getParam(const std::string &paramType, const std::string &paramValue) {
293 const std::string name = "dummy";
294 auto param = ParameterFactory::create(paramType, name);
295 param->fromString(paramValue);
296 return param->value<T>();
297}
298
299void updatePosition(ComponentInfo &componentInfo, const IComponent *component, const V3D &newRelPos) {
300 const auto compIndex = componentInfo.indexOf(component->getComponentID());
301 V3D position = newRelPos;
302 if (componentInfo.hasParent(compIndex)) {
303 const auto parentIndex = componentInfo.parent(compIndex);
304 componentInfo.rotation(parentIndex).rotate(position);
305 position += componentInfo.position(parentIndex);
306 }
307 componentInfo.setPosition(compIndex, position);
308}
309
310void updateRotation(ComponentInfo &componentInfo, const IComponent *component, const Quat &newRelRot) {
311 const auto compIndex = componentInfo.indexOf(component->getComponentID());
312
313 auto rotation = newRelRot;
314 if (componentInfo.hasParent(compIndex)) {
315 const auto parentIndex = componentInfo.parent(compIndex);
316 rotation = componentInfo.rotation(parentIndex) * newRelRot;
317 }
318 componentInfo.setRotation(compIndex, rotation);
319}
320
321void adjustPositionsFromScaleFactor(ComponentInfo &componentInfo, const IComponent *component,
322 const std::string &paramName, double factor) {
323 double ScaleX = 1.0;
324 double ScaleY = 1.0;
325 if (paramName == "scalex")
326 ScaleX = factor;
327 else
328 ScaleY = factor;
329 applyRectangularDetectorScaleToComponentInfo(componentInfo, component->getComponentID(), ScaleX, ScaleY);
330}
331} // namespace
332
341
342 // Reference to the run
343 const auto &runData = run();
344
345 // Get pointer to parameter map that we may add parameters to and information
346 // about
347 // the parameters that my be specified in the instrument definition file (IDF)
349 Geometry::ParameterMap paramMapForPosAndRot;
350
351 // Get instrument and sample
352 auto &compInfo = mutableComponentInfo();
353 const auto parInstrument = getInstrument();
354 const auto instrument = parInstrument->baseInstrument();
355 const auto &paramInfoFromIDF = instrument->getLogfileCache();
356
357 std::map<const IComponent *, RTP> rtpParams;
358
359 // In this loop position and rotation parameters are inserted into the
360 // temporary map paramMapForPosAndRot. In the subsequent loop, after all
361 // parameters have been parsed, we update positions and rotations in
362 // DetectorInfo and the temporary map goes out of scope. The main reason for
363 // this is that ParameterMap will then take care of assembling parameters for
364 // individual position or rotation components into a vector or quaternion. In
365 // particular, we cannot directly change DetectorInfo since the order of
366 // rotation components is not guaranteed.
367 for (const auto &item : paramInfoFromIDF) {
368 const auto &paramInfo = item.second;
369 // Use the parameter's short name (e.g. "Alpha0"), not the cache key. The cache key may be
370 // function-qualified (e.g. "IkedaCarpenterPV:Alpha0") to keep two functions on the same
371 // component from clobbering each other, but downstream consumers always look up by short name.
372 const std::string &paramN = paramInfo->m_paramName;
373
374 try {
375 // Special case where user has specified r-position,t-position, and/or
376 // p-position.
377 // We need to know all three first to calculate a set of X,Y,Z
378 if (paramN.compare(1, 9, "-position") == 0) {
379 auto &rtpValues = rtpParams[paramInfo->m_component]; // If not found,
380 // constructs
381 // default
382 double value = ParameterValue(*paramInfo, runData);
383 if (paramN.compare(0, 1, "r") == 0) {
384 rtpValues.radius = value;
385 rtpValues.haveRadius = true;
386 } else if (paramN.compare(0, 1, "t") == 0)
387 rtpValues.theta = value;
388 else if (paramN.compare(0, 1, "p") == 0)
389 rtpValues.phi = value;
390 if (rtpValues.haveRadius) {
391 V3D pos;
392 pos.spherical(rtpValues.radius, rtpValues.theta, rtpValues.phi);
393 paramMapForPosAndRot.addV3D(paramInfo->m_component, ParameterMap::pos(), pos);
394 }
395 } else {
396 populateWithParameter(paramMap, paramMapForPosAndRot, paramN, *paramInfo, runData);
397 }
398 } catch (std::exception &exc) {
399 g_log.information() << "Unable to add component parameter '" << paramN << "'. Error: " << exc.what();
400 continue;
401 }
402 }
403 for (const auto &item : paramMapForPosAndRot) {
404 if (isPositionParameter(item.second->name())) {
405 const auto newRelPos = item.second->value<V3D>();
406 updatePosition(compInfo, item.first, newRelPos);
407 } else if (isRotationParameter(item.second->name())) {
408 const auto newRelRot = item.second->value<Quat>();
409 updateRotation(compInfo, item.first, newRelRot);
410 }
411 // Parameters for individual components (x,y,z) are ignored. ParameterMap
412 // did compute the correct compound positions and rotations internally.
413 }
414 // Special case RectangularDetector: Parameters scalex and scaley affect pixel
415 // positions.
416 for (const auto &item : paramMap) {
417 if (isScaleParameter(item.second->name()))
418 adjustPositionsFromScaleFactor(compInfo, item.first, item.second->name(), item.second->value<double>());
419 }
420 // paramMapForPosAndRot goes out of scope, dropping all position and rotation
421 // parameters of detectors (parameters for non-detector components have been
422 // inserted into paramMap via DetectorInfo::setPosition(IComponent *)).
423}
424
432 if (m_spectrumInfo)
435 m_spectrumInfo = std::make_unique<Beamline::SpectrumInfo>(count);
436 m_spectrumInfoWrapper = nullptr;
437}
438
444
449void ExperimentInfo::setDetectorGrouping(const size_t index, const std::set<detid_t> &detIDs) const {
450 SpectrumDefinition specDef;
451 for (const auto detID : detIDs) {
452 try {
453 const size_t detIndex = detectorInfo().indexOf(detID);
454 specDef.add(detIndex);
455 } catch (std::out_of_range &) {
456 // Silently strip bad detector IDs
457 }
458 }
459 m_spectrumInfo->setSpectrumDefinition(index, std::move(specDef));
461}
462
470void ExperimentInfo::updateCachedDetectorGrouping(const size_t /*unused*/) const {
471 throw std::runtime_error("ExperimentInfo::updateCachedDetectorGrouping: "
472 "Cannot update -- grouping information not "
473 "available");
474}
475
481 return *m_sample;
482}
483
493
497const Run &ExperimentInfo::run() const {
499 return *m_run;
500}
501
509 return m_run.access();
510}
511
514
517
530Kernel::Property *ExperimentInfo::getLog(const std::string &log) const {
532 try {
533 return run().getProperty(log);
535 // No log with that name
536 }
537 // If the instrument has a parameter with that name then take the value as a
538 // log name
539 const std::string logName = constInstrumentParameters().getString(sptr_instrument.get(), log);
540 if (logName.empty()) {
541 throw std::invalid_argument("ExperimentInfo::getLog - No instrument parameter named \"" + log +
542 "\". Cannot access full log name");
543 }
544 return run().getProperty(logName);
545}
546
555double ExperimentInfo::getLogAsSingleValue(const std::string &log) const {
557 try {
558 return run().getPropertyAsSingleValue(log);
560 // No log with that name
561 }
562 // If the instrument has a parameter with that name then take the value as a
563 // log name
564 const std::string logName = constInstrumentParameters().getString(sptr_instrument.get(), log);
565 if (logName.empty()) {
566 throw std::invalid_argument("ExperimentInfo::getLog - No instrument parameter named \"" + log +
567 "\". Cannot access full log name");
568 }
569 return run().getPropertyAsSingleValue(logName);
570}
571
578 const Run &thisRun = run();
579 if (!thisRun.hasProperty("run_number")) {
580 // No run_number property, default to 0
581 return 0;
582 } else {
583 Property const *prop = m_run->getProperty("run_number");
584 if (prop) {
585 // Use the string representation. That way both a string and a number
586 // property will work.
587 int val;
588 if (Strings::convert(prop->value(), val))
589 return val;
590 else
591 return 0;
592 }
593 }
594 return 0;
595}
596
607 static const char *emodeTag = "deltaE-mode";
608 std::string emodeStr;
609 if (run().hasProperty(emodeTag)) {
610 emodeStr = run().getPropertyValueAsType<std::string>(emodeTag);
611 } else if (sptr_instrument && constInstrumentParameters().contains(sptr_instrument.get(), emodeTag)) {
613 emodeStr = param->asString();
614 } else {
616 }
617 return Kernel::DeltaEMode::fromString(emodeStr);
618}
619
629double ExperimentInfo::getEFixed(const detid_t detID) const {
631 IDetector_const_sptr det = getInstrument()->getDetector(detID);
632 return getEFixed(det);
633}
634
641double ExperimentInfo::getEFixed(const std::shared_ptr<const Geometry::IDetector> &detector) const {
644 return getEFixedGivenEMode(detector, emode);
645}
646
647double ExperimentInfo::getEFixedForIndirect(const std::shared_ptr<const Geometry::IDetector> &detector,
648 const std::vector<std::string> &parameterNames) const {
649 double efixed = 0.;
650 for (auto &parameterName : parameterNames) {
651 Parameter_sptr par = constInstrumentParameters().getRecursive(detector.get(), parameterName);
652 if (par) {
653 efixed = par->value<double>();
654 } else {
655 std::vector<double> efixedVec = detector->getNumberParameter(parameterName);
656 if (efixedVec.empty()) {
657 int detid = detector->getID();
658 IDetector_const_sptr detectorSingle = getInstrument()->getDetector(detid);
659 efixedVec = detectorSingle->getNumberParameter(parameterName);
660 }
661 if (!efixedVec.empty()) {
662 efixed = efixedVec.at(0);
663 }
664 }
665 }
666 if (efixed == 0.) {
667 std::ostringstream os;
668 os << "ExperimentInfo::getEFixed - Indirect mode efixed requested but "
669 "detector has no Efixed parameter attached. ID="
670 << detector->getID();
671 throw std::runtime_error(os.str());
672 }
673 return efixed;
674}
675
683double ExperimentInfo::getEFixedGivenEMode(const std::shared_ptr<const Geometry::IDetector> &detector,
684 const Kernel::DeltaEMode::Type emode) const {
685 if (emode == Kernel::DeltaEMode::Direct) {
686 double efixed = 0.;
687 for (auto &parameterName : {"Ei", "EnergyRequested", "EnergyEstimate"}) {
688 if (run().hasProperty(parameterName)) {
689 efixed = run().getPropertyValueAsType<double>(parameterName);
690 break;
691 }
692 }
693 if (efixed == 0.) {
694 throw std::runtime_error("Experiment logs do not contain an Ei "
695 "value. Have you run GetEi?");
696 }
697 return efixed;
698 } else if (emode == Kernel::DeltaEMode::Indirect) {
699 if (!detector)
700 throw std::runtime_error("ExperimentInfo::getEFixed - Indirect mode "
701 "efixed requested without a valid detector.");
702 return getEFixedForIndirect(detector, {"Efixed", "EFixed-val"});
703 } else {
704 throw std::runtime_error("ExperimentInfo::getEFixed - EFixed requested for "
705 "elastic mode, don't know what to do!");
706 }
707}
708
709void ExperimentInfo::setEFixed(const detid_t detID, const double value) {
711 IDetector_const_sptr det = getInstrument()->getDetector(detID);
713 pmap.addDouble(det.get(), "Efixed", value);
714}
715
726 std::string date;
727 try {
728 date = run().startTime().toISO8601String();
729 } catch (std::runtime_error &) {
730 g_log.information("run_start/start_time not stored in workspace. Default "
731 "to current date.");
732 date = Types::Core::DateAndTime::getCurrentTime().toISO8601String();
733 }
734 return date;
735}
736
745 std::string date;
746 try {
747 date = run().startTime().toFormattedString();
748 } catch (std::runtime_error &) {
749 g_log.information("Note: run_start/start_time not stored in workspace.");
750 }
751 return date;
752}
753
762 std::string date;
763 try {
764 date = run().endTime().toFormattedString();
765 } catch (std::runtime_error &) {
766 g_log.information("Note: run_start/start_time not stored in workspace.");
767 }
768 return date;
769}
770
771//-----------------------------------------------------------------------------------------------------------------------
772
780 return m_parmap->detectorInfo();
781}
782
788
797 std::lock_guard<std::mutex> lock{m_spectrumInfoMutex};
798 if (!m_spectrumInfo) // this should happen only if not MatrixWorkspace
801 static_cast<void>(detectorInfo());
802 m_spectrumInfoWrapper = std::make_unique<SpectrumInfo>(*m_spectrumInfo, *this, m_parmap->mutableDetectorInfo());
803 }
804 }
805 // Rebuild any spectrum definitions that are out of date. Accessing
806 // `API::SpectrumInfo` will rebuild invalid spectrum definitions as it
807 // encounters them (if detector IDs in an `ISpectrum` are changed), however we
808 // need to deal with one special case here:
809 // If two algorithms (or two threads in the same algorithm) access the same
810 // workspace for reading at the same time, calls to
811 // `updateSpectrumDefinitionIfNecessary` done by `API::SpectrumInfo` break
812 // thread-safety. `Algorithm` sets a read-lock, but this lazy update method is
813 // `const` and will modify internals of the workspace nevertheless. We thus
814 // need explicit locking here. Note that we do not need extra locking in the
815 // case of `ExperimentInfo::mutableSpectrumInfo` or other calls to
816 // `updateSpectrumDefinitionIfNecessary` done by `API::SpectrumInfo`: If the
817 // workspace is only read-locked, this update will ensure that no updates will
818 // be triggered by SpectrumInfo, since changing detector IDs in an `ISpectrum`
819 // is not possible for a read-only workspace. If the workspace is write-locked
820 // detector IDs in ISpectrum may change, but the write-lock by `Algorithm`
821 // guarantees that there is no concurrent reader and thus updating is safe.
823 [](char i) { return i == 1; })) {
824 std::lock_guard<std::mutex> lock{m_spectrumInfoMutex};
826 [](char i) { return i == 1; })) {
827 auto size = static_cast<int64_t>(m_spectrumInfoWrapper->size());
828#pragma omp parallel for
829 for (int64_t i = 0; i < size; ++i) {
831 }
832 }
833 }
834 return *m_spectrumInfoWrapper;
835}
836
840 return const_cast<SpectrumInfo &>(static_cast<const ExperimentInfo &>(*this).spectrumInfo());
841}
842
843const Geometry::ComponentInfo &ExperimentInfo::componentInfo() const { return m_parmap->componentInfo(); }
844
845ComponentInfo &ExperimentInfo::mutableComponentInfo() { return m_parmap->mutableComponentInfo(); }
846
848void ExperimentInfo::setSpectrumDefinitions(Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions) {
849 if (spectrumDefinitions) {
850 m_spectrumInfo = std::make_unique<Beamline::SpectrumInfo>(std::move(spectrumDefinitions));
853 } else {
854 // Keep the old m_spectrumInfo which should have the correct size, but
855 // invalidate all definitions.
857 }
858 m_spectrumInfoWrapper = nullptr;
859}
860
867 // This uses a vector of char, such that flags for different indices can be
868 // set from different threads (std::vector<bool> is not thread-safe).
870}
871
876
883 if (m_spectrumInfo && (m_spectrumInfo->size() != 0))
884 return;
885 const auto &detIDs = sptr_instrument->getDetectorIDs();
886 setNumberOfDetectorGroups(detIDs.size());
887 size_t specIndex = 0;
888 for (const auto detID : detIDs) {
889 m_det2group[detID] = specIndex;
890 const size_t detIndex = detectorInfo().indexOf(detID);
891 SpectrumDefinition specDef;
892 specDef.add(detIndex);
893 // cppcheck-suppress nullPointerRedundantCheck
894 m_spectrumInfo->setSpectrumDefinition(specIndex, std::move(specDef));
895 m_spectrumDefinitionNeedsUpdate.at(specIndex) = 0;
896 specIndex++;
897 }
898}
899
905
910void ExperimentInfo::saveExperimentInfoNexus(Nexus::File *file, bool saveLegacyInstrument) const {
912 if (saveLegacyInstrument) {
913 instrument->saveNexus(file, "instrument");
914 }
915 sample().saveNexus(file, "sample");
916 run().saveNexus(file, "logs");
917}
918
925void ExperimentInfo::saveExperimentInfoNexus(Nexus::File *file, bool saveInstrument, bool saveSample,
926 bool saveLogs) const {
928
929 if (saveInstrument)
930 instrument->saveNexus(file, "instrument");
931 if (saveSample)
932 sample().saveNexus(file, "sample");
933 if (saveLogs)
934 run().saveNexus(file, "logs");
935}
936
941void ExperimentInfo::loadSampleAndLogInfoNexus(Nexus::File *file, std::string const &prefix) {
942 // First, the sample and then the logs
943 int sampleVersion = mutableSample().loadNexus(file, "sample");
944 if (sampleVersion == 0) {
945 // Old-style (before Sep-9-2011) NXS processed
946 // sample field contains both the logs and the sample details
947 file->openGroup("sample", "NXsample");
948 this->mutableRun().loadNexus(file, "", prefix);
949 file->closeGroup();
950 } else {
951 // Newer style: separate "logs" field for the Run object
952 this->mutableRun().loadNexus(file, "logs", prefix);
953 }
954}
955
960 // First, the sample and then the logs
961 int sampleVersion = mutableSample().loadNexus(file, "sample");
962 if (sampleVersion == 0) {
963 // Old-style (before Sep-9-2011) NXS processed
964 // sample field contains both the logs and the sample details
965 file->openGroup("sample", "NXsample");
966 this->mutableRun().loadNexus(file, "");
967 file->closeGroup();
968 } else {
969 // Newer style: separate "logs" field for the Run object
970 this->mutableRun().loadNexus(file, "logs");
971 }
972}
973
974void ExperimentInfo::loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file,
975 std::string &parameterStr, const std::string &prefix) {
976 // TODO load sample and log info
977 loadSampleAndLogInfoNexus(file, prefix);
978 loadInstrumentInfoNexus(nxFilename, file, parameterStr);
979}
980
991void ExperimentInfo::loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file,
992 std::string &parameterStr) {
993 // load sample and log info
995
996 loadInstrumentInfoNexus(nxFilename, file, parameterStr);
997}
998
1009void ExperimentInfo::loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file,
1010 std::string &parameterStr) {
1011
1012 // Open instrument group
1013 file->openGroup("instrument", "NXinstrument");
1014
1015 // Try to get the instrument embedded in the Nexus file
1016 std::string instrumentName;
1017 std::string instrumentXml;
1018 loadEmbeddedInstrumentInfoNexus(file, instrumentName, instrumentXml);
1019
1020 // load parameters if found
1021 loadInstrumentParametersNexus(file, parameterStr);
1022
1023 // Close the instrument group
1024 file->closeGroup();
1025
1026 // Set the instrument given the name and and XML obtained
1027 setInstumentFromXML(nxFilename, instrumentName, instrumentXml);
1028}
1029
1039void ExperimentInfo::loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file) {
1040
1041 // Open instrument group
1042 file->openGroup("instrument", "NXinstrument");
1043
1044 // Try to get the instrument embedded in the Nexus file
1045 std::string instrumentName;
1046 std::string instrumentXml;
1047 loadEmbeddedInstrumentInfoNexus(file, instrumentName, instrumentXml);
1048
1049 // Close the instrument group
1050 file->closeGroup();
1051
1052 // Set the instrument given the name and and XML obtained
1053 setInstumentFromXML(nxFilename, instrumentName, instrumentXml);
1054}
1055
1062void ExperimentInfo::loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName,
1063 std::string &instrumentXml) {
1064
1065 file->readData("name", instrumentName);
1066
1067 try {
1068 file->openGroup("instrument_xml", "NXnote");
1069 file->readData("data", instrumentXml);
1070 file->closeGroup();
1071 } catch (Nexus::Exception const &ex) {
1072 g_log.debug(std::string("Unable to load instrument_xml: ") + ex.what());
1073 }
1074}
1075
1085void ExperimentInfo::setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName,
1086 std::string &instrumentXml) {
1087
1088 instrumentXml = Strings::strip(instrumentXml);
1089 instrumentName = Strings::strip(instrumentName);
1090 std::string instrumentFilename;
1091 if (!instrumentXml.empty()) {
1092 // instrument xml is being loaded from the nxs file, set the
1093 // instrumentFilename
1094 // to identify the Nexus file as the source of the data
1095 instrumentFilename = nxFilename;
1096 g_log.debug() << "Using instrument IDF XML text contained in nexus file.\n";
1097 } else {
1098 // XML was not included or was empty
1099 // Use the instrument name to find the file
1100 instrumentFilename = InstrumentFileFinder::getInstrumentFilename(instrumentName, getWorkspaceStartDate());
1101 // And now load the contents
1102 instrumentXml = loadInstrumentXML(instrumentFilename);
1103 }
1104
1105 // ---------- Now parse that XML to make the instrument -------------------
1106 if (!instrumentXml.empty() && !instrumentName.empty()) {
1107 InstrumentDefinitionParser parser(instrumentFilename, instrumentName, instrumentXml);
1108
1109 std::string instrumentNameMangled = parser.getMangledName();
1110 Instrument_sptr instr;
1111 // Check whether the instrument is already in the InstrumentDataService
1112 if (InstrumentDataService::Instance().doesExist(instrumentNameMangled)) {
1113 // If it does, just use the one from the one stored there
1114 instr = InstrumentDataService::Instance().retrieve(instrumentNameMangled);
1115 } else {
1116 // Really create the instrument
1117 instr = parser.parseXML(nullptr);
1118 // Parse the instrument tree (internally create ComponentInfo and
1119 // DetectorInfo). This is an optimization that avoids duplicate parsing
1120 // of the instrument tree when loading multiple workspaces with the same
1121 // instrument. As a consequence less time is spent and less memory is
1122 // used. Note that this is only possible since the tree in `instrument`
1123 // will not be modified once we add it to the IDS.
1124 instr->parseTreeAndCacheBeamline();
1125
1126 // Add to data service for later retrieval
1127 InstrumentDataService::Instance().add(instrumentNameMangled, instr);
1128 }
1129 // Now set the instrument
1130 this->setInstrument(instr);
1131 }
1132}
1133
1140std::string ExperimentInfo::loadInstrumentXML(const std::string &filename) {
1141 try {
1142 return Strings::loadFile(filename);
1143 } catch (std::exception &e) {
1144 g_log.error() << "Error loading instrument IDF file: " << filename << ".\n";
1145 g_log.debug() << e.what() << '\n';
1146 throw;
1147 }
1148}
1149
1156void ExperimentInfo::loadInstrumentParametersNexus(Nexus::File *file, std::string &parameterStr) {
1157 try {
1158 file->openGroup("instrument_parameter_map", "NXnote");
1159 file->readData("data", parameterStr);
1160 file->closeGroup();
1161 } catch (Nexus::Exception const &ex) {
1162 g_log.debug(std::string("Unable to load instrument_parameter_map: ") + ex.what());
1163 g_log.information("Parameter map entry missing from NeXus file. Continuing without it.");
1164 }
1165}
1166
1173void ExperimentInfo::readParameterMap(const std::string &parameterStr) {
1175 auto &compInfo = mutableComponentInfo();
1176 auto &detInfo = mutableDetectorInfo();
1177 const auto parInstrument = getInstrument();
1178 const auto instr = parInstrument->baseInstrument();
1179
1182 Mantid::Kernel::StringTokenizer splitter(parameterStr, "|", options);
1183
1184 auto iend = splitter.end();
1185
1187 const std::string visibilityKey = "visible:"; // if visibility is defined, the value will follow this key
1188 // std::string prev_name;
1189 for (auto itr = splitter.begin(); itr != iend; ++itr) {
1190 tokens = Mantid::Kernel::StringTokenizer(*itr, ";");
1191 if (tokens.count() < 4)
1192 continue;
1193 std::string comp_name = tokens[0];
1194 // if( comp_name == prev_name ) continue; this blocks reading in different
1195 // parameters of the same component. RNT
1196 // prev_name = comp_name;
1197 const Geometry::IComponent *comp = nullptr;
1198 if (comp_name.find("detID:") != std::string::npos) {
1199 int detID = std::stoi(comp_name.substr(6));
1200 comp = instr->getDetector(detID).get();
1201 if (!comp) {
1202 g_log.warning() << "Cannot find detector " << detID << '\n';
1203 continue;
1204 }
1205 } else {
1206 comp = instr->getComponentByName(comp_name).get();
1207 if (!comp) {
1208 g_log.warning() << "Cannot find component " << comp_name << '\n';
1209 continue;
1210 }
1211 }
1212
1213 // create parameter's value as a sum of all tokens with index 3 or larger
1214 // this allow a parameter's value to contain ";"
1215 std::string paramValue = tokens[3];
1216 auto size = static_cast<int>(tokens.count());
1217 for (int i = 4; i < size; i++)
1218 paramValue += ";" + tokens[i];
1219 const auto &paramType = tokens[1];
1220 const auto &paramName = tokens[2];
1221 auto &paramVisibility = tokens[size - 1]; // parameter visibility, if defined, is the last token
1222 if (paramVisibility.find(visibilityKey) > paramVisibility.size())
1223 paramVisibility = "true"; // visibility not defined: default to visible
1224 else { // defined, the paramValue has one too many entries, -1 to remove also the semicolon
1225 paramVisibility =
1226 paramVisibility.substr(paramVisibility.find(visibilityKey) + visibilityKey.size(), paramVisibility.size());
1227 paramValue.erase(paramValue.find(visibilityKey) - 1, paramValue.size());
1228 }
1229 const auto paramDescr = std::string("");
1230 if (paramName == "masked") {
1231 auto value = getParam<bool>(paramType, paramValue);
1232 if (value) {
1233 // Do not add masking to ParameterMap, it is stored in DetectorInfo
1234 const auto componentIndex = compInfo.indexOf(comp->getComponentID());
1235 if (!compInfo.isDetector(componentIndex)) {
1236 throw std::runtime_error("Found masking for a non-detector "
1237 "component. This is not possible");
1238 } else
1239 detInfo.setMasked(componentIndex, value); // all detector indexes
1240 // have same component
1241 // index (guarantee)
1242 }
1243 } else if (isPositionParameter(paramName)) {
1244 // We are parsing a string obtained from a ParameterMap. The map may
1245 // contain posx, posy, and posz (in addition to pos). However, when these
1246 // component wise positions are set, 'pos' is updated accordingly. We are
1247 // thus ignoring position components below.
1248 const auto newRelPos = getParam<V3D>(paramType, paramValue);
1249 updatePosition(compInfo, comp, newRelPos);
1250 } else if (isRotationParameter(paramName)) {
1251 // We are parsing a string obtained from a ParameterMap. The map may
1252 // contain rotx, roty, and rotz (in addition to rot). However, when these
1253 // component wise rotations are set, 'rot' is updated accordingly. We are
1254 // thus ignoring rotation components below.
1255 const auto newRelRot = getParam<Quat>(paramType, paramValue);
1256 updateRotation(compInfo, comp, newRelRot);
1257 } else if (!isRedundantPosOrRot(paramName)) {
1258 // Special case RectangularDetector: Parameters scalex and scaley affect
1259 // pixel positions, but we must also add the parameter below.
1260 if (isScaleParameter(paramName))
1261 adjustPositionsFromScaleFactor(compInfo, comp, paramName, getParam<double>(paramType, paramValue));
1262 // For fitting parameters, route through addFittingParameter so that two functions on the same
1263 // component sharing a parameter short name (e.g. IkedaCarpenterPV:Gamma and
1264 // Bk2BkExpConvPV:Gamma) both survive a NeXus save/load round-trip. ParameterMap::add only
1265 // dedupes by (component, name) and would silently overwrite the first entry with the second.
1266 // The fitting-function name is embedded as the second comma-separated field of the value
1267 // string written by populateWithParameter().
1268
1269 // string from populateWithParameter() is expected to be " , " (space-comma-space) separated:
1270 // "m_value , m_fittingFunction , name , constraint[0] , constraint[1] , penaltyFactor , tie ,
1271 // formula , formulaUnit , resultUnit , interpolation"
1272 if (paramType == "fitting") {
1273 std::string fittingFunction;
1274 // Locate the second field by finding the first two commas; the fitting function is the
1275 // text between them. If there are fewer than two commas the value is malformed and
1276 // fittingFunction stays empty, falling back to the plain add() below.
1277 const auto firstComma = paramValue.find(',');
1278 if (firstComma != std::string::npos) {
1279 const auto secondComma = paramValue.find(',', firstComma + 1);
1280 if (secondComma != std::string::npos) {
1281 // Take the raw second field, e.g. " IkedaCarpenterPV " from "3.5 , IkedaCarpenterPV , ...".
1282 fittingFunction = paramValue.substr(firstComma + 1, secondComma - firstComma - 1);
1283 // Trim the surrounding spaces/tabs introduced by the " , " separator.
1284 const auto firstNonSpace = fittingFunction.find_first_not_of(" \t");
1285 if (firstNonSpace != std::string::npos) {
1286 const auto lastNonSpace = fittingFunction.find_last_not_of(" \t");
1287 fittingFunction = fittingFunction.substr(firstNonSpace, lastNonSpace - firstNonSpace + 1);
1288 } else
1289 // Field was entirely whitespace (e.g. "3.5 , , ..."): treat as no fitting function.
1290 fittingFunction.clear();
1291 }
1292 }
1293 if (!fittingFunction.empty()) {
1294 pmap.addFittingParameter(comp, paramName, fittingFunction, paramValue, &paramDescr, paramVisibility);
1295 } else {
1296 pmap.add(paramType, comp, paramName, paramValue, &paramDescr, paramVisibility);
1297 }
1298 } else {
1299 pmap.add(paramType, comp, paramName, paramValue, &paramDescr, paramVisibility);
1300 }
1301 }
1302 }
1303}
1304
1316 Geometry::ParameterMap &paramMapForPosAndRot, const std::string &name,
1317 const Geometry::XMLInstrumentParameter &paramInfo, const Run &runData) {
1318 const std::string &category = paramInfo.m_type;
1319 ParameterValue paramValue(paramInfo,
1320 runData); // Defines implicit conversion operator
1321
1322 const std::string *pDescription = nullptr;
1323 if (!paramInfo.m_description.empty())
1324 pDescription = &paramInfo.m_description;
1325 std::string pVisible = "true";
1326 if (!paramInfo.m_visible.empty())
1327 pVisible = paramInfo.m_visible;
1328
1329 // Some names are special. Values should be convertible to double
1330 if (name == "masked") {
1331 bool value(paramValue);
1332 if (value) {
1333 // Do not add masking to ParameterMap, it is stored in DetectorInfo
1334
1335 const auto componentIndex = componentInfo().indexOf(paramInfo.m_component->getComponentID());
1336 if (!componentInfo().isDetector(componentIndex))
1337 throw std::runtime_error("Found masking for a non-detector component. This is not possible");
1338 mutableDetectorInfo().setMasked(componentIndex,
1339 paramValue); // all detector indexes have
1340 // same component index
1341 // (guarantee)
1342 }
1343 } else if (name == "x" || name == "y" || name == "z") {
1344 paramMapForPosAndRot.addPositionCoordinate(paramInfo.m_component, name, paramValue);
1345 } else if (name == "rot" || name == "rotx" || name == "roty" || name == "rotz") {
1346 // Effectively this is dropping any parameters named 'rot'.
1347 paramMapForPosAndRot.addRotationParam(paramInfo.m_component, name, paramValue, pDescription);
1348 } else if (category == "fitting") {
1349 std::ostringstream str;
1350 // read parameter map relies on extracting m_fittingFunction from this string - edit with care
1351 str << paramInfo.m_value << " , " << paramInfo.m_fittingFunction << " , " << name << " , "
1352 << paramInfo.m_constraint[0] << " , " << paramInfo.m_constraint[1] << " , " << paramInfo.m_penaltyFactor
1353 << " , " << paramInfo.m_tie << " , " << paramInfo.m_formula << " , " << paramInfo.m_formulaUnit << " , "
1354 << paramInfo.m_resultUnit << " , " << (*(paramInfo.m_interpolation));
1355 // Dedupe by (name, fitting function) — otherwise two functions on the same component sharing
1356 // a parameter short name (e.g. Bk2BkExpConvPV:Gamma and IkedaCarpenterPV:Gamma) would clobber
1357 // each other in the map.
1358 paramMap.addFittingParameter(paramInfo.m_component, name, paramInfo.m_fittingFunction, str.str(), pDescription,
1359 pVisible);
1360 } else if (category == "string") {
1361 paramMap.addString(paramInfo.m_component, name, paramInfo.m_value, pDescription, pVisible);
1362 } else if (category == "bool") {
1363 paramMap.addBool(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1364 } else if (category == "int") {
1365 paramMap.addInt(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1366 } else { // assume double
1367 paramMap.addDouble(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1368 }
1369}
1370
1372 // The default implementation does nothing. Used by subclasses
1373 // (FileBackedExperimentInfo) to load content from files upon access.
1374}
1375
1376} // namespace Mantid::API
1377
1378namespace Mantid::Kernel {
1379
1380template <>
1382IPropertyManager::getValue<Mantid::API::ExperimentInfo_sptr>(const std::string &name) const {
1383 auto *prop = dynamic_cast<PropertyWithValue<Mantid::API::ExperimentInfo_sptr> *>(getPointerToProperty(name));
1384 if (prop) {
1385 return *prop;
1386 } else {
1387 std::string message =
1388 "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<ExperimentInfo>.";
1389 throw std::runtime_error(message);
1390 }
1391}
1392
1393template <>
1395IPropertyManager::getValue<Mantid::API::ExperimentInfo_const_sptr>(const std::string &name) const {
1396 auto const *prop = dynamic_cast<PropertyWithValue<Mantid::API::ExperimentInfo_sptr> *>(getPointerToProperty(name));
1397 if (prop) {
1398 return prop->operator()();
1399 } else {
1400 std::string message =
1401 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<ExperimentInfo>.";
1402 throw std::runtime_error(message);
1403 }
1404}
1405
1406} // namespace Mantid::Kernel
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
double position
Definition GetAllEi.cpp:154
std::map< DeltaEMode::Type, std::string > index
int count
counter
Definition Matrix.cpp:37
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
This class is shared by a few Workspace types and holds information related to a particular experimen...
void loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName, std::string &instrumentXml)
Attempt to load instrument embedded in Nexus file. *file must have instrument group open.
Geometry::DetectorInfo & mutableDetectorInfo()
Return a non-const reference to the DetectorInfo object.
Run & mutableRun()
Writable version of the run object.
Kernel::cow_ptr< Sample > m_sample
The information on the sample environment.
const SpectrumInfo & spectrumInfo() const
Return a reference to the SpectrumInfo object.
std::shared_ptr< Geometry::ParameterMap > m_parmap
Parameters modifying the base instrument.
ExperimentInfo()
Default constructor.
void setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName, std::string &instrumentXml)
Set the instrument given the name and XML leading from IDF file if XML string is empty.
Geometry::ComponentInfo & mutableComponentInfo()
const Geometry::DetectorInfo & detectorInfo() const
Return a const reference to the DetectorInfo object.
virtual ExperimentInfo * cloneExperimentInfo() const
Clone us.
std::unordered_map< detid_t, size_t > m_det2group
Detector grouping information.
double getEFixed(const detid_t detID) const
Easy access to the efixed value for this run & detector ID.
void readParameterMap(const std::string &parameterStr)
Populate the parameter map given a string.
virtual void populateIfNotLoaded() const
Called as the first operation of most public methods.
void invalidateSpectrumDefinition(const size_t index)
Notifies the ExperimentInfo that a spectrum definition has changed.
void saveExperimentInfoNexus(Nexus::File *file, bool saveLegacyInstrument=true) const
Saves this experiment description to the open NeXus file.
size_t numberOfDetectorGroups() const
Returns the number of detector groups.
void updateSpectrumDefinitionIfNecessary(const size_t index) const
std::string getAvailableWorkspaceStartDate() const
Return workspace start date as a formatted string (strftime, as returned by Types::Core::DateAndTime)...
std::string loadInstrumentXML(const std::string &filename)
Loads the contents of a file and returns the string The file is assumed to be an IDF,...
virtual ~ExperimentInfo()
Virtual destructor.
virtual void updateCachedDetectorGrouping(const size_t index) const
Update detector grouping for spectrum with given index.
void cacheDefaultDetectorGrouping() const
Sets up a default detector grouping.
void copyExperimentInfoFrom(const ExperimentInfo *other)
Copy everything from the given experiment object.
const Run & run() const
Run details object access.
void loadSampleAndLogInfoNexus(Nexus::File *file, std::string const &prefix)
Load the sample and log info from an open NeXus file.
const Geometry::ParameterMap & constInstrumentParameters() const
Const version.
Geometry::Instrument_const_sptr getInstrument() const
Returns the parameterized instrument.
Kernel::DeltaEMode::Type getEMode() const
Returns the emode for this run.
std::unique_ptr< Beamline::SpectrumInfo > m_spectrumInfo
void loadExperimentInfoNexus(std::string const &nxFilename, Nexus::File *file, std::string &parameterStr, std::string const &prefix)
const Sample & sample() const
Sample accessors.
void setEFixed(const detid_t detID, const double value)
Set the efixed value for a given detector ID.
double getEFixedGivenEMode(const std::shared_ptr< const Geometry::IDetector > &detector, const Kernel::DeltaEMode::Type emode) const
Easy access to the efixed value for this run & detector.
double getEFixedForIndirect(const std::shared_ptr< const Geometry::IDetector > &detector, const std::vector< std::string > &parameterNames) const
const std::string toString() const
Returns a string description of the object.
const Geometry::ParameterMap & instrumentParameters() const
Returns the set of parameters modifying the base instrument (const-version)
int getRunNumber() const
Utility method to get the run number.
std::string getAvailableWorkspaceEndDate() const
Return workspace end date as a formatted string (strftime style, as returned by Kernel::DateAdnTime) ...
const Geometry::ComponentInfo & componentInfo() const
std::string getWorkspaceStartDate() const
Returns the start date for this experiment (or current time if no info available)
void setInstrument(const Geometry::Instrument_const_sptr &instr)
Instrument accessors.
std::unique_ptr< SpectrumInfo > m_spectrumInfoWrapper
void setSharedRun(Kernel::cow_ptr< Run > run)
Set the run object. Use in particular to clear run without copying old run.
void setDetectorGrouping(const size_t index, const std::set< detid_t > &detIDs) const
Sets the detector grouping for the spectrum with the given index.
Kernel::cow_ptr< Run > sharedRun()
Return the cow ptr of the run.
ExperimentInfo & operator=(const ExperimentInfo &)
Implements the copy assignment operator.
void setSpectrumDefinitions(Kernel::cow_ptr< std::vector< SpectrumDefinition > > spectrumDefinitions)
Sets the SpectrumDefinition for all spectra.
void populateWithParameter(Geometry::ParameterMap &paramMap, Geometry::ParameterMap &paramMapForPosAndRot, const std::string &name, const Geometry::XMLInstrumentParameter &paramInfo, const Run &runData)
Fill with given instrument parameter.
std::vector< char > m_spectrumDefinitionNeedsUpdate
double getLogAsSingleValue(const std::string &log) const
Access a single value from a log for this experiment.
SpectrumInfo & mutableSpectrumInfo()
Return a non-const reference to the SpectrumInfo object.
void loadInstrumentParametersNexus(Nexus::File *file, std::string &parameterStr)
Load instrument parameters from an open Nexus file in Instrument group if found there.
void setNumberOfDetectorGroups(const size_t count) const
Sets the number of detector groups.
Sample & mutableSample()
Writable version of the sample object.
Geometry::Instrument_const_sptr sptr_instrument
The base (unparametrized) instrument.
void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr)
Load the instrument from an open NeXus file.
void populateInstrumentParameters()
Add parameters to the instrument parameter map that are defined in instrument definition file or para...
Kernel::Property * getLog(const std::string &log) const
Access a log for this experiment.
void invalidateAllSpectrumDefinitions()
Sets flags for all spectrum definitions indicating that they need to be updated.
Kernel::cow_ptr< Run > m_run
The run information.
static std::string getInstrumentFilename(const std::string &instrumentName, const std::string &date="")
Get the IDF using the instrument name and date.
const Types::Core::DateAndTime endTime() const
Return the run end time.
bool hasProperty(const std::string &name) const
Does the property exist on the object.
const Types::Core::DateAndTime startTime() const
Return the run start time.
Kernel::Property * getProperty(const std::string &name) const
Returns the named property as a pointer.
double getPropertyAsSingleValue(const std::string &name, Kernel::Math::StatisticType statistic=Kernel::Math::Mean) const
Returns a property as a single double value from its name.
HeldType getPropertyValueAsType(const std::string &name) const
Get the value of a property as the given TYPE.
This class stores information regarding an experimental run as a series of log entries.
Definition Run.h:35
void saveNexus(Nexus::File *file, const std::string &group, bool keepOpen=false) const override
Save the run to a NeXus file with a given group name.
Definition Run.cpp:647
void loadNexus(Nexus::File *file, const std::string &group, const std::string &prefix, bool keepOpen=false) override
Load the run from a NeXus file with a given group name.
Definition Run.cpp:699
This class stores information about the sample used in particular run.
Definition Sample.h:33
int loadNexus(Nexus::File *file, const std::string &group)
Load the object from an open NeXus file.
Definition Sample.cpp:331
void saveNexus(Nexus::File *file, const std::string &group) const
Save the object to an open NeXus file.
Definition Sample.cpp:286
const Geometry::OrientedLattice & getOrientedLattice() const
Get a reference to the sample's OrientedLattice.
Definition Sample.cpp:154
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
const Kernel::cow_ptr< std::vector< SpectrumDefinition > > & sharedSpectrumDefinitions() const
std::shared_ptr< const IComponent > getComponentByName(const std::string &cname, int nlevels=0) const override
Returns a pointer to the first component of assembly encountered with the given name.
ComponentInfo : Provides a component centric view on to the instrument.
bool hasParent(const size_t componentIndex) const
void setRotation(size_t componentIndex, const Kernel::Quat &newRotation)
size_t parent(const size_t componentIndex) const
Kernel::Quat rotation(const size_t componentIndex) const
Kernel::V3D position(const size_t componentIndex) const
size_t indexOf(Geometry::IComponent const *id) const
void setPosition(size_t componentIndex, const Kernel::V3D &newPosition)
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
void setMasked(const size_t index, bool masked)
Set the mask flag of the detector with given index. Not thread safe.
size_t indexOf(const detid_t id) const
Returns the index of the detector with the given detector ID.
size_t size() const
Returns the size of the DetectorInfo, i.e., the number of detectors in the instrument.
base class for Geometric IComponent
Definition IComponent.h:53
virtual ComponentID getComponentID() const =0
Returns the ComponentID - a unique identifier of the component.
Creates an instrument data from a XML instrument description file.
std::shared_ptr< Instrument > parseXML(Kernel::ProgressBase *progressReporter)
Parse XML contents.
std::string getMangledName()
Handle used in the singleton constructor for instrument file should append the value file sha-1 check...
Base Instrument Class.
Definition Instrument.h:49
std::size_t getNumberDetectors(bool skipMonitors=false) const
std::shared_ptr< const Instrument > baseInstrument() const
Pointer to the 'real' instrument, for parametrized instruments.
IDetector_const_sptr getDetector(const detid_t &detector_id) const
Gets a pointer to the detector from its ID Note that for getting the detector associated with a spect...
Class to implement UB matrix.
static std::shared_ptr< Instrument > createInstrument(const std::shared_ptr< const Instrument > &base, const std::shared_ptr< ParameterMap > &map)
Create a parameterized instrument from the given base and ParameterMap.
static std::shared_ptr< Parameter > create(const std::string &className, const std::string &name, const std::string &visible="true")
Creates an instance of a parameter.
Definition Parameter.cpp:83
const std::vector< std::string > & getParameterFilenames() const
Returns a list of all the parameter files loaded.
bool contains(const IComponent *comp, const std::string &name, const std::string &type="") const
Does the named parameter exist for the given component and type (std::string version)
void addInt(const IComponent *comp, const std::string &name, const std::string &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Adds an int value to the parameter map.
void addPositionCoordinate(const IComponent *comp, const std::string &name, const double value, const std::string *const pDescription=nullptr)
Create or adjust "pos" parameter for a component.
std::shared_ptr< Parameter > getRecursive(const IComponent *comp, const std::string &name, const std::string &type="") const
Use get() recursively to see if can find param in all parents of comp and given type (std::string ver...
static const std::string & rot()
std::string getString(const IComponent *comp, const std::string &name, bool recursive=false) const
Return the value of a parameter as a string.
void addString(const IComponent *comp, const std::string &name, const std::string &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Adds a std::string value to the parameter map.
void addDouble(const IComponent *comp, const std::string &name, const std::string &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Adds a double value to the parameter map.
static const std::string & pos()
Return string to be used in the map.
void addRotationParam(const IComponent *comp, const std::string &name, const double deg, const std::string *const pDescription=nullptr)
Create or adjust "rot" parameter for a component.
void addFittingParameter(const IComponent *comp, const std::string &name, const std::string &fittingFunction, const std::string &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Add a fitting parameter.
void addV3D(const IComponent *comp, const std::string &name, const std::string &value, const std::string *const pDescription=nullptr)
Adds a Kernel::V3D value to the parameter map.
void addBool(const IComponent *comp, const std::string &name, const std::string &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Adds a bool value to the parameter map.
std::shared_ptr< Parameter > get(const IComponent *comp, const std::string &name, const std::string &type="") const
Get a parameter with a given name and type (std::string version)
double alpha() const
Get lattice parameter.
Definition UnitCell.cpp:133
double a(int nd) const
Get lattice parameter a1-a3 as function of index (0-2)
Definition UnitCell.cpp:94
double c() const
Get lattice parameter.
Definition UnitCell.cpp:128
double beta() const
Get lattice parameter.
Definition UnitCell.cpp:138
double b() const
Get lattice parameter.
Definition UnitCell.cpp:123
double gamma() const
Get lattice parameter.
Definition UnitCell.cpp:143
This class is used to store information about parameters in XML instrument definition files and instr...
const Geometry::IComponent * m_component
value from the log value
const std::string m_value
rather then extracting value from logfile,
const std::string m_type
type of the data, e.g. int, double or string
const std::string m_description
if present, contains help string, describing the parameter
const std::string m_visible
if present, describes whether the parameter shall be visible in InstrumentViewer
std::shared_ptr< Kernel::Interpolation > m_interpolation
evaluating the formula
const std::string m_fittingFunction
specific to fitting parameter
std::string m_penaltyFactor
parameter specify lower and upper bound in that order
const std::string m_formula
specify fitting function
const std::string m_resultUnit
expected result (output) unit from
const std::vector< std::string > m_constraint
specific to fitting
const std::string m_tie
specific to fitting parameter specify any tie
const std::string m_formulaUnit
formula to use for setting this parameter
Exception for when an item is not found in a collection.
Definition Exception.h:145
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
void debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
The concrete, templated class for properties.
Base class for properties.
Definition Property.h:94
virtual std::string value() const =0
Returns the value of the property as a string.
Class for quaternions.
Definition Quat.h:39
void rotate(V3D &) const
Rotate a vector.
Definition Quat.cpp:397
Iterator begin()
Iterator referring to first element in the container.
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
Iterator end()
Iterator referring to the past-the-end element in the container.
std::size_t count() const
Get the total number of tokens.
TimeROI : Object that holds information about when the time measurement was active.
Definition TimeROI.h:18
Class for 3D vectors.
Definition V3D.h:34
void spherical(const double R, const double theta, const double phi) noexcept
Sets the vector position based on spherical coordinates.
Definition V3D.cpp:56
Implements a copy on write data template.
Definition cow_ptr.h:41
Class that provides for a standard Nexus exception.
std::shared_ptr< const ExperimentInfo > ExperimentInfo_const_sptr
Shared pointer to const ExperimentInfo.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
MANTID_API_DLL void applyRectangularDetectorScaleToComponentInfo(Geometry::ComponentInfo &componentInfo, Geometry::IComponent *componentId, const double scaleX, const double scaleY)
Helpers for resizing RectangularDetectors.
std::shared_ptr< Parameter > Parameter_sptr
Typedef for the shared pointer.
Definition Parameter.h:194
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.
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
MANTID_KERNEL_DLL std::string strip(const std::string &A)
strip pre/post spaces
Definition Strings.cpp:419
MANTID_KERNEL_DLL std::string loadFile(const std::string &filename)
Loads the entire contents of a text file into a string.
Definition Strings.cpp:26
int convert(const std::string &A, T &out)
Convert a string into a number.
Definition Strings.cpp:696
int32_t detid_t
Typedef for a detector ID.
Generate a tableworkspace to store the calibration results.
std::string to_string(const wide_integer< Bits, Signed > &n)
static Type fromString(const std::string &modeStr)
Returns the emode from the given string.
Type
Define the available energy transfer modes It is important to assign enums proper numbers,...
Definition DeltaEMode.h:29