|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +#ifndef O2_BASE_DATA_HEADER_HELPERS_ |
| 12 | +#define O2_BASE_DATA_HEADER_HELPERS_ |
| 13 | + |
| 14 | +#include "Headers/DataHeader.h" |
| 15 | +#include <fmt/format.h> |
| 16 | + |
| 17 | +template <typename T> |
| 18 | +struct fmt::formatter<T, std::enable_if_t<o2::header::is_descriptor<T>::value, char>> { |
| 19 | + // Presentation format: 'f' - fixed, 'e' - exponential. |
| 20 | + char presentation = 's'; |
| 21 | + |
| 22 | + // Parses format specifications of the form ['f' | 'e']. |
| 23 | + constexpr auto parse(format_parse_context& ctx) |
| 24 | + { |
| 25 | + auto it = ctx.begin(), end = ctx.end(); |
| 26 | + if (it != end && (*it == 's')) { |
| 27 | + presentation = *it++; |
| 28 | + } |
| 29 | + |
| 30 | + // Check if reached the end of the range: |
| 31 | + if (it != end && *it != '}') { |
| 32 | + throw format_error("invalid pick format"); |
| 33 | + } |
| 34 | + |
| 35 | + // Return an iterator past the end of the parsed range: |
| 36 | + return it; |
| 37 | + } |
| 38 | + |
| 39 | + template <typename FormatContext> |
| 40 | + auto format(const T& p, FormatContext& ctx) |
| 41 | + { |
| 42 | + return format_to(ctx.out(), "{}", p.template as<std::string>()); |
| 43 | + } |
| 44 | +}; |
| 45 | + |
| 46 | +template <> |
| 47 | +struct fmt::formatter<o2::header::DataHeader> { |
| 48 | + // Presentation format: 'f' - fixed, 'e' - exponential. |
| 49 | + char presentation = 's'; |
| 50 | + |
| 51 | + // Parses format specifications of the form ['f' | 'e']. |
| 52 | + constexpr auto parse(format_parse_context& ctx) |
| 53 | + { |
| 54 | + auto it = ctx.begin(), end = ctx.end(); |
| 55 | + if (it != end && (*it == 's')) { |
| 56 | + presentation = *it++; |
| 57 | + } |
| 58 | + |
| 59 | + // Check if reached the end of the range: |
| 60 | + if (it != end && *it != '}') { |
| 61 | + throw format_error("invalid format"); |
| 62 | + } |
| 63 | + |
| 64 | + // Return an iterator past the end of the parsed range: |
| 65 | + return it; |
| 66 | + } |
| 67 | + |
| 68 | + template <typename FormatContext> |
| 69 | + auto format(const o2::header::DataHeader& h, FormatContext& ctx) |
| 70 | + { |
| 71 | + auto res = fmt::format("Data header version %u, flags: %u\n", h.headerVersion, h.flags) + |
| 72 | + fmt::format(" origin : {}\n", h.dataOrigin.str) + |
| 73 | + fmt::format(" serialization: {}\n", h.payloadSerializationMethod.str) + |
| 74 | + fmt::format(" description : {}\n", h.dataDescription.str) + |
| 75 | + fmt::format(" sub spec. : {}\n", (long long unsigned int)h.subSpecification) + |
| 76 | + fmt::format(" header size : {}\n", h.headerSize) + |
| 77 | + fmt::format(" payloadSize : {}\n", (long long unsigned int)h.payloadSize) + |
| 78 | + fmt::format(" firstTFOrbit : {}\n", h.firstTForbit) + |
| 79 | + fmt::format(" tfCounter : {}\n", h.tfCounter) + |
| 80 | + fmt::format(" runNumber : {}\n", h.runNumber); |
| 81 | + return format_to(ctx.out(), "{}", res); |
| 82 | + } |
| 83 | +}; |
| 84 | + |
| 85 | +#endif // O2_BASE_DATA_HEADER_HELPERS_ |
0 commit comments