MarlinMT  0.1.0
RunHeader.h
Go to the documentation of this file.
1 #pragma once
2 
3 // -- std headers
4 #include <string>
5 #include <map>
6 
7 // -- marlinmt headers
8 #include <marlinmt/Extensions.h>
9 #include <marlinmt/Utils.h>
10 
11 namespace marlinmt {
12 
22  class RunHeader {
23  using ParameterMap = std::map<std::string, std::string> ;
24 
25  public:
26  RunHeader() = default ;
27  ~RunHeader() = default ;
28  RunHeader(const RunHeader &) = delete ;
29  RunHeader &operator=(const RunHeader &) = delete ;
30  RunHeader(RunHeader &&) = default ;
31  RunHeader &operator=(RunHeader &&) = default ;
32 
36  int runNumber() const ;
37 
43  RunHeader &setRunNumber( int n ) ;
44 
48  const std::string &description() const ;
49 
55  RunHeader &setDescription( const std::string &desc ) ;
56 
60  const std::string &detectorName() const ;
61 
67  RunHeader &setDetectorName( const std::string &det ) ;
68 
72  const ParameterMap &parameters() const ;
73 
78 
84  template <typename T>
85  std::optional<T> parameter( const std::string &name ) const ;
86 
94  template <typename T>
95  RunHeader &setParameter( const std::string &name, const T &value ) ;
96 
101 
105  const Extensions &extensions() const ;
106 
107  private:
109  int _runNumber {0} ;
111  std::string _detectorName {} ;
113  std::string _description {} ;
118  };
119 
120  //--------------------------------------------------------------------------
121  //--------------------------------------------------------------------------
122 
123  inline int RunHeader::runNumber() const {
124  return _runNumber ;
125  }
126 
127  //--------------------------------------------------------------------------
128 
130  _runNumber = n ;
131  return *this ;
132  }
133 
134  //--------------------------------------------------------------------------
135 
136  inline const std::string &RunHeader::description() const {
137  return _description ;
138  }
139 
140  //--------------------------------------------------------------------------
141 
142  inline RunHeader &RunHeader::setDescription( const std::string &desc ) {
143  _description = desc ;
144  return *this ;
145  }
146 
147  //--------------------------------------------------------------------------
148 
149  inline const std::string &RunHeader::detectorName() const {
150  return _detectorName ;
151  }
152 
153  //--------------------------------------------------------------------------
154 
155  inline RunHeader &RunHeader::setDetectorName( const std::string &det ) {
156  _detectorName = det ;
157  return *this ;
158  }
159 
160  //--------------------------------------------------------------------------
161 
163  return _parameters ;
164  }
165 
166  //--------------------------------------------------------------------------
167 
169  return _parameters ;
170  }
171 
172  //--------------------------------------------------------------------------
173 
174  template <typename T>
175  inline std::optional<T> RunHeader::parameter( const std::string &name ) const {
176  auto iter = _parameters.find( name ) ;
177  if( _parameters.end() != iter ) {
178  return details::convert<T>::from_string( iter->second ) ;
179  }
180  return std::nullopt ;
181  }
182 
183  //--------------------------------------------------------------------------
184 
185  template <typename T>
186  inline RunHeader &RunHeader::setParameter( const std::string &name, const T &value ) {
188  return *this ;
189  }
190 
191  //--------------------------------------------------------------------------
192 
194  return _extensions ;
195  }
196 
197  //--------------------------------------------------------------------------
198 
199  inline const Extensions &RunHeader::extensions() const {
200  return _extensions ;
201  }
202 
203 }
RunHeader & setRunNumber(int n)
Set the run number.
Definition: RunHeader.h:129
const ParameterMap & parameters() const
Get the run parameters.
Definition: RunHeader.h:162
ParameterMap _parameters
The run parameters map.
Definition: RunHeader.h:115
RunHeader & setDetectorName(const std::string &det)
Set the detector name.
Definition: RunHeader.h:155
Extensions & extensions()
Get the run extensions.
Definition: RunHeader.h:193
RunHeader & setDescription(const std::string &desc)
Set the run description.
Definition: RunHeader.h:142
Extensions class.
Definition: Extensions.h:71
constexpr unsigned long long value(const Flag_t &flag)
Definition: Flags.h:106
Extensions _extensions
The run extensions.
Definition: RunHeader.h:117
std::string _detectorName
The detector name.
Definition: RunHeader.h:111
static T from_string(const std::string &str)
Definition: Utils.h:378
std::map< std::string, std::string > ParameterMap
Definition: RunHeader.h:23
const std::string & detectorName() const
Get the detector name.
Definition: RunHeader.h:149
std::optional< T > parameter(const std::string &name) const
Get a parameter by name.
Definition: RunHeader.h:175
std::string _description
The run description.
Definition: RunHeader.h:113
static std::string to_string(const T &value)
Definition: Utils.h:370
RunHeader class.
Definition: RunHeader.h:22
int _runNumber
The run number.
Definition: RunHeader.h:109
RunHeader & operator=(const RunHeader &)=delete
const std::string & description() const
Get the run description.
Definition: RunHeader.h:136
int runNumber() const
Get the run number.
Definition: RunHeader.h:123
RunHeader & setParameter(const std::string &name, const T &value)
Set a run parameter.
Definition: RunHeader.h:186