Mantid
Loading...
Searching...
No Matches
SampleEnvironmentSpec.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9namespace Mantid::DataHandling {
10
15SampleEnvironmentSpec::SampleEnvironmentSpec(std::string name) : m_name(std::move(name)), m_cans(), m_components() {}
16
24 // if there's only one can and an id wasn't specified then return it
25 if ((m_cans.size() == 1) && (id.empty())) {
26 return m_cans.begin()->second;
27 } else {
28
29 auto indexIter = m_cans.find(id);
30 if (indexIter != m_cans.end())
31 return indexIter->second;
32 else
33 throw std::invalid_argument("SampleEnvironmentSpec::find() - Unable to "
34 "find Container matching ID '" +
35 id + "'");
36 }
37}
38
44 auto env = std::make_unique<Geometry::SampleEnvironment>(m_name, findContainer(canID));
45 for (const auto &component : m_components) {
46 env->add(component);
47 }
48 return env;
49}
50
57 if (can->id().empty()) {
58 throw std::invalid_argument("SampleEnvironmentSpec::addContainer() - Container must "
59 "have an id field. Empty string found.");
60 }
61 m_cans.emplace(can->id(), can);
62}
63
69 m_components.emplace_back(component);
70}
71
72} // namespace Mantid::DataHandling
SampleEnvironmentSpec(std::string name)
Constructor.
void addContainer(const Geometry::Container_const_sptr &can)
Adds a can definition to the known list.
Geometry::SampleEnvironment_uptr buildEnvironment(const std::string &canID) const
Build a new SampleEnvironment instance from a given can ID.
void addComponent(const Geometry::IObject_const_sptr &component)
Add a non-can component to the specification.
Geometry::Container_const_sptr findContainer(const std::string &id) const
Find a can by id string.
std::shared_ptr< const Container > Container_const_sptr
Typdef for a shared pointer to a const object.
Definition: Container.h:107
std::unique_ptr< SampleEnvironment > SampleEnvironment_uptr
std::shared_ptr< const IObject > IObject_const_sptr
Typdef for a shared pointer to a const object.
Definition: IObject.h:94
STL namespace.