Belle II Software  release-05-02-19
Interface.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/FrameworkExceptions.h>
14 #include <framework/gearbox/Unit.h>
15 
16 #include <string>
17 
18 class TObject;
19 
20 namespace Belle2 {
26  class GearDir;
27 
28  namespace gearbox {
30  BELLE2_DEFINE_EXCEPTION(PathEmptyError, "Path '%1%' does not exist or is empty")
32  BELLE2_DEFINE_EXCEPTION(ConversionError, "Path '%1%': Could not convert '%2%' to numerical value")
34  BELLE2_DEFINE_EXCEPTION(TObjectConversionError, "Path '%1%': Could not convert to TObject! Malformed data?")
35 
37  class Interface {
38  public:
39 
41  Interface(): m_path("/") {}
42 
44  virtual ~Interface() {}
45 
50  virtual int getNumberNodes(const std::string& path = "") const = 0;
51 
56  bool exists(const std::string& path = "") const { return getNumberNodes(path) > 0; }
57 
62  operator bool() const { return exists(); }
63 
64 
69  std::vector<GearDir> getNodes(const std::string& path = "") const;
70 
72  std::string getPath() const { return m_path; }
73 
80  virtual std::string getString(const std::string& path = "") const noexcept(false) = 0;
81 
93  virtual std::pair<std::string, std::string> getStringWithUnit(const std::string& path) const noexcept(false) = 0;
94 
103  std::string getString(const std::string& path, const std::string& defaultValue) const;
104 
114  virtual const TObject* getTObject(const std::string& path) const noexcept(false) = 0;
115 
123  double getDouble(const std::string& path = "") const noexcept(false);
124 
134  double getDouble(const std::string& path, double defaultValue) const noexcept(false);
135 
143  int getInt(const std::string& path = "") const noexcept(false);
144 
154  int getInt(const std::string& path, int defaultValue) const noexcept(false);
155 
162  bool getBool(const std::string& path = "") const noexcept(false);
163 
172  bool getBool(const std::string& path, bool defaultValue) const;
173 
187  double getWithUnit(const std::string& path) const noexcept(false);
188 
205  double getWithUnit(const std::string& path, double defaultValue) const noexcept(false);
206 
224  std::vector<double> getArray(const std::string& path) const noexcept(false);
225 
245  std::vector<double> getArray(const std::string& path, const std::vector<double>& defaultValue) const noexcept(false);
246 
247 
261  double getLength(const std::string& path = "") const noexcept(false)
262  {
263  return getWithUnit(path);
264  }
265 
283  double getLength(const std::string& path, double defaultValue) const noexcept(false)
284  {
285  return getWithUnit(path, defaultValue);
286  }
287 
301  double getAngle(const std::string& path = "") const noexcept(false)
302  {
303  return getWithUnit(path);
304  }
305 
323  double getAngle(const std::string& path, double defaultValue) const noexcept(false)
324  {
325  return getWithUnit(path, defaultValue);
326  }
327 
341  double getEnergy(const std::string& path = "") const noexcept(false)
342  {
343  return getWithUnit(path);
344  }
345 
363  double getEnergy(const std::string& path, double defaultValue) const noexcept(false)
364  {
365  return getWithUnit(path, defaultValue);
366  }
367 
381  double getDensity(const std::string& path = "") const noexcept(false)
382  {
383  return getWithUnit(path);
384  }
385 
403  double getDensity(const std::string& path, double defaultValue) const noexcept(false)
404  {
405  return getWithUnit(path, defaultValue);
406  }
407 
421  double getTime(const std::string& path = "") const noexcept(false)
422  {
423  return getWithUnit(path);
424  }
425 
443  double getTime(const std::string& path, double defaultValue) const noexcept(false)
444  {
445  return getWithUnit(path, defaultValue);
446  }
447 
461  double getFrequency(const std::string& path = "") const noexcept(false)
462  {
463  return getWithUnit(path);
464  }
465 
483  double getFrequency(const std::string& path, double defaultValue) const noexcept(false)
484  {
485  return getWithUnit(path, defaultValue);
486  }
487 
488  protected:
489 
491  std::string ensureNode(const std::string& path) const ;
493  std::string ensurePath(const std::string& path) const;
495  std::string addIndex(const std::string& path, int index) const;
497  std::string joinPath(const std::string& path, const std::string& subpath) const;
498 
500  std::string m_path;
501 
502  };
503  }
505 }
Belle2::gearbox::Interface::getAngle
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:301
Belle2::gearbox::Interface::getTime
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:421
Belle2::gearbox::Interface::getDensity
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:381
Belle2::gearbox::Interface::getFrequency
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:483
Belle2::gearbox::Interface::~Interface
virtual ~Interface()
empty, virtual destructor
Definition: Interface.h:44
Belle2::gearbox::Interface::getTime
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:443
Belle2::gearbox::Interface::getPath
std::string getPath() const
Return path of the current interface.
Definition: Interface.h:72
Belle2::gearbox::Interface::exists
bool exists(const std::string &path="") const
Check if a given parameter path exists.
Definition: Interface.h:56
Belle2::gearbox::Interface::getAngle
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:323
Belle2::gearbox::Interface::getFrequency
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:461
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::gearbox::Interface::getLength
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:283
Belle2::gearbox::Interface::getDensity
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:403
Belle2::gearbox::Interface::getEnergy
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:341
Belle2::gearbox::Interface
Exception to be thrown in case of an empty result.
Definition: Interface.h:37
BELLE2_DEFINE_EXCEPTION
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Definition: FrameworkExceptions.h:46
Belle2::gearbox::Interface::Interface
Interface()
default constructor initializing to toplevel parameter space
Definition: Interface.h:41
Belle2::gearbox::Interface::getEnergy
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:363
Belle2::gearbox::Interface::m_path
std::string m_path
path of the current interface
Definition: Interface.h:500