30bool matchesNamedType(Parameter
const ¶meter, std::string
const &type) {
31 return type.empty() || parameter.type() == type;
37bool matchesType(Parameter
const ¶meter, std::string
const &type) {
38 Kernel::CaseInsensitiveStringComparator
const less;
39 return !less(parameter.type(), type) && !less(type, parameter.type());
43void ParameterInfo::add(
size_t const componentIndex, std::shared_ptr<Parameter>
const ¶meter) {
47 auto &componentParameters =
m_store[componentIndex];
50 auto const existing = componentParameters.find(parameter->name());
51 if (existing != componentParameters.end()) {
52 existing->second = parameter;
54 componentParameters.emplace(parameter->name(), parameter);
59 std::string
const &fittingFunction) {
63 auto &componentParameters =
m_store[componentIndex];
66 auto const range = componentParameters.equal_range(parameter->name());
67 for (
auto it = range.first; it != range.second; ++it) {
68 if (it->second->type() !=
"fitting") {
73 it->second = parameter;
80 componentParameters.emplace(parameter->name(), parameter);
88 m_store[componentIndex].emplace(parameter->name(), parameter);
92 return static_cast<bool>(
get(componentIndex,
name, type));
96 std::string
const &type)
const {
97 std::shared_ptr<Parameter> result;
98 auto const component =
m_store.find(componentIndex);
99 if (component !=
m_store.end()) {
100 auto const range = component->second.equal_range(
name);
101 for (
auto it = range.first; it != range.second; ++it) {
102 if (matchesNamedType(*it->second, type)) {
112 std::shared_ptr<Parameter> result;
113 auto const component =
m_store.find(componentIndex);
114 if (component !=
m_store.end()) {
115 for (
auto const &[
name, parameter] : component->second) {
116 static_cast<void>(
name);
117 if (matchesType(*parameter, type)) {
127 std::string
const &
name, std::string
const &type)
const {
128 std::shared_ptr<Parameter> result;
129 for (
size_t index = componentIndex;;) {
140 size_t const componentIndex,
141 std::string
const &type)
const {
142 std::shared_ptr<Parameter> result;
143 for (
size_t index = componentIndex;;) {
154 size_t const componentIndex,
155 std::string
const &
name,
156 std::string
const &fittingFunction)
const {
157 std::shared_ptr<Parameter> result;
158 for (
size_t index = componentIndex;;) {
160 if (component !=
m_store.end()) {
161 auto const range = component->second.equal_range(
name);
162 for (
auto it = range.first; it != range.second; ++it) {
163 if (it->second->type() !=
"fitting") {
185 std::set<std::string> result;
186 auto const component =
m_store.find(componentIndex);
187 if (component !=
m_store.end()) {
188 for (
auto const &[
name, parameter] : component->second) {
189 static_cast<void>(parameter);
197 auto const component =
m_store.find(componentIndex);
198 return component ==
m_store.end() ? emptyParameters() : component->second;
212 auto const range = parameters.equal_range(
name);
213 for (
auto it = range.first; it != range.second;) {
214 if (it->second && it->second->name() ==
name) {
215 it = parameters.erase(it);
226 for (
auto component =
m_store.begin(); component !=
m_store.end();) {
227 eraseExactName(component->second,
name);
229 if (component->second.empty()) {
230 component =
m_store.erase(component);
238 auto const component =
m_store.find(componentIndex);
239 if (component !=
m_store.end()) {
240 eraseExactName(component->second,
name);
241 if (component->second.empty()) {
252 return std::accumulate(
m_store.cbegin(),
m_store.cend(),
size_t{0},
253 [](
size_t acc,
auto const &component) { return acc + component.second.size(); });
258 size_t parameterObjectsMem = 0;
259 for (
auto const &[componentIndex, componentParameters] :
m_store) {
260 static_cast<void>(componentIndex);
262 storeMem +=
sizeof(
decltype(
m_store)::value_type) + 4 *
sizeof(
void *);
263 for (
auto const &[
name, parameter] : componentParameters) {
265 storeMem +=
sizeof(ComponentParameters::value_type) + 4 *
sizeof(
void *) +
name.capacity();
267 parameterObjectsMem +=
sizeof(
Parameter) + parameter->m_name.capacity() + parameter->m_type.capacity() +
268 parameter->m_str_value.capacity() + parameter->m_description.capacity();
272 return sizeof(*this) + storeMem + parameterObjectsMem;
std::map< DeltaEMode::Type, std::string > index
ComponentInfo : Provides a component centric view on to the instrument.
bool hasParent(const size_t componentIndex) const
size_t parent(const size_t componentIndex) const
Store information about a fitting parameter such as its value if it is constrained or tied.
const std::string & getFunction() const
get function
void insert(size_t const componentIndex, std::shared_ptr< Parameter > const ¶meter)
Insert a parameter without add()'s add-or-replace deduplication.
size_t size() const
The total number of parameters across all components.
std::shared_ptr< Parameter > getByType(size_t const componentIndex, std::string const &type) const
The first parameter of this type on this component, or a null shared pointer.
std::set< std::string > names(size_t const componentIndex) const
The names of the parameters on this component.
bool addFittingParameter(size_t const componentIndex, std::shared_ptr< Parameter > const ¶meter, std::string const &fittingFunction)
Add a fitting parameter, deduplicating by (name, function) rather than by name alone so that two func...
ComponentParameters const & parameters(size_t const componentIndex) const
All parameters on one component, non-recursive, ordered by name.
std::shared_ptr< Parameter > get(size_t const componentIndex, std::string const &name, std::string const &type="") const
The named parameter on this component, or a null shared pointer if there is none.
void clearParametersByName(std::string const &name)
Remove every parameter of this name from every component.
void clear()
Remove all parameters.
bool contains(size_t const componentIndex, std::string const &name, std::string const &type="") const
Does a parameter of this name (and optionally this type) exist on this component?
void add(size_t const componentIndex, std::shared_ptr< Parameter > const ¶meter)
Add a parameter, replacing any existing parameter of the same name on the same component.
size_t getMemorySize() const
std::shared_ptr< Parameter > getRecursiveFittingParameter(ComponentInfo const &componentInfo, size_t const componentIndex, std::string const &name, std::string const &fittingFunction) const
Find a fitting parameter by (short name, function) walking up the component hierarchy.
std::multimap< std::string, std::shared_ptr< Parameter >, Kernel::CaseInsensitiveStringComparator > ComponentParameters
Parameters of a single component, ordered by name.
std::shared_ptr< Parameter > getRecursive(ComponentInfo const &componentInfo, size_t const componentIndex, std::string const &name, std::string const &type="") const
As get(), but walking up the component hierarchy until a match is found.
std::map< size_t, ComponentParameters > m_store
std::shared_ptr< Parameter > getRecursiveByType(ComponentInfo const &componentInfo, size_t const componentIndex, std::string const &type) const
As getByType(), but walking up the component hierarchy until a match is found.
Base class for parameters of an instrument.