R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BFormatters.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2023 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#pragma once
15
16#include "R3BShared.h"
17#include "R3BValueError.h"
18#include <Math/Vector3Dfwd.h>
19#include <TVector3.h>
20#include <fmt/base.h>
21#include <fmt/core.h>
22#include <fmt/format.h>
23
24// NOLINTNEXTLINE(misc-include-cleaner)
25#include <Math/Vector3D.h>
26
27template <>
28class fmt::formatter<TVector3>
29{
30 public:
31 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
32 template <typename FmtContent>
33 constexpr auto format(const TVector3& vec, FmtContent& ctn) const
34 {
35 return fmt::format_to(ctn.out(), "[x: {}, y: {}, z: {}]", vec.X(), vec.Y(), vec.Z());
36 }
37};
38
39template <typename DataType>
40class fmt::formatter<R3B::ValueError<DataType>>
41{
42 public:
43 // TODO: add more options
44 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
45 template <typename FmtContent>
46 constexpr auto format(const R3B::ValueError<DataType>& value_error, FmtContent& ctn) const
47 {
48 return fmt::format_to(ctn.out(), "{}+/-{}", value_error.value, value_error.error);
49 }
50};
51
52template <>
53class fmt::formatter<ROOT::Math::XYZVector>
54{
55 public:
56 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
57 template <typename FmtContent>
58 constexpr auto format(const ROOT::Math::XYZVector& vec, FmtContent& ctn) const
59 {
60 return fmt::format_to(ctn.out(), "[x: {}, y: {}, z: {}]", vec.X(), vec.Y(), vec.Z());
61 }
62};
63
64template <typename DataType>
65class fmt::formatter<R3B::LRPair<DataType>>
66{
67 public:
68 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
69 template <typename FmtContent>
70 constexpr auto format(const R3B::LRPair<DataType>& data_pair, FmtContent& ctn) const
71 {
72 return fmt::format_to(ctn.out(), "[left: {}, right: {}]", data_pair.left(), data_pair.right());
73 }
74};
75
76template <>
77class fmt::formatter<R3B::Side>
78{
79 public:
80 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
81 template <typename FmtContent>
82 constexpr auto format(const R3B::Side& side, FmtContent& ctn) const
83 {
84 if (side == R3B::Side::left)
85 {
86 return fmt::format_to(ctn.out(), "{}", "left");
87 }
88 return fmt::format_to(ctn.out(), "{}", "right");
89 }
90};
Side
Definition R3BShared.h:112
auto left() -> DataType &
Definition R3BShared.h:149
auto right() -> DataType &
Definition R3BShared.h:150
constexpr auto format(const R3B::LRPair< DataType > &data_pair, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)
constexpr auto format(const R3B::Side &side, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)
constexpr auto format(const R3B::ValueError< DataType > &value_error, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)
static constexpr auto parse(format_parse_context &ctx)
constexpr auto format(const ROOT::Math::XYZVector &vec, FmtContent &ctn) const
constexpr auto format(const TVector3 &vec, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)