yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.0
BinningUtils.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2023 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_BinningUtils_h
7#define YODA_BinningUtils_h
8
9#include <type_traits>
10#include <string>
11
12namespace YODA {
13
16
17 template <typename... EdgeT>
18 using all_CAxes = typename std::conjunction<std::is_floating_point<EdgeT>...>;
19
21 template <typename... EdgeT>
22 using enable_if_all_CAxisT = std::enable_if_t<all_CAxes<EdgeT...>::value>;
23
25 template <typename EdgeT>
26 using enable_if_CAxisT = std::enable_if_t<std::is_floating_point<EdgeT>::value, EdgeT>;
27
29 template <typename EdgeT>
30 using enable_if_DAxisT = std::enable_if_t<!std::is_floating_point<EdgeT>::value, EdgeT>;
31
33
36
45 template <typename T>
46 struct TypeID {
47 static const char* name() { return typeid(T).name(); }
48 };
49
51 template <>
52 struct TypeID<std::string> {
53 static const char* name() { return "s"; }
54 };
55
57 template<typename A, typename... As>
58 std::string mkAxisConfig() {
59 return (std::string(TypeID<A>::name()) + ... + TypeID<As>::name());
60 }
61
64 template <ssize_t DbnN, typename A, typename... As>
65 std::string mkTypeString() {
66
67 constexpr size_t N = sizeof...(As)+1;
68
69 if constexpr (all_CAxes<A, As...>::value) {
70 if constexpr (DbnN < 0) {
71 return "Estimate"+std::to_string(N)+"D";
72 }
73 if constexpr (DbnN == N+1) {
74 return "Profile"+std::to_string(N)+"D";
75 }
76 if constexpr (DbnN == N) {
77 return "Histo"+std::to_string(N)+"D";
78 }
79 }
80
81 std::string type = "Binned";
82 if (DbnN < 0) type += "Estimate";
83 else if (DbnN == N) type += "Histo";
84 else if (DbnN == N+1) type += "Profile";
85 else type += "Dbn" + std::to_string(DbnN);
86
87 std::string axes = (TypeID<A>::name() + ... + (std::string{","} + TypeID<As>::name()));
88
89 return (type + "<" + axes + ">");
90 }
91
93 template <typename A, typename... As>
94 std::string mkTypeString() { return mkTypeString<-1, A, As...>(); }
95
97
98}
99
100#endif
Anonymous namespace to limit visibility.
std::string mkTypeString()
Helper function to construct the BinnedDbn and BinnedEstimate type names.
std::enable_if_t< all_CAxes< EdgeT... >::value > enable_if_all_CAxisT
Checks if all edge types are continuous.
std::string mkAxisConfig()
Helper function to construct the axis config.
typename std::conjunction< std::is_floating_point< EdgeT >... > all_CAxes
std::enable_if_t<!std::is_floating_point< EdgeT >::value, EdgeT > enable_if_DAxisT
Checks if edge type is discrete and returns edge type.
std::enable_if_t< std::is_floating_point< EdgeT >::value, EdgeT > enable_if_CAxisT
Checks if edge type is continuous and returns edge type.
static const char * name()
Returns the type ID as a character sequence.
static const char * name()