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(numDets) + " vs " + std::to_string(detInfo.size()));
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 if (instr->isParametrized()) {
190 sptr_instrument = instr->baseInstrument();
191 // We take a *copy* of the ParameterMap since we are modifying it by setting
192 // a pointer to our DetectorInfo, and in case it contains legacy parameters
193 // such as positions or rotations.
194 m_parmap = std::make_shared<ParameterMap>(*instr->getParameterMap());
195 } else {
196 sptr_instrument = instr;
197 m_parmap = std::make_shared<ParameterMap>();
198 }
199 m_parmap->setInstrument(sptr_instrument.get());
200}
201
212
220
228
236
237namespace {
239
243struct RTP {
244 RTP() : radius(0.0), haveRadius(false), theta(0.0), phi(0.0) {}
245 double radius;
246 bool haveRadius;
247 double theta;
248 double phi;
249};
250
251struct ParameterValue {
252 ParameterValue(const Geometry::XMLInstrumentParameter &paramInfo, const API::Run &run)
253 : info(paramInfo), runData(run) {}
254
255 operator double() {
256 if (info.m_logfileID.empty())
257 return boost::lexical_cast<double>(info.m_value);
258 else {
259 const TimeROI *roi = &runData.getTimeROI();
260 return info.createParamValue(runData.getTimeSeriesProperty<double>(info.m_logfileID), roi);
261 }
262 }
263 operator int() { return boost::lexical_cast<int>(info.m_value); }
264 operator bool() {
265 if (boost::iequals(info.m_value, "true"))
266 return true;
267 else if (boost::iequals(info.m_value, "yes"))
268 return true;
269 else
270 return false;
271 }
273 const Run &runData;
274};
276} // namespace
277
278namespace {
279bool isPositionParameter(const std::string &name) { return ParameterMap::pos() == name; }
280
281bool isRotationParameter(const std::string &name) { return ParameterMap::rot() == name; }
282
283bool isScaleParameter(const std::string &name) { return (name == "scalex" || name == "scaley"); }
284
285bool isRedundantPosOrRot(const std::string &name) {
286 // Check size first as a small optimization.
287 return (name.size() == 4) &&
288 (name == "posx" || name == "posy" || name == "posz" || name == "rotx" || name == "roty" || name == "rotz");
289}
290
291template <class T> T getParam(const std::string &paramType, const std::string &paramValue) {
292 const std::string name = "dummy";
293 auto param = ParameterFactory::create(paramType, name);
294 param->fromString(paramValue);
295 return param->value<T>();
296}
297
298void updatePosition(ComponentInfo &componentInfo, const IComponent *component, const V3D &newRelPos) {
299 const auto compIndex = componentInfo.indexOf(component->getComponentID());
300 V3D position = newRelPos;
301 if (componentInfo.hasParent(compIndex)) {
302 const auto parentIndex = componentInfo.parent(compIndex);
303 componentInfo.rotation(parentIndex).rotate(position);
304 position += componentInfo.position(parentIndex);
305 }
306 componentInfo.setPosition(compIndex, position);
307}
308
309void updateRotation(ComponentInfo &componentInfo, const IComponent *component, const Quat &newRelRot) {
310 const auto compIndex = componentInfo.indexOf(component->getComponentID());
311
312 auto rotation = newRelRot;
313 if (componentInfo.hasParent(compIndex)) {
314 const auto parentIndex = componentInfo.parent(compIndex);
315 rotation = componentInfo.rotation(parentIndex) * newRelRot;
316 }
317 componentInfo.setRotation(compIndex, rotation);
318}
319
320void adjustPositionsFromScaleFactor(ComponentInfo &componentInfo, const IComponent *component,
321 const std::string &paramName, double factor) {
322 double ScaleX = 1.0;
323 double ScaleY = 1.0;
324 if (paramName == "scalex")
325 ScaleX = factor;
326 else
327 ScaleY = factor;
328 applyRectangularDetectorScaleToComponentInfo(componentInfo, component->getComponentID(), ScaleX, ScaleY);
329}
330} // namespace
331
340
341 // Reference to the run
342 const auto &runData = run();
343
344 // Get pointer to parameter map that we may add parameters to and information
345 // about
346 // the parameters that my be specified in the instrument definition file (IDF)
348 Geometry::ParameterMap paramMapForPosAndRot;
349
350 // Get instrument and sample
351 auto &compInfo = mutableComponentInfo();
352 const auto parInstrument = getInstrument();
353 const auto instrument = parInstrument->baseInstrument();
354 const auto &paramInfoFromIDF = instrument->getLogfileCache();
355
356 std::map<const IComponent *, RTP> rtpParams;
357
358 // In this loop position and rotation parameters are inserted into the
359 // temporary map paramMapForPosAndRot. In the subsequent loop, after all
360 // parameters have been parsed, we update positions and rotations in
361 // DetectorInfo and the temporary map goes out of scope. The main reason for
362 // this is that ParameterMap will then take care of assembling parameters for
363 // individual position or rotation components into a vector or quaternion. In
364 // particular, we cannot directly change DetectorInfo since the order of
365 // rotation components is not guaranteed.
366 for (const auto &item : paramInfoFromIDF) {
367 const auto &nameComp = item.first;
368 const auto &paramInfo = item.second;
369 const std::string &paramN = nameComp.first;
370
371 try {
372 // Special case where user has specified r-position,t-position, and/or
373 // p-position.
374 // We need to know all three first to calculate a set of X,Y,Z
375 if (paramN.compare(1, 9, "-position") == 0) {
376 auto &rtpValues = rtpParams[paramInfo->m_component]; // If not found,
377 // constructs
378 // default
379 double value = ParameterValue(*paramInfo, runData);
380 if (paramN.compare(0, 1, "r") == 0) {
381 rtpValues.radius = value;
382 rtpValues.haveRadius = true;
383 } else if (paramN.compare(0, 1, "t") == 0)
384 rtpValues.theta = value;
385 else if (paramN.compare(0, 1, "p") == 0)
386 rtpValues.phi = value;
387 if (rtpValues.haveRadius) {
388 V3D pos;
389 pos.spherical(rtpValues.radius, rtpValues.theta, rtpValues.phi);
390 paramMapForPosAndRot.addV3D(paramInfo->m_component, ParameterMap::pos(), pos);
391 }
392 } else {
393 populateWithParameter(paramMap, paramMapForPosAndRot, paramN, *paramInfo, runData);
394 }
395 } catch (std::exception &exc) {
396 g_log.information() << "Unable to add component parameter '" << nameComp.first << "'. Error: " << exc.what();
397 continue;
398 }
399 }
400 for (const auto &item : paramMapForPosAndRot) {
401 if (isPositionParameter(item.second->name())) {
402 const auto newRelPos = item.second->value<V3D>();
403 updatePosition(compInfo, item.first, newRelPos);
404 } else if (isRotationParameter(item.second->name())) {
405 const auto newRelRot = item.second->value<Quat>();
406 updateRotation(compInfo, item.first, newRelRot);
407 }
408 // Parameters for individual components (x,y,z) are ignored. ParameterMap
409 // did compute the correct compound positions and rotations internally.
410 }
411 // Special case RectangularDetector: Parameters scalex and scaley affect pixel
412 // positions.
413 for (const auto &item : paramMap) {
414 if (isScaleParameter(item.second->name()))
415 adjustPositionsFromScaleFactor(compInfo, item.first, item.second->name(), item.second->value<double>());
416 }
417 // paramMapForPosAndRot goes out of scope, dropping all position and rotation
418 // parameters of detectors (parameters for non-detector components have been
419 // inserted into paramMap via DetectorInfo::setPosition(IComponent *)).
420}
421
429 if (m_spectrumInfo)
432 m_spectrumInfo = std::make_unique<Beamline::SpectrumInfo>(count);
433 m_spectrumInfoWrapper = nullptr;
434}
435
441
446void ExperimentInfo::setDetectorGrouping(const size_t index, const std::set<detid_t> &detIDs) const {
447 SpectrumDefinition specDef;
448 for (const auto detID : detIDs) {
449 try {
450 const size_t detIndex = detectorInfo().indexOf(detID);
451 specDef.add(detIndex);
452 } catch (std::out_of_range &) {
453 // Silently strip bad detector IDs
454 }
455 }
456 m_spectrumInfo->setSpectrumDefinition(index, std::move(specDef));
458}
459
467void ExperimentInfo::updateCachedDetectorGrouping(const size_t /*unused*/) const {
468 throw std::runtime_error("ExperimentInfo::updateCachedDetectorGrouping: "
469 "Cannot update -- grouping information not "
470 "available");
471}
472
478 return *m_sample;
479}
480
490
494const Run &ExperimentInfo::run() const {
496 return *m_run;
497}
498
506 return m_run.access();
507}
508
511
514
527Kernel::Property *ExperimentInfo::getLog(const std::string &log) const {
529 try {
530 return run().getProperty(log);
532 // No log with that name
533 }
534 // If the instrument has a parameter with that name then take the value as a
535 // log name
536 const std::string logName = constInstrumentParameters().getString(sptr_instrument.get(), log);
537 if (logName.empty()) {
538 throw std::invalid_argument("ExperimentInfo::getLog - No instrument parameter named \"" + log +
539 "\". Cannot access full log name");
540 }
541 return run().getProperty(logName);
542}
543
552double ExperimentInfo::getLogAsSingleValue(const std::string &log) const {
554 try {
555 return run().getPropertyAsSingleValue(log);
557 // No log with that name
558 }
559 // If the instrument has a parameter with that name then take the value as a
560 // log name
561 const std::string logName = constInstrumentParameters().getString(sptr_instrument.get(), log);
562 if (logName.empty()) {
563 throw std::invalid_argument("ExperimentInfo::getLog - No instrument parameter named \"" + log +
564 "\". Cannot access full log name");
565 }
566 return run().getPropertyAsSingleValue(logName);
567}
568
575 const Run &thisRun = run();
576 if (!thisRun.hasProperty("run_number")) {
577 // No run_number property, default to 0
578 return 0;
579 } else {
580 Property const *prop = m_run->getProperty("run_number");
581 if (prop) {
582 // Use the string representation. That way both a string and a number
583 // property will work.
584 int val;
585 if (Strings::convert(prop->value(), val))
586 return val;
587 else
588 return 0;
589 }
590 }
591 return 0;
592}
593
604 static const char *emodeTag = "deltaE-mode";
605 std::string emodeStr;
606 if (run().hasProperty(emodeTag)) {
607 emodeStr = run().getPropertyValueAsType<std::string>(emodeTag);
608 } else if (sptr_instrument && constInstrumentParameters().contains(sptr_instrument.get(), emodeTag)) {
610 emodeStr = param->asString();
611 } else {
613 }
614 return Kernel::DeltaEMode::fromString(emodeStr);
615}
616
626double ExperimentInfo::getEFixed(const detid_t detID) const {
628 IDetector_const_sptr det = getInstrument()->getDetector(detID);
629 return getEFixed(det);
630}
631
638double ExperimentInfo::getEFixed(const std::shared_ptr<const Geometry::IDetector> &detector) const {
641 return getEFixedGivenEMode(detector, emode);
642}
643
644double ExperimentInfo::getEFixedForIndirect(const std::shared_ptr<const Geometry::IDetector> &detector,
645 const std::vector<std::string> &parameterNames) const {
646 double efixed = 0.;
647 for (auto &parameterName : parameterNames) {
648 Parameter_sptr par = constInstrumentParameters().getRecursive(detector.get(), parameterName);
649 if (par) {
650 efixed = par->value<double>();
651 } else {
652 std::vector<double> efixedVec = detector->getNumberParameter(parameterName);
653 if (efixedVec.empty()) {
654 int detid = detector->getID();
655 IDetector_const_sptr detectorSingle = getInstrument()->getDetector(detid);
656 efixedVec = detectorSingle->getNumberParameter(parameterName);
657 }
658 if (!efixedVec.empty()) {
659 efixed = efixedVec.at(0);
660 }
661 }
662 }
663 if (efixed == 0.) {
664 std::ostringstream os;
665 os << "ExperimentInfo::getEFixed - Indirect mode efixed requested but "
666 "detector has no Efixed parameter attached. ID="
667 << detector->getID();
668 throw std::runtime_error(os.str());
669 }
670 return efixed;
671}
672
680double ExperimentInfo::getEFixedGivenEMode(const std::shared_ptr<const Geometry::IDetector> &detector,
681 const Kernel::DeltaEMode::Type emode) const {
682 if (emode == Kernel::DeltaEMode::Direct) {
683 double efixed = 0.;
684 for (auto &parameterName : {"Ei", "EnergyRequested", "EnergyEstimate"}) {
685 if (run().hasProperty(parameterName)) {
686 efixed = run().getPropertyValueAsType<double>(parameterName);
687 break;
688 }
689 }
690 if (efixed == 0.) {
691 throw std::runtime_error("Experiment logs do not contain an Ei "
692 "value. Have you run GetEi?");
693 }
694 return efixed;
695 } else if (emode == Kernel::DeltaEMode::Indirect) {
696 if (!detector)
697 throw std::runtime_error("ExperimentInfo::getEFixed - Indirect mode "
698 "efixed requested without a valid detector.");
699 return getEFixedForIndirect(detector, {"Efixed", "EFixed-val"});
700 } else {
701 throw std::runtime_error("ExperimentInfo::getEFixed - EFixed requested for "
702 "elastic mode, don't know what to do!");
703 }
704}
705
706void ExperimentInfo::setEFixed(const detid_t detID, const double value) {
708 IDetector_const_sptr det = getInstrument()->getDetector(detID);
710 pmap.addDouble(det.get(), "Efixed", value);
711}
712
723 std::string date;
724 try {
725 date = run().startTime().toISO8601String();
726 } catch (std::runtime_error &) {
727 g_log.information("run_start/start_time not stored in workspace. Default "
728 "to current date.");
729 date = Types::Core::DateAndTime::getCurrentTime().toISO8601String();
730 }
731 return date;
732}
733
742 std::string date;
743 try {
744 date = run().startTime().toFormattedString();
745 } catch (std::runtime_error &) {
746 g_log.information("Note: run_start/start_time not stored in workspace.");
747 }
748 return date;
749}
750
759 std::string date;
760 try {
761 date = run().endTime().toFormattedString();
762 } catch (std::runtime_error &) {
763 g_log.information("Note: run_start/start_time not stored in workspace.");
764 }
765 return date;
766}
767
768//-----------------------------------------------------------------------------------------------------------------------
769
777 return m_parmap->detectorInfo();
778}
779
785
794 std::lock_guard<std::mutex> lock{m_spectrumInfoMutex};
795 if (!m_spectrumInfo) // this should happen only if not MatrixWorkspace
798 static_cast<void>(detectorInfo());
799 m_spectrumInfoWrapper = std::make_unique<SpectrumInfo>(*m_spectrumInfo, *this, m_parmap->mutableDetectorInfo());
800 }
801 }
802 // Rebuild any spectrum definitions that are out of date. Accessing
803 // `API::SpectrumInfo` will rebuild invalid spectrum definitions as it
804 // encounters them (if detector IDs in an `ISpectrum` are changed), however we
805 // need to deal with one special case here:
806 // If two algorithms (or two threads in the same algorithm) access the same
807 // workspace for reading at the same time, calls to
808 // `updateSpectrumDefinitionIfNecessary` done by `API::SpectrumInfo` break
809 // thread-safety. `Algorithm` sets a read-lock, but this lazy update method is
810 // `const` and will modify internals of the workspace nevertheless. We thus
811 // need explicit locking here. Note that we do not need extra locking in the
812 // case of `ExperimentInfo::mutableSpectrumInfo` or other calls to
813 // `updateSpectrumDefinitionIfNecessary` done by `API::SpectrumInfo`: If the
814 // workspace is only read-locked, this update will ensure that no updates will
815 // be triggered by SpectrumInfo, since changing detector IDs in an `ISpectrum`
816 // is not possible for a read-only workspace. If the workspace is write-locked
817 // detector IDs in ISpectrum may change, but the write-lock by `Algorithm`
818 // guarantees that there is no concurrent reader and thus updating is safe.
820 [](char i) { return i == 1; })) {
821 std::lock_guard<std::mutex> lock{m_spectrumInfoMutex};
823 [](char i) { return i == 1; })) {
824 auto size = static_cast<int64_t>(m_spectrumInfoWrapper->size());
825#pragma omp parallel for
826 for (int64_t i = 0; i < size; ++i) {
828 }
829 }
830 }
831 return *m_spectrumInfoWrapper;
832}
833
837 return const_cast<SpectrumInfo &>(static_cast<const ExperimentInfo &>(*this).spectrumInfo());
838}
839
840const Geometry::ComponentInfo &ExperimentInfo::componentInfo() const { return m_parmap->componentInfo(); }
841
842ComponentInfo &ExperimentInfo::mutableComponentInfo() { return m_parmap->mutableComponentInfo(); }
843
845void ExperimentInfo::setSpectrumDefinitions(Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions) {
846 if (spectrumDefinitions) {
847 m_spectrumInfo = std::make_unique<Beamline::SpectrumInfo>(std::move(spectrumDefinitions));
850 } else {
851 // Keep the old m_spectrumInfo which should have the correct size, but
852 // invalidate all definitions.
854 }
855 m_spectrumInfoWrapper = nullptr;
856}
857
864 // This uses a vector of char, such that flags for different indices can be
865 // set from different threads (std::vector<bool> is not thread-safe).
867}
868
873
880 if (m_spectrumInfo && (m_spectrumInfo->size() != 0))
881 return;
882 const auto &detIDs = sptr_instrument->getDetectorIDs();
883 setNumberOfDetectorGroups(detIDs.size());
884 size_t specIndex = 0;
885 for (const auto detID : detIDs) {
886 m_det2group[detID] = specIndex;
887 const size_t detIndex = detectorInfo().indexOf(detID);
888 SpectrumDefinition specDef;
889 specDef.add(detIndex);
890 m_spectrumInfo->setSpectrumDefinition(specIndex, std::move(specDef));
891 m_spectrumDefinitionNeedsUpdate.at(specIndex) = 0;
892 specIndex++;
893 }
894}
895
901
906void ExperimentInfo::saveExperimentInfoNexus(Nexus::File *file, bool saveLegacyInstrument) const {
908 if (saveLegacyInstrument) {
909 instrument->saveNexus(file, "instrument");
910 }
911 sample().saveNexus(file, "sample");
912 run().saveNexus(file, "logs");
913}
914
921void ExperimentInfo::saveExperimentInfoNexus(Nexus::File *file, bool saveInstrument, bool saveSample,
922 bool saveLogs) const {
924
925 if (saveInstrument)
926 instrument->saveNexus(file, "instrument");
927 if (saveSample)
928 sample().saveNexus(file, "sample");
929 if (saveLogs)
930 run().saveNexus(file, "logs");
931}
932
937void ExperimentInfo::loadSampleAndLogInfoNexus(Nexus::File *file, std::string const &prefix) {
938 // First, the sample and then the logs
939 int sampleVersion = mutableSample().loadNexus(file, "sample");
940 if (sampleVersion == 0) {
941 // Old-style (before Sep-9-2011) NXS processed
942 // sample field contains both the logs and the sample details
943 file->openGroup("sample", "NXsample");
944 this->mutableRun().loadNexus(file, "", prefix);
945 file->closeGroup();
946 } else {
947 // Newer style: separate "logs" field for the Run object
948 this->mutableRun().loadNexus(file, "logs", prefix);
949 }
950}
951
956 // First, the sample and then the logs
957 int sampleVersion = mutableSample().loadNexus(file, "sample");
958 if (sampleVersion == 0) {
959 // Old-style (before Sep-9-2011) NXS processed
960 // sample field contains both the logs and the sample details
961 file->openGroup("sample", "NXsample");
962 this->mutableRun().loadNexus(file, "");
963 file->closeGroup();
964 } else {
965 // Newer style: separate "logs" field for the Run object
966 this->mutableRun().loadNexus(file, "logs");
967 }
968}
969
970void ExperimentInfo::loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file,
971 std::string &parameterStr, const std::string &prefix) {
972 // TODO load sample and log info
973 loadSampleAndLogInfoNexus(file, prefix);
974 loadInstrumentInfoNexus(nxFilename, file, parameterStr);
975}
976
987void ExperimentInfo::loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file,
988 std::string &parameterStr) {
989 // load sample and log info
991
992 loadInstrumentInfoNexus(nxFilename, file, parameterStr);
993}
994
1005void ExperimentInfo::loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file,
1006 std::string &parameterStr) {
1007
1008 // Open instrument group
1009 file->openGroup("instrument", "NXinstrument");
1010
1011 // Try to get the instrument embedded in the Nexus file
1012 std::string instrumentName;
1013 std::string instrumentXml;
1014 loadEmbeddedInstrumentInfoNexus(file, instrumentName, instrumentXml);
1015
1016 // load parameters if found
1017 loadInstrumentParametersNexus(file, parameterStr);
1018
1019 // Close the instrument group
1020 file->closeGroup();
1021
1022 // Set the instrument given the name and and XML obtained
1023 setInstumentFromXML(nxFilename, instrumentName, instrumentXml);
1024}
1025
1035void ExperimentInfo::loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file) {
1036
1037 // Open instrument group
1038 file->openGroup("instrument", "NXinstrument");
1039
1040 // Try to get the instrument embedded in the Nexus file
1041 std::string instrumentName;
1042 std::string instrumentXml;
1043 loadEmbeddedInstrumentInfoNexus(file, instrumentName, instrumentXml);
1044
1045 // Close the instrument group
1046 file->closeGroup();
1047
1048 // Set the instrument given the name and and XML obtained
1049 setInstumentFromXML(nxFilename, instrumentName, instrumentXml);
1050}
1051
1058void ExperimentInfo::loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName,
1059 std::string &instrumentXml) {
1060
1061 file->readData("name", instrumentName);
1062
1063 try {
1064 file->openGroup("instrument_xml", "NXnote");
1065 file->readData("data", instrumentXml);
1066 file->closeGroup();
1067 } catch (Nexus::Exception const &ex) {
1068 g_log.debug(std::string("Unable to load instrument_xml: ") + ex.what());
1069 }
1070}
1071
1081void ExperimentInfo::setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName,
1082 std::string &instrumentXml) {
1083
1084 instrumentXml = Strings::strip(instrumentXml);
1085 instrumentName = Strings::strip(instrumentName);
1086 std::string instrumentFilename;
1087 if (!instrumentXml.empty()) {
1088 // instrument xml is being loaded from the nxs file, set the
1089 // instrumentFilename
1090 // to identify the Nexus file as the source of the data
1091 instrumentFilename = nxFilename;
1092 g_log.debug() << "Using instrument IDF XML text contained in nexus file.\n";
1093 } else {
1094 // XML was not included or was empty
1095 // Use the instrument name to find the file
1096 instrumentFilename = InstrumentFileFinder::getInstrumentFilename(instrumentName, getWorkspaceStartDate());
1097 // And now load the contents
1098 instrumentXml = loadInstrumentXML(instrumentFilename);
1099 }
1100
1101 // ---------- Now parse that XML to make the instrument -------------------
1102 if (!instrumentXml.empty() && !instrumentName.empty()) {
1103 InstrumentDefinitionParser parser(instrumentFilename, instrumentName, instrumentXml);
1104
1105 std::string instrumentNameMangled = parser.getMangledName();
1106 Instrument_sptr instr;
1107 // Check whether the instrument is already in the InstrumentDataService
1108 if (InstrumentDataService::Instance().doesExist(instrumentNameMangled)) {
1109 // If it does, just use the one from the one stored there
1110 instr = InstrumentDataService::Instance().retrieve(instrumentNameMangled);
1111 } else {
1112 // Really create the instrument
1113 instr = parser.parseXML(nullptr);
1114 // Parse the instrument tree (internally create ComponentInfo and
1115 // DetectorInfo). This is an optimization that avoids duplicate parsing
1116 // of the instrument tree when loading multiple workspaces with the same
1117 // instrument. As a consequence less time is spent and less memory is
1118 // used. Note that this is only possible since the tree in `instrument`
1119 // will not be modified once we add it to the IDS.
1120 instr->parseTreeAndCacheBeamline();
1121
1122 // Add to data service for later retrieval
1123 InstrumentDataService::Instance().add(instrumentNameMangled, instr);
1124 }
1125 // Now set the instrument
1126 this->setInstrument(instr);
1127 }
1128}
1129
1136std::string ExperimentInfo::loadInstrumentXML(const std::string &filename) {
1137 try {
1138 return Strings::loadFile(filename);
1139 } catch (std::exception &e) {
1140 g_log.error() << "Error loading instrument IDF file: " << filename << ".\n";
1141 g_log.debug() << e.what() << '\n';
1142 throw;
1143 }
1144}
1145
1152void ExperimentInfo::loadInstrumentParametersNexus(Nexus::File *file, std::string &parameterStr) {
1153 try {
1154 file->openGroup("instrument_parameter_map", "NXnote");
1155 file->readData("data", parameterStr);
1156 file->closeGroup();
1157 } catch (Nexus::Exception const &ex) {
1158 g_log.debug(std::string("Unable to load instrument_parameter_map: ") + ex.what());
1159 g_log.information("Parameter map entry missing from NeXus file. Continuing without it.");
1160 }
1161}
1162
1169void ExperimentInfo::readParameterMap(const std::string &parameterStr) {
1171 auto &compInfo = mutableComponentInfo();
1172 auto &detInfo = mutableDetectorInfo();
1173 const auto parInstrument = getInstrument();
1174 const auto instr = parInstrument->baseInstrument();
1175
1178 Mantid::Kernel::StringTokenizer splitter(parameterStr, "|", options);
1179
1180 auto iend = splitter.end();
1181
1183 const std::string visibilityKey = "visible:"; // if visibility is defined, the value will follow this key
1184 // std::string prev_name;
1185 for (auto itr = splitter.begin(); itr != iend; ++itr) {
1186 tokens = Mantid::Kernel::StringTokenizer(*itr, ";");
1187 if (tokens.count() < 4)
1188 continue;
1189 std::string comp_name = tokens[0];
1190 // if( comp_name == prev_name ) continue; this blocks reading in different
1191 // parameters of the same component. RNT
1192 // prev_name = comp_name;
1193 const Geometry::IComponent *comp = nullptr;
1194 if (comp_name.find("detID:") != std::string::npos) {
1195 int detID = std::stoi(comp_name.substr(6));
1196 comp = instr->getDetector(detID).get();
1197 if (!comp) {
1198 g_log.warning() << "Cannot find detector " << detID << '\n';
1199 continue;
1200 }
1201 } else {
1202 comp = instr->getComponentByName(comp_name).get();
1203 if (!comp) {
1204 g_log.warning() << "Cannot find component " << comp_name << '\n';
1205 continue;
1206 }
1207 }
1208
1209 // create parameter's value as a sum of all tokens with index 3 or larger
1210 // this allow a parameter's value to contain ";"
1211 std::string paramValue = tokens[3];
1212 auto size = static_cast<int>(tokens.count());
1213 for (int i = 4; i < size; i++)
1214 paramValue += ";" + tokens[i];
1215 const auto &paramType = tokens[1];
1216 const auto &paramName = tokens[2];
1217 auto &paramVisibility = tokens[size - 1]; // parameter visibility, if defined, is the last token
1218 if (paramVisibility.find(visibilityKey) > paramVisibility.size())
1219 paramVisibility = "true"; // visibility not defined: default to visible
1220 else { // defined, the paramValue has one too many entries, -1 to remove also the semicolon
1221 paramVisibility =
1222 paramVisibility.substr(paramVisibility.find(visibilityKey) + visibilityKey.size(), paramVisibility.size());
1223 paramValue.erase(paramValue.find(visibilityKey) - 1, paramValue.size());
1224 }
1225 const auto paramDescr = std::string("");
1226 if (paramName == "masked") {
1227 auto value = getParam<bool>(paramType, paramValue);
1228 if (value) {
1229 // Do not add masking to ParameterMap, it is stored in DetectorInfo
1230 const auto componentIndex = compInfo.indexOf(comp->getComponentID());
1231 if (!compInfo.isDetector(componentIndex)) {
1232 throw std::runtime_error("Found masking for a non-detector "
1233 "component. This is not possible");
1234 } else
1235 detInfo.setMasked(componentIndex, value); // all detector indexes
1236 // have same component
1237 // index (guarantee)
1238 }
1239 } else if (isPositionParameter(paramName)) {
1240 // We are parsing a string obtained from a ParameterMap. The map may
1241 // contain posx, posy, and posz (in addition to pos). However, when these
1242 // component wise positions are set, 'pos' is updated accordingly. We are
1243 // thus ignoring position components below.
1244 const auto newRelPos = getParam<V3D>(paramType, paramValue);
1245 updatePosition(compInfo, comp, newRelPos);
1246 } else if (isRotationParameter(paramName)) {
1247 // We are parsing a string obtained from a ParameterMap. The map may
1248 // contain rotx, roty, and rotz (in addition to rot). However, when these
1249 // component wise rotations are set, 'rot' is updated accordingly. We are
1250 // thus ignoring rotation components below.
1251 const auto newRelRot = getParam<Quat>(paramType, paramValue);
1252 updateRotation(compInfo, comp, newRelRot);
1253 } else if (!isRedundantPosOrRot(paramName)) {
1254 // Special case RectangularDetector: Parameters scalex and scaley affect
1255 // pixel positions, but we must also add the parameter below.
1256 if (isScaleParameter(paramName))
1257 adjustPositionsFromScaleFactor(compInfo, comp, paramName, getParam<double>(paramType, paramValue));
1258 pmap.add(paramType, comp, paramName, paramValue, &paramDescr, paramVisibility);
1259 }
1260 }
1261}
1262
1274 Geometry::ParameterMap &paramMapForPosAndRot, const std::string &name,
1275 const Geometry::XMLInstrumentParameter &paramInfo, const Run &runData) {
1276 const std::string &category = paramInfo.m_type;
1277 ParameterValue paramValue(paramInfo,
1278 runData); // Defines implicit conversion operator
1279
1280 const std::string *pDescription = nullptr;
1281 if (!paramInfo.m_description.empty())
1282 pDescription = &paramInfo.m_description;
1283 std::string pVisible = "true";
1284 if (!paramInfo.m_visible.empty())
1285 pVisible = paramInfo.m_visible;
1286
1287 // Some names are special. Values should be convertible to double
1288 if (name == "masked") {
1289 bool value(paramValue);
1290 if (value) {
1291 // Do not add masking to ParameterMap, it is stored in DetectorInfo
1292
1293 const auto componentIndex = componentInfo().indexOf(paramInfo.m_component->getComponentID());
1294 if (!componentInfo().isDetector(componentIndex))
1295 throw std::runtime_error("Found masking for a non-detector component. This is not possible");
1296 mutableDetectorInfo().setMasked(componentIndex,
1297 paramValue); // all detector indexes have
1298 // same component index
1299 // (guarantee)
1300 }
1301 } else if (name == "x" || name == "y" || name == "z") {
1302 paramMapForPosAndRot.addPositionCoordinate(paramInfo.m_component, name, paramValue);
1303 } else if (name == "rot" || name == "rotx" || name == "roty" || name == "rotz") {
1304 // Effectively this is dropping any parameters named 'rot'.
1305 paramMapForPosAndRot.addRotationParam(paramInfo.m_component, name, paramValue, pDescription);
1306 } else if (category == "fitting") {
1307 std::ostringstream str;
1308 str << paramInfo.m_value << " , " << paramInfo.m_fittingFunction << " , " << name << " , "
1309 << paramInfo.m_constraint[0] << " , " << paramInfo.m_constraint[1] << " , " << paramInfo.m_penaltyFactor
1310 << " , " << paramInfo.m_tie << " , " << paramInfo.m_formula << " , " << paramInfo.m_formulaUnit << " , "
1311 << paramInfo.m_resultUnit << " , " << (*(paramInfo.m_interpolation));
1312 paramMap.add("fitting", paramInfo.m_component, name, str.str(), pDescription, pVisible);
1313 } else if (category == "string") {
1314 paramMap.addString(paramInfo.m_component, name, paramInfo.m_value, pDescription, pVisible);
1315 } else if (category == "bool") {
1316 paramMap.addBool(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1317 } else if (category == "int") {
1318 paramMap.addInt(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1319 } else { // assume double
1320 paramMap.addDouble(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1321 }
1322}
1323
1325 // The default implementation does nothing. Used by subclasses
1326 // (FileBackedExperimentInfo) to load content from files upon access.
1327}
1328
1329} // namespace Mantid::API
1330
1331namespace Mantid::Kernel {
1332
1333template <>
1335IPropertyManager::getValue<Mantid::API::ExperimentInfo_sptr>(const std::string &name) const {
1336 auto *prop = dynamic_cast<PropertyWithValue<Mantid::API::ExperimentInfo_sptr> *>(getPointerToProperty(name));
1337 if (prop) {
1338 return *prop;
1339 } else {
1340 std::string message =
1341 "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<ExperimentInfo>.";
1342 throw std::runtime_error(message);
1343 }
1344}
1345
1346template <>
1348IPropertyManager::getValue<Mantid::API::ExperimentInfo_const_sptr>(const std::string &name) const {
1349 auto const *prop = dynamic_cast<PropertyWithValue<Mantid::API::ExperimentInfo_sptr> *>(getPointerToProperty(name));
1350 if (prop) {
1351 return prop->operator()();
1352 } else {
1353 std::string message =
1354 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<ExperimentInfo>.";
1355 throw std::runtime_error(message);
1356 }
1357}
1358
1359} // 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:326
void saveNexus(Nexus::File *file, const std::string &group) const
Save the object to an open NeXus file.
Definition Sample.cpp:285
const Geometry::OrientedLattice & getOrientedLattice() const
Get a reference to the sample's OrientedLattice.
Definition Sample.cpp:153
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:48
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 add(const std::string &type, const IComponent *comp, const std::string &name, const std::string &value, const std::string *const pDescription=nullptr, const std::string &visible="true")
Method for adding a parameter providing its value as a string.
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