Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:13:36

0001 // -*- C++ -*-
0002 //
0003 // This file is part of YODA -- Yet more Objects for Data Analysis
0004 // Copyright (C) 2008-2024 The YODA collaboration (see AUTHORS for details)
0005 //
0006 #ifndef YODA_BinningUtils_h
0007 #define YODA_BinningUtils_h
0008 
0009 #include <type_traits>
0010 #include <string>
0011 
0012 namespace YODA {
0013 
0014   /// @name Helper methods to probe continuous/discrete axis properties.
0015   /// @{
0016 
0017   template <typename... EdgeT>
0018   using all_CAxes = typename std::conjunction<std::is_floating_point<EdgeT>...>;
0019 
0020   /// @brief Checks if all edge types are continuous.
0021   template <typename... EdgeT>
0022   using enable_if_all_CAxisT = std::enable_if_t<all_CAxes<EdgeT...>::value>;
0023 
0024   /// @brief Checks if edge type is continuous and returns edge type.
0025   template <typename EdgeT>
0026   using enable_if_CAxisT = std::enable_if_t<std::is_floating_point<EdgeT>::value, EdgeT>;
0027 
0028   /// @brief Checks if edge type is discrete and returns edge type.
0029   template <typename EdgeT>
0030   using enable_if_DAxisT = std::enable_if_t<!std::is_floating_point<EdgeT>::value, EdgeT>;
0031 
0032   /// @}
0033 
0034   /// @name Helper methods to stringify edge types
0035   /// @{
0036 
0037   /// @brief Returns the type ID as a character sequence
0038   ///
0039   /// d - double
0040   /// f - float
0041   /// i - int
0042   /// j - unsigned int
0043   /// m - size_t
0044   /// l - ssize_t
0045   template <typename T>
0046   struct TypeID {
0047     static const char* name() { return typeid(T).name(); }
0048   };
0049 
0050   /// @brief Specialisation for type string
0051   template <>
0052   struct TypeID<std::string> {
0053     static const char* name() { return "s"; }
0054   };
0055 
0056   /// @brief Helper function to construct the axis config
0057   template<typename A, typename... As>
0058   std::string mkAxisConfig() {
0059     return (std::string(TypeID<A>::name()) + ... + TypeID<As>::name());
0060   }
0061 
0062   /// @brief Helper function to construct the BinnedDbn and
0063   /// BinnedEstimate type names.
0064   template <ssize_t DbnN, typename A, typename... As>
0065   std::string mkTypeString() {
0066 
0067     constexpr size_t N = sizeof...(As)+1;
0068 
0069     if constexpr (all_CAxes<A, As...>::value) {
0070       if constexpr (DbnN < 0) {
0071         return "Estimate"+std::to_string(N)+"D";
0072       }
0073       if constexpr (DbnN == N+1) {
0074         return "Profile"+std::to_string(N)+"D";
0075       }
0076       if constexpr (DbnN == N) {
0077         return "Histo"+std::to_string(N)+"D";
0078       }
0079     }
0080 
0081     std::string type = "Binned";
0082     if (DbnN < 0)          type += "Estimate";
0083     else if (DbnN == N)    type += "Histo";
0084     else if (DbnN == N+1)  type += "Profile";
0085     else type += "Dbn" + std::to_string(DbnN);
0086 
0087     std::string axes = (TypeID<A>::name() + ... + (std::string{","} + TypeID<As>::name()));
0088 
0089     return (type + "<" + axes + ">");
0090   }
0091 
0092   /// @brief Same as above, but for non-Dbn bin contents.
0093   template <typename A, typename... As>
0094   std::string mkTypeString() {  return mkTypeString<-1, A, As...>(); }
0095 
0096   /// @}
0097 
0098 }
0099 
0100 #endif