ATLAS Offline Software
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 
11 using namespace std;
12 using namespace TCS;
13 
14 
16 ParameterSpace::addParameter(const std::string & name, TCS::parType_t value) {
17  return addParameter( Parameter(name, value));
18 }
19 
20 
22 ParameterSpace::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
29 ParameterSpace::addParameter(const TCS::Parameter& p) {
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 
41 ParameterSpace::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
49 ParameterSpace::setParameter(const Parameter & p) {
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 
91 bool
92 ParameterSpace::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 
100 const Parameter &
101 ParameterSpace::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 
113 const Parameter &
114 ParameterSpace::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 
126 namespace TCS {
127 
128 
129 std::ostream &
130 operator<<(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 }
ParameterSpace.h
TCS::Parameter
Definition: Parameter.h:24
TCS::parType_t
uint32_t parType_t
Definition: Parameter.h:22
xAOD::JetAlgorithmType::algName
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.
Definition: JetContainerInfo.cxx:67
athena.value
value
Definition: athena.py:124
TCS::ParameterSpace
Definition: ParameterSpace.h:18
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
selection
std::string selection
Definition: fbtTestBasics.cxx:75
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TCS::ParameterSpace::isInitialized
bool isInitialized() const
Definition: ParameterSpace.h:34
operator<<
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Definition: TestGaudiProperty.cxx:69
TCS
Definition: Global/GlobalSimulation/src/IO/Decision.h:18
Exception.h