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 &nameComp = item.first;
369 const auto &paramInfo = item.second;
370 const std::string &paramN = nameComp.first;
371
372 try {
373 // Special case where user has specified r-position,t-position, and/or
374 // p-position.
375 // We need to know all three first to calculate a set of X,Y,Z
376 if (paramN.compare(1, 9, "-position") == 0) {
377 auto &rtpValues = rtpParams[paramInfo->m_component]; // If not found,
378 // constructs
379 // default
380 double value = ParameterValue(*paramInfo, runData);
381 if (paramN.compare(0, 1, "r") == 0) {
382 rtpValues.radius = value;
383 rtpValues.haveRadius = true;
384 } else if (paramN.compare(0, 1, "t") == 0)
385 rtpValues.theta = value;
386 else if (paramN.compare(0, 1, "p") == 0)
387 rtpValues.phi = value;
388 if (rtpValues.haveRadius) {
389 V3D pos;
390 pos.spherical(rtpValues.radius, rtpValues.theta, rtpValues.phi);
391 paramMapForPosAndRot.addV3D(paramInfo->m_component, ParameterMap::pos(), pos);
392 }
393 } else {
394 populateWithParameter(paramMap, paramMapForPosAndRot, paramN, *paramInfo, runData);
395 }
396 } catch (std::exception &exc) {
397 g_log.information() << "Unable to add component parameter '" << nameComp.first << "'. Error: " << exc.what();
398 continue;
399 }
400 }
401 for (const auto &item : paramMapForPosAndRot) {
402 if (isPositionParameter(item.second->name())) {
403 const auto newRelPos = item.second->value<V3D>();
404 updatePosition(compInfo, item.first, newRelPos);
405 } else if (isRotationParameter(item.second->name())) {
406 const auto newRelRot = item.second->value<Quat>();
407 updateRotation(compInfo, item.first, newRelRot);
408 }
409 // Parameters for individual components (x,y,z) are ignored. ParameterMap
410 // did compute the correct compound positions and rotations internally.
411 }
412 // Special case RectangularDetector: Parameters scalex and scaley affect pixel
413 // positions.
414 for (const auto &item : paramMap) {
415 if (isScaleParameter(item.second->name()))
416 adjustPositionsFromScaleFactor(compInfo, item.first, item.second->name(), item.second->value<double>());
417 }
418 // paramMapForPosAndRot goes out of scope, dropping all position and rotation
419 // parameters of detectors (parameters for non-detector components have been
420 // inserted into paramMap via DetectorInfo::setPosition(IComponent *)).
421}
422
430 if (m_spectrumInfo)
433 m_spectrumInfo = std::make_unique<Beamline::SpectrumInfo>(count);
434 m_spectrumInfoWrapper = nullptr;
435}
436
442
447void ExperimentInfo::setDetectorGrouping(const size_t index, const std::set<detid_t> &detIDs) const {
448 SpectrumDefinition specDef;
449 for (const auto detID : detIDs) {
450 try {
451 const size_t detIndex = detectorInfo().indexOf(detID);
452 specDef.add(detIndex);
453 } catch (std::out_of_range &) {
454 // Silently strip bad detector IDs
455 }
456 }
457 m_spectrumInfo->setSpectrumDefinition(index, std::move(specDef));
459}
460
468void ExperimentInfo::updateCachedDetectorGrouping(const size_t /*unused*/) const {
469 throw std::runtime_error("ExperimentInfo::updateCachedDetectorGrouping: "
470 "Cannot update -- grouping information not "
471 "available");
472}
473
479 return *m_sample;
480}
481
491
495const Run &ExperimentInfo::run() const {
497 return *m_run;
498}
499
507 return m_run.access();
508}
509
512
515
528Kernel::Property *ExperimentInfo::getLog(const std::string &log) const {
530 try {
531 return run().getProperty(log);
533 // No log with that name
534 }
535 // If the instrument has a parameter with that name then take the value as a
536 // log name
537 const std::string logName = constInstrumentParameters().getString(sptr_instrument.get(), log);
538 if (logName.empty()) {
539 throw std::invalid_argument("ExperimentInfo::getLog - No instrument parameter named \"" + log +
540 "\". Cannot access full log name");
541 }
542 return run().getProperty(logName);
543}
544
553double ExperimentInfo::getLogAsSingleValue(const std::string &log) const {
555 try {
556 return run().getPropertyAsSingleValue(log);
558 // No log with that name
559 }
560 // If the instrument has a parameter with that name then take the value as a
561 // log name
562 const std::string logName = constInstrumentParameters().getString(sptr_instrument.get(), log);
563 if (logName.empty()) {
564 throw std::invalid_argument("ExperimentInfo::getLog - No instrument parameter named \"" + log +
565 "\". Cannot access full log name");
566 }
567 return run().getPropertyAsSingleValue(logName);
568}
569
576 const Run &thisRun = run();
577 if (!thisRun.hasProperty("run_number")) {
578 // No run_number property, default to 0
579 return 0;
580 } else {
581 Property const *prop = m_run->getProperty("run_number");
582 if (prop) {
583 // Use the string representation. That way both a string and a number
584 // property will work.
585 int val;
586 if (Strings::convert(prop->value(), val))
587 return val;
588 else
589 return 0;
590 }
591 }
592 return 0;
593}
594
605 static const char *emodeTag = "deltaE-mode";
606 std::string emodeStr;
607 if (run().hasProperty(emodeTag)) {
608 emodeStr = run().getPropertyValueAsType<std::string>(emodeTag);
609 } else if (sptr_instrument && constInstrumentParameters().contains(sptr_instrument.get(), emodeTag)) {
611 emodeStr = param->asString();
612 } else {
614 }
615 return Kernel::DeltaEMode::fromString(emodeStr);
616}
617
627double ExperimentInfo::getEFixed(const detid_t detID) const {
629 IDetector_const_sptr det = getInstrument()->getDetector(detID);
630 return getEFixed(det);
631}
632
639double ExperimentInfo::getEFixed(const std::shared_ptr<const Geometry::IDetector> &detector) const {
642 return getEFixedGivenEMode(detector, emode);
643}
644
645double ExperimentInfo::getEFixedForIndirect(const std::shared_ptr<const Geometry::IDetector> &detector,
646 const std::vector<std::string> &parameterNames) const {
647 double efixed = 0.;
648 for (auto &parameterName : parameterNames) {
649 Parameter_sptr par = constInstrumentParameters().getRecursive(detector.get(), parameterName);
650 if (par) {
651 efixed = par->value<double>();
652 } else {
653 std::vector<double> efixedVec = detector->getNumberParameter(parameterName);
654 if (efixedVec.empty()) {
655 int detid = detector->getID();
656 IDetector_const_sptr detectorSingle = getInstrument()->getDetector(detid);
657 efixedVec = detectorSingle->getNumberParameter(parameterName);
658 }
659 if (!efixedVec.empty()) {
660 efixed = efixedVec.at(0);
661 }
662 }
663 }
664 if (efixed == 0.) {
665 std::ostringstream os;
666 os << "ExperimentInfo::getEFixed - Indirect mode efixed requested but "
667 "detector has no Efixed parameter attached. ID="
668 << detector->getID();
669 throw std::runtime_error(os.str());
670 }
671 return efixed;
672}
673
681double ExperimentInfo::getEFixedGivenEMode(const std::shared_ptr<const Geometry::IDetector> &detector,
682 const Kernel::DeltaEMode::Type emode) const {
683 if (emode == Kernel::DeltaEMode::Direct) {
684 double efixed = 0.;
685 for (auto &parameterName : {"Ei", "EnergyRequested", "EnergyEstimate"}) {
686 if (run().hasProperty(parameterName)) {
687 efixed = run().getPropertyValueAsType<double>(parameterName);
688 break;
689 }
690 }
691 if (efixed == 0.) {
692 throw std::runtime_error("Experiment logs do not contain an Ei "
693 "value. Have you run GetEi?");
694 }
695 return efixed;
696 } else if (emode == Kernel::DeltaEMode::Indirect) {
697 if (!detector)
698 throw std::runtime_error("ExperimentInfo::getEFixed - Indirect mode "
699 "efixed requested without a valid detector.");
700 return getEFixedForIndirect(detector, {"Efixed", "EFixed-val"});
701 } else {
702 throw std::runtime_error("ExperimentInfo::getEFixed - EFixed requested for "
703 "elastic mode, don't know what to do!");
704 }
705}
706
707void ExperimentInfo::setEFixed(const detid_t detID, const double value) {
709 IDetector_const_sptr det = getInstrument()->getDetector(detID);
711 pmap.addDouble(det.get(), "Efixed", value);
712}
713
724 std::string date;
725 try {
726 date = run().startTime().toISO8601String();
727 } catch (std::runtime_error &) {
728 g_log.information("run_start/start_time not stored in workspace. Default "
729 "to current date.");
730 date = Types::Core::DateAndTime::getCurrentTime().toISO8601String();
731 }
732 return date;
733}
734
743 std::string date;
744 try {
745 date = run().startTime().toFormattedString();
746 } catch (std::runtime_error &) {
747 g_log.information("Note: run_start/start_time not stored in workspace.");
748 }
749 return date;
750}
751
760 std::string date;
761 try {
762 date = run().endTime().toFormattedString();
763 } catch (std::runtime_error &) {
764 g_log.information("Note: run_start/start_time not stored in workspace.");
765 }
766 return date;
767}
768
769//-----------------------------------------------------------------------------------------------------------------------
770
778 return m_parmap->detectorInfo();
779}
780
786
795 std::lock_guard<std::mutex> lock{m_spectrumInfoMutex};
796 if (!m_spectrumInfo) // this should happen only if not MatrixWorkspace
799 static_cast<void>(detectorInfo());
800 m_spectrumInfoWrapper = std::make_unique<SpectrumInfo>(*m_spectrumInfo, *this, m_parmap->mutableDetectorInfo());
801 }
802 }
803 // Rebuild any spectrum definitions that are out of date. Accessing
804 // `API::SpectrumInfo` will rebuild invalid spectrum definitions as it
805 // encounters them (if detector IDs in an `ISpectrum` are changed), however we
806 // need to deal with one special case here:
807 // If two algorithms (or two threads in the same algorithm) access the same
808 // workspace for reading at the same time, calls to
809 // `updateSpectrumDefinitionIfNecessary` done by `API::SpectrumInfo` break
810 // thread-safety. `Algorithm` sets a read-lock, but this lazy update method is
811 // `const` and will modify internals of the workspace nevertheless. We thus
812 // need explicit locking here. Note that we do not need extra locking in the
813 // case of `ExperimentInfo::mutableSpectrumInfo` or other calls to
814 // `updateSpectrumDefinitionIfNecessary` done by `API::SpectrumInfo`: If the
815 // workspace is only read-locked, this update will ensure that no updates will
816 // be triggered by SpectrumInfo, since changing detector IDs in an `ISpectrum`
817 // is not possible for a read-only workspace. If the workspace is write-locked
818 // detector IDs in ISpectrum may change, but the write-lock by `Algorithm`
819 // guarantees that there is no concurrent reader and thus updating is safe.
821 [](char i) { return i == 1; })) {
822 std::lock_guard<std::mutex> lock{m_spectrumInfoMutex};
824 [](char i) { return i == 1; })) {
825 auto size = static_cast<int64_t>(m_spectrumInfoWrapper->size());
826#pragma omp parallel for
827 for (int64_t i = 0; i < size; ++i) {
829 }
830 }
831 }
832 return *m_spectrumInfoWrapper;
833}
834
838 return const_cast<SpectrumInfo &>(static_cast<const ExperimentInfo &>(*this).spectrumInfo());
839}
840
841const Geometry::ComponentInfo &ExperimentInfo::componentInfo() const { return m_parmap->componentInfo(); }
842
843ComponentInfo &ExperimentInfo::mutableComponentInfo() { return m_parmap->mutableComponentInfo(); }
844
846void ExperimentInfo::setSpectrumDefinitions(Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions) {
847 if (spectrumDefinitions) {
848 m_spectrumInfo = std::make_unique<Beamline::SpectrumInfo>(std::move(spectrumDefinitions));
851 } else {
852 // Keep the old m_spectrumInfo which should have the correct size, but
853 // invalidate all definitions.
855 }
856 m_spectrumInfoWrapper = nullptr;
857}
858
865 // This uses a vector of char, such that flags for different indices can be
866 // set from different threads (std::vector<bool> is not thread-safe).
868}
869
874
881 if (m_spectrumInfo && (m_spectrumInfo->size() != 0))
882 return;
883 const auto &detIDs = sptr_instrument->getDetectorIDs();
884 setNumberOfDetectorGroups(detIDs.size());
885 size_t specIndex = 0;
886 for (const auto detID : detIDs) {
887 m_det2group[detID] = specIndex;
888 const size_t detIndex = detectorInfo().indexOf(detID);
889 SpectrumDefinition specDef;
890 specDef.add(detIndex);
891 m_spectrumInfo->setSpectrumDefinition(specIndex, std::move(specDef));
892 m_spectrumDefinitionNeedsUpdate.at(specIndex) = 0;
893 specIndex++;
894 }
895}
896
902
907void ExperimentInfo::saveExperimentInfoNexus(Nexus::File *file, bool saveLegacyInstrument) const {
909 if (saveLegacyInstrument) {
910 instrument->saveNexus(file, "instrument");
911 }
912 sample().saveNexus(file, "sample");
913 run().saveNexus(file, "logs");
914}
915
922void ExperimentInfo::saveExperimentInfoNexus(Nexus::File *file, bool saveInstrument, bool saveSample,
923 bool saveLogs) const {
925
926 if (saveInstrument)
927 instrument->saveNexus(file, "instrument");
928 if (saveSample)
929 sample().saveNexus(file, "sample");
930 if (saveLogs)
931 run().saveNexus(file, "logs");
932}
933
938void ExperimentInfo::loadSampleAndLogInfoNexus(Nexus::File *file, std::string const &prefix) {
939 // First, the sample and then the logs
940 int sampleVersion = mutableSample().loadNexus(file, "sample");
941 if (sampleVersion == 0) {
942 // Old-style (before Sep-9-2011) NXS processed
943 // sample field contains both the logs and the sample details
944 file->openGroup("sample", "NXsample");
945 this->mutableRun().loadNexus(file, "", prefix);
946 file->closeGroup();
947 } else {
948 // Newer style: separate "logs" field for the Run object
949 this->mutableRun().loadNexus(file, "logs", prefix);
950 }
951}
952
957 // First, the sample and then the logs
958 int sampleVersion = mutableSample().loadNexus(file, "sample");
959 if (sampleVersion == 0) {
960 // Old-style (before Sep-9-2011) NXS processed
961 // sample field contains both the logs and the sample details
962 file->openGroup("sample", "NXsample");
963 this->mutableRun().loadNexus(file, "");
964 file->closeGroup();
965 } else {
966 // Newer style: separate "logs" field for the Run object
967 this->mutableRun().loadNexus(file, "logs");
968 }
969}
970
971void ExperimentInfo::loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file,
972 std::string &parameterStr, const std::string &prefix) {
973 // TODO load sample and log info
974 loadSampleAndLogInfoNexus(file, prefix);
975 loadInstrumentInfoNexus(nxFilename, file, parameterStr);
976}
977
988void ExperimentInfo::loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file,
989 std::string &parameterStr) {
990 // load sample and log info
992
993 loadInstrumentInfoNexus(nxFilename, file, parameterStr);
994}
995
1006void ExperimentInfo::loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file,
1007 std::string &parameterStr) {
1008
1009 // Open instrument group
1010 file->openGroup("instrument", "NXinstrument");
1011
1012 // Try to get the instrument embedded in the Nexus file
1013 std::string instrumentName;
1014 std::string instrumentXml;
1015 loadEmbeddedInstrumentInfoNexus(file, instrumentName, instrumentXml);
1016
1017 // load parameters if found
1018 loadInstrumentParametersNexus(file, parameterStr);
1019
1020 // Close the instrument group
1021 file->closeGroup();
1022
1023 // Set the instrument given the name and and XML obtained
1024 setInstumentFromXML(nxFilename, instrumentName, instrumentXml);
1025}
1026
1036void ExperimentInfo::loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file) {
1037
1038 // Open instrument group
1039 file->openGroup("instrument", "NXinstrument");
1040
1041 // Try to get the instrument embedded in the Nexus file
1042 std::string instrumentName;
1043 std::string instrumentXml;
1044 loadEmbeddedInstrumentInfoNexus(file, instrumentName, instrumentXml);
1045
1046 // Close the instrument group
1047 file->closeGroup();
1048
1049 // Set the instrument given the name and and XML obtained
1050 setInstumentFromXML(nxFilename, instrumentName, instrumentXml);
1051}
1052
1059void ExperimentInfo::loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName,
1060 std::string &instrumentXml) {
1061
1062 file->readData("name", instrumentName);
1063
1064 try {
1065 file->openGroup("instrument_xml", "NXnote");
1066 file->readData("data", instrumentXml);
1067 file->closeGroup();
1068 } catch (Nexus::Exception const &ex) {
1069 g_log.debug(std::string("Unable to load instrument_xml: ") + ex.what());
1070 }
1071}
1072
1082void ExperimentInfo::setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName,
1083 std::string &instrumentXml) {
1084
1085 instrumentXml = Strings::strip(instrumentXml);
1086 instrumentName = Strings::strip(instrumentName);
1087 std::string instrumentFilename;
1088 if (!instrumentXml.empty()) {
1089 // instrument xml is being loaded from the nxs file, set the
1090 // instrumentFilename
1091 // to identify the Nexus file as the source of the data
1092 instrumentFilename = nxFilename;
1093 g_log.debug() << "Using instrument IDF XML text contained in nexus file.\n";
1094 } else {
1095 // XML was not included or was empty
1096 // Use the instrument name to find the file
1097 instrumentFilename = InstrumentFileFinder::getInstrumentFilename(instrumentName, getWorkspaceStartDate());
1098 // And now load the contents
1099 instrumentXml = loadInstrumentXML(instrumentFilename);
1100 }
1101
1102 // ---------- Now parse that XML to make the instrument -------------------
1103 if (!instrumentXml.empty() && !instrumentName.empty()) {
1104 InstrumentDefinitionParser parser(instrumentFilename, instrumentName, instrumentXml);
1105
1106 std::string instrumentNameMangled = parser.getMangledName();
1107 Instrument_sptr instr;
1108 // Check whether the instrument is already in the InstrumentDataService
1109 if (InstrumentDataService::Instance().doesExist(instrumentNameMangled)) {
1110 // If it does, just use the one from the one stored there
1111 instr = InstrumentDataService::Instance().retrieve(instrumentNameMangled);
1112 } else {
1113 // Really create the instrument
1114 instr = parser.parseXML(nullptr);
1115 // Parse the instrument tree (internally create ComponentInfo and
1116 // DetectorInfo). This is an optimization that avoids duplicate parsing
1117 // of the instrument tree when loading multiple workspaces with the same
1118 // instrument. As a consequence less time is spent and less memory is
1119 // used. Note that this is only possible since the tree in `instrument`
1120 // will not be modified once we add it to the IDS.
1121 instr->parseTreeAndCacheBeamline();
1122
1123 // Add to data service for later retrieval
1124 InstrumentDataService::Instance().add(instrumentNameMangled, instr);
1125 }
1126 // Now set the instrument
1127 this->setInstrument(instr);
1128 }
1129}
1130
1137std::string ExperimentInfo::loadInstrumentXML(const std::string &filename) {
1138 try {
1139 return Strings::loadFile(filename);
1140 } catch (std::exception &e) {
1141 g_log.error() << "Error loading instrument IDF file: " << filename << ".\n";
1142 g_log.debug() << e.what() << '\n';
1143 throw;
1144 }
1145}
1146
1153void ExperimentInfo::loadInstrumentParametersNexus(Nexus::File *file, std::string &parameterStr) {
1154 try {
1155 file->openGroup("instrument_parameter_map", "NXnote");
1156 file->readData("data", parameterStr);
1157 file->closeGroup();
1158 } catch (Nexus::Exception const &ex) {
1159 g_log.debug(std::string("Unable to load instrument_parameter_map: ") + ex.what());
1160 g_log.information("Parameter map entry missing from NeXus file. Continuing without it.");
1161 }
1162}
1163
1170void ExperimentInfo::readParameterMap(const std::string &parameterStr) {
1172 auto &compInfo = mutableComponentInfo();
1173 auto &detInfo = mutableDetectorInfo();
1174 const auto parInstrument = getInstrument();
1175 const auto instr = parInstrument->baseInstrument();
1176
1179 Mantid::Kernel::StringTokenizer splitter(parameterStr, "|", options);
1180
1181 auto iend = splitter.end();
1182
1184 const std::string visibilityKey = "visible:"; // if visibility is defined, the value will follow this key
1185 // std::string prev_name;
1186 for (auto itr = splitter.begin(); itr != iend; ++itr) {
1187 tokens = Mantid::Kernel::StringTokenizer(*itr, ";");
1188 if (tokens.count() < 4)
1189 continue;
1190 std::string comp_name = tokens[0];
1191 // if( comp_name == prev_name ) continue; this blocks reading in different
1192 // parameters of the same component. RNT
1193 // prev_name = comp_name;
1194 const Geometry::IComponent *comp = nullptr;
1195 if (comp_name.find("detID:") != std::string::npos) {
1196 int detID = std::stoi(comp_name.substr(6));
1197 comp = instr->getDetector(detID).get();
1198 if (!comp) {
1199 g_log.warning() << "Cannot find detector " << detID << '\n';
1200 continue;
1201 }
1202 } else {
1203 comp = instr->getComponentByName(comp_name).get();
1204 if (!comp) {
1205 g_log.warning() << "Cannot find component " << comp_name << '\n';
1206 continue;
1207 }
1208 }
1209
1210 // create parameter's value as a sum of all tokens with index 3 or larger
1211 // this allow a parameter's value to contain ";"
1212 std::string paramValue = tokens[3];
1213 auto size = static_cast<int>(tokens.count());
1214 for (int i = 4; i < size; i++)
1215 paramValue += ";" + tokens[i];
1216 const auto &paramType = tokens[1];
1217 const auto &paramName = tokens[2];
1218 auto &paramVisibility = tokens[size - 1]; // parameter visibility, if defined, is the last token
1219 if (paramVisibility.find(visibilityKey) > paramVisibility.size())
1220 paramVisibility = "true"; // visibility not defined: default to visible
1221 else { // defined, the paramValue has one too many entries, -1 to remove also the semicolon
1222 paramVisibility =
1223 paramVisibility.substr(paramVisibility.find(visibilityKey) + visibilityKey.size(), paramVisibility.size());
1224 paramValue.erase(paramValue.find(visibilityKey) - 1, paramValue.size());
1225 }
1226 const auto paramDescr = std::string("");
1227 if (paramName == "masked") {
1228 auto value = getParam<bool>(paramType, paramValue);
1229 if (value) {
1230 // Do not add masking to ParameterMap, it is stored in DetectorInfo
1231 const auto componentIndex = compInfo.indexOf(comp->getComponentID());
1232 if (!compInfo.isDetector(componentIndex)) {
1233 throw std::runtime_error("Found masking for a non-detector "
1234 "component. This is not possible");
1235 } else
1236 detInfo.setMasked(componentIndex, value); // all detector indexes
1237 // have same component
1238 // index (guarantee)
1239 }
1240 } else if (isPositionParameter(paramName)) {
1241 // We are parsing a string obtained from a ParameterMap. The map may
1242 // contain posx, posy, and posz (in addition to pos). However, when these
1243 // component wise positions are set, 'pos' is updated accordingly. We are
1244 // thus ignoring position components below.
1245 const auto newRelPos = getParam<V3D>(paramType, paramValue);
1246 updatePosition(compInfo, comp, newRelPos);
1247 } else if (isRotationParameter(paramName)) {
1248 // We are parsing a string obtained from a ParameterMap. The map may
1249 // contain rotx, roty, and rotz (in addition to rot). However, when these
1250 // component wise rotations are set, 'rot' is updated accordingly. We are
1251 // thus ignoring rotation components below.
1252 const auto newRelRot = getParam<Quat>(paramType, paramValue);
1253 updateRotation(compInfo, comp, newRelRot);
1254 } else if (!isRedundantPosOrRot(paramName)) {
1255 // Special case RectangularDetector: Parameters scalex and scaley affect
1256 // pixel positions, but we must also add the parameter below.
1257 if (isScaleParameter(paramName))
1258 adjustPositionsFromScaleFactor(compInfo, comp, paramName, getParam<double>(paramType, paramValue));
1259 pmap.add(paramType, comp, paramName, paramValue, &paramDescr, paramVisibility);
1260 }
1261 }
1262}
1263
1275 Geometry::ParameterMap &paramMapForPosAndRot, const std::string &name,
1276 const Geometry::XMLInstrumentParameter &paramInfo, const Run &runData) {
1277 const std::string &category = paramInfo.m_type;
1278 ParameterValue paramValue(paramInfo,
1279 runData); // Defines implicit conversion operator
1280
1281 const std::string *pDescription = nullptr;
1282 if (!paramInfo.m_description.empty())
1283 pDescription = &paramInfo.m_description;
1284 std::string pVisible = "true";
1285 if (!paramInfo.m_visible.empty())
1286 pVisible = paramInfo.m_visible;
1287
1288 // Some names are special. Values should be convertible to double
1289 if (name == "masked") {
1290 bool value(paramValue);
1291 if (value) {
1292 // Do not add masking to ParameterMap, it is stored in DetectorInfo
1293
1294 const auto componentIndex = componentInfo().indexOf(paramInfo.m_component->getComponentID());
1295 if (!componentInfo().isDetector(componentIndex))
1296 throw std::runtime_error("Found masking for a non-detector component. This is not possible");
1297 mutableDetectorInfo().setMasked(componentIndex,
1298 paramValue); // all detector indexes have
1299 // same component index
1300 // (guarantee)
1301 }
1302 } else if (name == "x" || name == "y" || name == "z") {
1303 paramMapForPosAndRot.addPositionCoordinate(paramInfo.m_component, name, paramValue);
1304 } else if (name == "rot" || name == "rotx" || name == "roty" || name == "rotz") {
1305 // Effectively this is dropping any parameters named 'rot'.
1306 paramMapForPosAndRot.addRotationParam(paramInfo.m_component, name, paramValue, pDescription);
1307 } else if (category == "fitting") {
1308 std::ostringstream str;
1309 str << paramInfo.m_value << " , " << paramInfo.m_fittingFunction << " , " << name << " , "
1310 << paramInfo.m_constraint[0] << " , " << paramInfo.m_constraint[1] << " , " << paramInfo.m_penaltyFactor
1311 << " , " << paramInfo.m_tie << " , " << paramInfo.m_formula << " , " << paramInfo.m_formulaUnit << " , "
1312 << paramInfo.m_resultUnit << " , " << (*(paramInfo.m_interpolation));
1313 paramMap.add("fitting", paramInfo.m_component, name, str.str(), pDescription, pVisible);
1314 } else if (category == "string") {
1315 paramMap.addString(paramInfo.m_component, name, paramInfo.m_value, pDescription, pVisible);
1316 } else if (category == "bool") {
1317 paramMap.addBool(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1318 } else if (category == "int") {
1319 paramMap.addInt(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1320 } else { // assume double
1321 paramMap.addDouble(paramInfo.m_component, name, paramValue, pDescription, pVisible);
1322 }
1323}
1324
1326 // The default implementation does nothing. Used by subclasses
1327 // (FileBackedExperimentInfo) to load content from files upon access.
1328}
1329
1330} // namespace Mantid::API
1331
1332namespace Mantid::Kernel {
1333
1334template <>
1336IPropertyManager::getValue<Mantid::API::ExperimentInfo_sptr>(const std::string &name) const {
1337 auto *prop = dynamic_cast<PropertyWithValue<Mantid::API::ExperimentInfo_sptr> *>(getPointerToProperty(name));
1338 if (prop) {
1339 return *prop;
1340 } else {
1341 std::string message =
1342 "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<ExperimentInfo>.";
1343 throw std::runtime_error(message);
1344 }
1345}
1346
1347template <>
1349IPropertyManager::getValue<Mantid::API::ExperimentInfo_const_sptr>(const std::string &name) const {
1350 auto const *prop = dynamic_cast<PropertyWithValue<Mantid::API::ExperimentInfo_sptr> *>(getPointerToProperty(name));
1351 if (prop) {
1352 return prop->operator()();
1353 } else {
1354 std::string message =
1355 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<ExperimentInfo>.";
1356 throw std::runtime_error(message);
1357 }
1358}
1359
1360} // 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 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