Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-19 08:31:39

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