Belle II Software light-2406-ragdoll
Interface.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/FrameworkExceptions.h>
12#include <framework/gearbox/Unit.h>
13
14#include <string>
15
16class TObject;
17
18namespace Belle2 {
24 class GearDir;
25
26 namespace gearbox {
28 BELLE2_DEFINE_EXCEPTION(PathEmptyError, "Path '%1%' does not exist or is empty")
30 BELLE2_DEFINE_EXCEPTION(ConversionError, "Path '%1%': Could not convert '%2%' to numerical value")
32 BELLE2_DEFINE_EXCEPTION(TObjectConversionError, "Path '%1%': Could not convert to TObject! Malformed data?")
33
35 class Interface {
36 public:
37
39 Interface(): m_path("/") {}
40
42 virtual ~Interface() {}
43
48 virtual int getNumberNodes(const std::string& path = "") const = 0;
49
54 bool exists(const std::string& path = "") const { return getNumberNodes(path) > 0; }
55
60 operator bool() const { return exists(); }
61
62
67 std::vector<GearDir> getNodes(const std::string& path = "") const;
68
70 std::string getPath() const { return m_path; }
71
78 virtual std::string getString(const std::string& path = "") const noexcept(false) = 0;
79
91 virtual std::pair<std::string, std::string> getStringWithUnit(const std::string& path) const noexcept(false) = 0;
92
101 std::string getString(const std::string& path, const std::string& defaultValue) const;
102
112 virtual const TObject* getTObject(const std::string& path) const noexcept(false) = 0;
113
121 double getDouble(const std::string& path = "") const noexcept(false);
122
132 double getDouble(const std::string& path, double defaultValue) const noexcept(false);
133
141 int getInt(const std::string& path = "") const noexcept(false);
142
152 int getInt(const std::string& path, int defaultValue) const noexcept(false);
153
160 bool getBool(const std::string& path = "") const noexcept(false);
161
170 bool getBool(const std::string& path, bool defaultValue) const;
171
185 double getWithUnit(const std::string& path) const noexcept(false);
186
203 double getWithUnit(const std::string& path, double defaultValue) const noexcept(false);
204
222 std::vector<double> getArray(const std::string& path) const noexcept(false);
223
243 std::vector<double> getArray(const std::string& path, const std::vector<double>& defaultValue) const noexcept(false);
244
245
259 double getLength(const std::string& path = "") const noexcept(false)
260 {
261 return getWithUnit(path);
262 }
263
281 double getLength(const std::string& path, double defaultValue) const noexcept(false)
282 {
283 return getWithUnit(path, defaultValue);
284 }
285
299 double getAngle(const std::string& path = "") const noexcept(false)
300 {
301 return getWithUnit(path);
302 }
303
321 double getAngle(const std::string& path, double defaultValue) const noexcept(false)
322 {
323 return getWithUnit(path, defaultValue);
324 }
325
339 double getEnergy(const std::string& path = "") const noexcept(false)
340 {
341 return getWithUnit(path);
342 }
343
361 double getEnergy(const std::string& path, double defaultValue) const noexcept(false)
362 {
363 return getWithUnit(path, defaultValue);
364 }
365
379 double getDensity(const std::string& path = "") const noexcept(false)
380 {
381 return getWithUnit(path);
382 }
383
401 double getDensity(const std::string& path, double defaultValue) const noexcept(false)
402 {
403 return getWithUnit(path, defaultValue);
404 }
405
419 double getTime(const std::string& path = "") const noexcept(false)
420 {
421 return getWithUnit(path);
422 }
423
441 double getTime(const std::string& path, double defaultValue) const noexcept(false)
442 {
443 return getWithUnit(path, defaultValue);
444 }
445
459 double getFrequency(const std::string& path = "") const noexcept(false)
460 {
461 return getWithUnit(path);
462 }
463
481 double getFrequency(const std::string& path, double defaultValue) const noexcept(false)
482 {
483 return getWithUnit(path, defaultValue);
484 }
485
486 protected:
487
489 std::string ensureNode(const std::string& path) const ;
491 std::string ensurePath(const std::string& path) const;
493 std::string addIndex(const std::string& path, int index) const;
495 std::string joinPath(const std::string& path, const std::string& subpath) const;
496
498 std::string m_path;
499
500 };
501 }
503}
Exception to be thrown in case of an empty result.
Definition: Interface.h:35
double getDensity(const std::string &path, double defaultValue) const noexcept(false)
Get the parameter path as a double converted to the standard density unit.
Definition: Interface.h:401
double getAngle(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard angle unit.
Definition: Interface.h:299
double getTime(const std::string &path, double defaultValue) const noexcept(false)
Get the parameter path as a double converted to the standard time unit.
Definition: Interface.h:441
Interface()
default constructor initializing to toplevel parameter space
Definition: Interface.h:39
double getDensity(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard density unit.
Definition: Interface.h:379
virtual std::string getString(const std::string &path="") const noexcept(false)=0
Get the parameter path as a string.
double getFrequency(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard frequency unit.
Definition: Interface.h:459
double getTime(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard time unit.
Definition: Interface.h:419
double getLength(const std::string &path, double defaultValue) const noexcept(false)
Get the parameter path as a double converted to the standard length unit.
Definition: Interface.h:281
double getEnergy(const std::string &path, double defaultValue) const noexcept(false)
Get the parameter path as a double converted to the standard energy unit.
Definition: Interface.h:361
std::string getPath() const
Return path of the current interface.
Definition: Interface.h:70
bool exists(const std::string &path="") const
Check if a given parameter path exists.
Definition: Interface.h:54
double getEnergy(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard energy unit.
Definition: Interface.h:339
std::string m_path
path of the current interface
Definition: Interface.h:498
virtual ~Interface()
empty, virtual destructor
Definition: Interface.h:42
virtual int getNumberNodes(const std::string &path="") const =0
Return the number of nodes a given path will expand to.
double getFrequency(const std::string &path, double defaultValue) const noexcept(false)
Get the parameter path as a double converted to the standard frequency unit.
Definition: Interface.h:481
double getAngle(const std::string &path, double defaultValue) const noexcept(false)
Get the parameter path as a double converted to the standard angle unit.
Definition: Interface.h:321
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.