ATLAS Offline Software
Loading...
Searching...
No Matches
ParameterSpace.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4// ParameterSpace.cxx
5// TopoCore
6// Created by Joerg Stelzer on 11/18/12.
7
10
11using namespace std;
12using namespace TCS;
13
14
16ParameterSpace::addParameter(const std::string & name, TCS::parType_t value) {
17 return addParameter( Parameter(name, value));
18}
19
20
22ParameterSpace::addParameter(const std::string & name, TCS::parType_t value, unsigned int selection) {
23 return addParameter( Parameter(name, value, selection));
24}
25
26
27// adds a new Parameter, throws TCS::Exception if parameter exists isDefault flag will be set to true
30 if( contains(p.name(), p.selection()) ) {
31 TCS_EXCEPTION("ParameterSpace: parameter '" << p.name() << "|" << p.selection() <<
32 "' exists already in parameter space of '" << algName() << "' and can't be added");
33 }
34 m_parameters.push_back(p);
35 m_parameters.back().setIsDefault(true);
36 return *this;
37}
38
39
41ParameterSpace::setParameter(const std::string & name, TCS::parType_t value, unsigned int selection) {
42 return setParameter(Parameter(name, value, selection));
43}
44
45
46// sets a parameter value, throws TCS::Exception if parameter doesn't exist
47// sets isDefault flag to false
50
51 bool foundParameter = false;
52
53 //cout << "Setting parameter " << p.name() << "[" << p.selection() << "] for algorithm " << algName() << endl;
54
55 for(TCS::Parameter& pa : m_parameters) {
56 foundParameter =
57 ( !pa.isExtended() && pa.name()==p.name() ) ||
58 ( pa.isExtended() && pa.name()==p.name() && pa.selection()==p.selection() );
59
60 if(! foundParameter) continue;
61
62 if( pa.isExtended() ) {
63 pa.setValue(p.value());
64 pa.setPosition(p.position());
65 pa.setSelection(p.selection());
66 pa.setIsExtended(true); // for parameters to print correctly
67 } else {
68 pa.setValue(p.value());
69 pa.setIsExtended(false);
70 }
71 pa.setIsDefault(false);
72 break;
73 }
74
75 if( ! foundParameter ) {
76 cout << "Parameter '" << p.name() << "' not found for algorithm " << algName()
77 << " and can't be set. Available parameters are" << endl;
78
79 for(TCS::Parameter& pa : m_parameters) {
80 cout << " " << pa.name() << " " << (pa.isExtended()?"array":"single") << endl;
81 }
82 TCS_EXCEPTION( "Parameter '" << p.name() << "' not found for algorithm " << algName() << " and can't be set." );
83 }
84 return *this;
85}
86
87
88
89
90
91bool
92ParameterSpace::contains(const std::string & parameterName, unsigned int selection) const {
93 for(const Parameter& pa: m_parameters)
94 if( (pa.name() == parameterName) && (pa.selection() == selection) ) return true;
95 return false;
96}
97
98
99
100const Parameter &
101ParameterSpace::parameter(const std::string & parameterName) const {
102 for(const Parameter & pa : m_parameters) {
103 if( pa.isExtended() ) continue;
104 if( pa.name() == parameterName )
105 return pa;
106 }
107
108 TCS_EXCEPTION("Single parameter " << parameterName << " not found for algorithm " << algName());
109 return m_parameters[0]; // doesn't make sense, but should never get here
110}
111
112
113const Parameter &
114ParameterSpace::parameter(const std::string & parameterName, unsigned int selection) const {
115 for(const Parameter & pa : m_parameters) {
116 if( ! pa.isExtended() ) continue;
117 if( (pa.name() == parameterName) && (pa.selection() == selection) )
118 return pa;
119 }
120
121 TCS_EXCEPTION("Array parameter " << parameterName << "[" << selection << "] not found for algorithm " << algName());
122 return m_parameters[0]; // doesn't make sense, but should never get here
123}
124
125
126namespace TCS {
127
128
129std::ostream &
130operator<<(std::ostream &o, const TCS::ParameterSpace & ps) {
131 if( ps.isInitialized()) {
132 o << " parameters: " << ps().size();
133 for(const TCS::Parameter& parameter : ps) {
134 o << endl << " " << parameter;
135 }
136 }
137 return o;
138}
139
140
141}
const Parameter & parameter(const std::string &parameterName) const
bool contains(const std::string &parameterName, unsigned int selection) const
ParameterSpace & setParameter(const Parameter &p)
const std::string & algName() const
ParameterSpace & addParameter(const Parameter &p)
const std::string selection
std::ostream & operator<<(std::ostream &os, const TCS::Bin &bin)
uint32_t parType_t
Definition Parameter.h:22
STL namespace.