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