From cc684a77d4ae157c09eecea538a755e07a9785ea Mon Sep 17 00:00:00 2001
From: Rosen Matev <rosen.matev@cern.ch>
Date: Thu, 17 Mar 2022 12:48:01 +0100
Subject: [PATCH 1/3] Fix output for new histograms in JSON and MessageSvc
 sinks

---
 GaudiCoreSvc/src/MessageSvc/JSONSink.cpp      |  7 +--
 .../src/MessageSvc/MessageSvcSink.cpp         |  7 +--
 GaudiExamples/options/Histograms.py           |  3 +-
 .../tests/qmtest/refs/Histograms.ref          | 52 +++++++++++++++----
 .../qmtest/refs/config2/Histograms_wg.ref     | 51 ++++++++++++++----
 5 files changed, 85 insertions(+), 35 deletions(-)

diff --git a/GaudiCoreSvc/src/MessageSvc/JSONSink.cpp b/GaudiCoreSvc/src/MessageSvc/JSONSink.cpp
index 4c9a2de9f9..5798912fc2 100644
--- a/GaudiCoreSvc/src/MessageSvc/JSONSink.cpp
+++ b/GaudiCoreSvc/src/MessageSvc/JSONSink.cpp
@@ -73,12 +73,7 @@ namespace Gaudi::Monitoring {
     StatusCode stop() override;
 
     // Gaudi::Monitoring::Hub::Sink implementation
-    void registerEntity( Hub::Entity ent ) override {
-      if ( std::string_view( ent.type ).substr( 0, 8 ) == "counter:" || ent.type == "statentity" ||
-           ent.type == "histogram" ) {
-        m_monitoringEntities.emplace_back( std::move( ent ) );
-      }
-    }
+    void registerEntity( Hub::Entity ent ) override { m_monitoringEntities.emplace_back( std::move( ent ) ); }
 
     // Gaudi::Monitoring::Hub::Sink implementation
     void removeEntity( Hub::Entity const& ent ) override {
diff --git a/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp b/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp
index 714bf19ed6..0f2351bdfe 100644
--- a/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp
+++ b/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp
@@ -171,12 +171,7 @@ namespace Gaudi::Monitoring {
     StatusCode stop() override;
 
     // Gaudi::Monitoring::Hub::Sink implementation
-    void registerEntity( Hub::Entity ent ) override {
-      if ( std::string_view( ent.type ).substr( 0, 8 ) == "counter:" || ent.type == "statentity" ||
-           ent.type == "histogram" ) {
-        m_monitoringEntities.emplace_back( std::move( ent ) );
-      }
-    }
+    void registerEntity( Hub::Entity ent ) override { m_monitoringEntities.emplace_back( std::move( ent ) ); }
 
     // Gaudi::Monitoring::Hub::Sink implementation
     void removeEntity( Hub::Entity const& ent ) override {
diff --git a/GaudiExamples/options/Histograms.py b/GaudiExamples/options/Histograms.py
index 07efde9e20..969ddf1927 100644
--- a/GaudiExamples/options/Histograms.py
+++ b/GaudiExamples/options/Histograms.py
@@ -8,6 +8,7 @@
 # granted to it by virtue of its status as an Intergovernmental Organization        #
 # or submit itself to any jurisdiction.                                             #
 #####################################################################################
+from Configurables import Gaudi__Monitoring__JSONSink as JSONSink
 from Configurables import Gaudi__Monitoring__MessageSvcSink as MessageSvcSink
 from Gaudi.Configuration import *
 
@@ -36,5 +37,5 @@ app = ApplicationMgr(
     EvtSel="NONE",
     HistogramPersistency="ROOT",
     TopAlg=algs,
-    ExtSvc=[MessageSvcSink(), RootHistoSink()],
+    ExtSvc=[MessageSvcSink(), RootHistoSink(), JSONSink(DumpFullInfo=True)],
 )
diff --git a/GaudiExamples/tests/qmtest/refs/Histograms.ref b/GaudiExamples/tests/qmtest/refs/Histograms.ref
index af1541cd5e..984b911c7c 100644
--- a/GaudiExamples/tests/qmtest/refs/Histograms.ref
+++ b/GaudiExamples/tests/qmtest/refs/Histograms.ref
@@ -1,10 +1,9 @@
-# setting LC_ALL to "C"
-# --> Including file '/builds/gaudi/Gaudi/GaudiExamples/options/Histograms.py'
-# <-- End of file '/builds/gaudi/Gaudi/GaudiExamples/options/Histograms.py'
+# --> Including file '/home/rmatev/stack/Gaudi/GaudiExamples/options/Histograms.py'
+# <-- End of file '/home/rmatev/stack/Gaudi/GaudiExamples/options/Histograms.py'
 ApplicationMgr    SUCCESS
 ====================================================================================================================================
-                                                   Welcome to ApplicationMgr (GaudiCoreSvc v34r1)
-                                          running on runner-7f-zqs17-project-38-concurrent-0 on Mon Oct 19 16:16:56 2020
+                                                   Welcome to ApplicationMgr (GaudiCoreSvc v36r4)
+                                          running on n4050101 on Thu Mar 17 12:37:21 2022
 ====================================================================================================================================
 ApplicationMgr       INFO Application Manager Configured successfully
 SimpleHistos        DEBUG Property update for OutputLevel : new value = 2
@@ -134,8 +133,39 @@ SimpleHistos        DEBUG Monitoring histogram 'test1' desc = 'Forced Alpha ID t
 SimpleHistos        DEBUG Booked 1D Histogram : ID='test1' Path=SimpleHistos Title='Forced Alpha ID time test'
 SimpleHistos         INFO GaudiHistoAlgorithm:: Filling Histograms...... Please be patient !
 SimpleCounterHi...SUCCESS Filling Histograms...... Please be patient !
-SimpleCounterHi...   INFO Number of counters : 1
+Gaudi::Monitori...   INFO Writing counters to JSON file counters.json
+SimpleCounterHi...   INFO Number of counters : 31
  |    Counter                                      |     #     |    sum     | mean/eff^* | rms/err^*  |     min     |     max     |
+ | "Gauss"                                         |     49813 |
+ | "GaussBuf"                                      |    500000 |
+ | "GaussFlat"                                     |     49813 |
+ | "GaussFlatBuf"                                  |    500000 |
+ | "GaussFlatGauss"                                |     50102 |
+ | "GaussFlatGaussBuf"                             |    500000 |
+ | "GaussFlatGaussInt"                             |     50000 |
+ | "GaussFlatGaussNA"                              |     50000 |
+ | "GaussFlatGaussW"                               |     50000 |
+ | "GaussFlatInt"                                  |     50000 |
+ | "GaussFlatNA"                                   |     50000 |
+ | "GaussFlatW"                                    |     50000 |
+ | "GaussInt"                                      |     50000 |
+ | "GaussNA"                                       |     50000 |
+ | "GaussW"                                        |     50000 |
+ | "ProfGauss"                                     |    100000 |
+ | "ProfGaussBuf"                                  |    500000 |
+ | "ProfGaussFlat"                                 |    100000 |
+ | "ProfGaussFlatBuf"                              |    500000 |
+ | "ProfGaussFlatGauss"                            |    100000 |
+ | "ProfGaussFlatGaussBuf"                         |    500000 |
+ | "ProfGaussFlatGaussInt"                         |     50000 |
+ | "ProfGaussFlatGaussNA"                          |     50000 |
+ | "ProfGaussFlatGaussW"                           |     50000 |
+ | "ProfGaussFlatInt"                              |     50000 |
+ | "ProfGaussFlatNA"                               |     50000 |
+ | "ProfGaussFlatW"                                |     50000 |
+ | "ProfGaussInt"                                  |     50000 |
+ | "ProfGaussNA"                                   |     50000 |
+ | "ProfGaussW"                                    |     50000 |
  | "calls"                                         |     50000 |
 ApplicationMgr       INFO Application Manager Stopped successfully
 SimpleHistos      SUCCESS Booked 30 Histogram(s) : 1D=10 2D=5 3D=3 1DProf=9 2DProf=3
@@ -183,11 +213,11 @@ EventLoopMgr         INFO Histograms converted successfully according to request
 *****Chrono*****     INFO ****************************************************************************************************
 *****Chrono*****     INFO  The Final CPU consumption ( Chrono ) Table (ordered)
 *****Chrono*****     INFO ****************************************************************************************************
-1DOldStyle           INFO Time User   : Tot=   30 [ms] Ave/Min/Max=  0.0006(+-  0.0775)/       0/      10 [ms] #=49999
-1DForcedAlphaID      INFO Time User   : Tot=   80 [ms] Ave/Min/Max=  0.0016(+-   0.126)/       0/      10 [ms] #=49999
-1DAutoID             INFO Time User   : Tot=  100 [ms] Ave/Min/Max=   0.002(+-   0.141)/       0/      10 [ms] #=49999
-1DForcedNumericID    INFO Time User   : Tot=  120 [ms] Ave/Min/Max=  0.0024(+-   0.155)/       0/      10 [ms] #=49999
-ChronoStatSvc        INFO Time User   : Tot= 3.34  [s]  #=  1
+1DForcedNumericID    INFO Time User   : Tot=    0 [us] Ave/Min/Max=       0(+-       0)/       0/       0 [us] #=49999
+1DForcedAlphaID      INFO Time User   : Tot=   20 [ms] Ave/Min/Max=  0.0004(+-  0.0632)/       0/      10 [ms] #=49999
+1DAutoID             INFO Time User   : Tot=   40 [ms] Ave/Min/Max=  0.0008(+-  0.0894)/       0/      10 [ms] #=49999
+1DOldStyle           INFO Time User   : Tot=   60 [ms] Ave/Min/Max=  0.0012(+-    0.11)/       0/      10 [ms] #=49999
+ChronoStatSvc        INFO Time User   : Tot= 3.36  [s]  #=  1
 *****Chrono*****     INFO ****************************************************************************************************
 ChronoStatSvc.f...   INFO  Service finalized successfully
 ApplicationMgr       INFO Application Manager Finalized successfully
diff --git a/GaudiExamples/tests/qmtest/refs/config2/Histograms_wg.ref b/GaudiExamples/tests/qmtest/refs/config2/Histograms_wg.ref
index 08be8f1522..b59c3df392 100644
--- a/GaudiExamples/tests/qmtest/refs/config2/Histograms_wg.ref
+++ b/GaudiExamples/tests/qmtest/refs/config2/Histograms_wg.ref
@@ -1,10 +1,9 @@
-# setting LC_ALL to "C"
-# --> Including file '/builds/gaudi/Gaudi/GaudiExamples/options/Histograms_with_global.py'
-# <-- End of file '/builds/gaudi/Gaudi/GaudiExamples/options/Histograms_with_global.py'
+# --> Including file '/home/rmatev/stack/Gaudi/GaudiExamples/options/Histograms_with_global.py'
+# <-- End of file '/home/rmatev/stack/Gaudi/GaudiExamples/options/Histograms_with_global.py'
 ApplicationMgr    SUCCESS
 ====================================================================================================================================
-                                                   Welcome to ApplicationMgr (GaudiCoreSvc v34r1)
-                                          running on runner-7f-zqs17-project-38-concurrent-0 on Mon Oct 19 16:16:46 2020
+                                                   Welcome to ApplicationMgr (GaudiCoreSvc v36r4)
+                                          running on n4050101 on Thu Mar 17 12:37:18 2022
 ====================================================================================================================================
 ApplicationMgr       INFO Application Manager Configured successfully
 SimpleHistos        DEBUG Property update for OutputLevel : new value = 2
@@ -136,8 +135,38 @@ SimpleHistos        DEBUG Monitoring histogram 'test1' desc = 'Forced Alpha ID t
 SimpleHistos        DEBUG Booked 1D Histogram : ID='test1' Path=SimpleHistos Title='Forced Alpha ID time test'
 SimpleHistos         INFO GaudiHistoAlgorithm:: Filling Histograms...... Please be patient !
 SimpleCounterHi...SUCCESS Filling Histograms...... Please be patient !
-SimpleCounterHi...   INFO Number of counters : 1
+SimpleCounterHi...   INFO Number of counters : 31
  |    Counter                                      |     #     |    sum     | mean/eff^* | rms/err^*  |     min     |     max     |
+ | "Gauss"                                         |     49813 |
+ | "GaussBuf"                                      |    500000 |
+ | "GaussFlat"                                     |     49813 |
+ | "GaussFlatBuf"                                  |    500000 |
+ | "GaussFlatGauss"                                |     50102 |
+ | "GaussFlatGaussBuf"                             |    500000 |
+ | "GaussFlatGaussInt"                             |     50000 |
+ | "GaussFlatGaussNA"                              |     50000 |
+ | "GaussFlatGaussW"                               |     50000 |
+ | "GaussFlatInt"                                  |     50000 |
+ | "GaussFlatNA"                                   |     50000 |
+ | "GaussFlatW"                                    |     50000 |
+ | "GaussInt"                                      |     50000 |
+ | "GaussNA"                                       |     50000 |
+ | "GaussW"                                        |     50000 |
+ | "ProfGauss"                                     |    100000 |
+ | "ProfGaussBuf"                                  |    500000 |
+ | "ProfGaussFlat"                                 |    100000 |
+ | "ProfGaussFlatBuf"                              |    500000 |
+ | "ProfGaussFlatGauss"                            |    100000 |
+ | "ProfGaussFlatGaussBuf"                         |    500000 |
+ | "ProfGaussFlatGaussInt"                         |     50000 |
+ | "ProfGaussFlatGaussNA"                          |     50000 |
+ | "ProfGaussFlatGaussW"                           |     50000 |
+ | "ProfGaussFlatInt"                              |     50000 |
+ | "ProfGaussFlatNA"                               |     50000 |
+ | "ProfGaussFlatW"                                |     50000 |
+ | "ProfGaussInt"                                  |     50000 |
+ | "ProfGaussNA"                                   |     50000 |
+ | "ProfGaussW"                                    |     50000 |
  | "calls"                                         |     50000 |
 ApplicationMgr       INFO Application Manager Stopped successfully
 SimpleHistos      SUCCESS Booked 30 Histogram(s) : 1D=10 2D=5 3D=3 1DProf=9 2DProf=3
@@ -185,11 +214,11 @@ EventLoopMgr         INFO Histograms converted successfully according to request
 *****Chrono*****     INFO ****************************************************************************************************
 *****Chrono*****     INFO  The Final CPU consumption ( Chrono ) Table (ordered)
 *****Chrono*****     INFO ****************************************************************************************************
-1DAutoID             INFO Time User   : Tot=   80 [ms] Ave/Min/Max=  0.0016(+-   0.126)/       0/      10 [ms] #=49999
-1DForcedAlphaID      INFO Time User   : Tot=  120 [ms] Ave/Min/Max=  0.0024(+-   0.155)/       0/      10 [ms] #=49999
-1DForcedNumericID    INFO Time User   : Tot=  110 [ms] Ave/Min/Max=  0.0022(+-   0.148)/       0/      10 [ms] #=49999
-1DOldStyle           INFO Time User   : Tot=  130 [ms] Ave/Min/Max=  0.0026(+-   0.161)/       0/      10 [ms] #=49999
-ChronoStatSvc        INFO Time User   : Tot= 3.26  [s]  #=  1
+1DForcedNumericID    INFO Time User   : Tot=    0 [us] Ave/Min/Max=       0(+-       0)/       0/       0 [us] #=49999
+1DOldStyle           INFO Time User   : Tot=    0 [us] Ave/Min/Max=       0(+-       0)/       0/       0 [us] #=49999
+1DAutoID             INFO Time User   : Tot=   10 [ms] Ave/Min/Max=  0.0002(+-  0.0447)/       0/      10 [ms] #=49999
+1DForcedAlphaID      INFO Time User   : Tot=   20 [ms] Ave/Min/Max=  0.0004(+-  0.0632)/       0/      10 [ms] #=49999
+ChronoStatSvc        INFO Time User   : Tot= 3.13  [s]  #=  1
 *****Chrono*****     INFO ****************************************************************************************************
 ChronoStatSvc.f...   INFO  Service finalized successfully
 ApplicationMgr       INFO Application Manager Finalized successfully
-- 
GitLab


From e8867fde8c24e4b5e0a80fda870366b440d4fac9 Mon Sep 17 00:00:00 2001
From: Rosen Matev <rosen.matev@cern.ch>
Date: Thu, 9 Jun 2022 09:03:01 +0200
Subject: [PATCH 2/3] Add examples for maps of histograms

---
 .../src/Histograms/CounterHistos.cpp          | 35 ++++++++++++++
 .../tests/qmtest/refs/Histograms.ref          | 44 ++++++++++--------
 .../qmtest/refs/config2/Histograms_wg.ref     | 46 +++++++++++--------
 3 files changed, 86 insertions(+), 39 deletions(-)

diff --git a/GaudiExamples/src/Histograms/CounterHistos.cpp b/GaudiExamples/src/Histograms/CounterHistos.cpp
index e8224c1e76..86a962e2a3 100644
--- a/GaudiExamples/src/Histograms/CounterHistos.cpp
+++ b/GaudiExamples/src/Histograms/CounterHistos.cpp
@@ -73,6 +73,20 @@ namespace Gaudi {
       public:
         using Gaudi::Algorithm::Algorithm;
 
+        StatusCode initialize() override {
+          const StatusCode sc = Algorithm::initialize();
+          if ( sc.isFailure() ) return sc;
+
+          for ( int i : { 1, 2, 3 } ) {
+            using Axis = Gaudi::Accumulators::Axis<decltype( m_map_gauss_init )::mapped_type::AxisArithmeticType>;
+            m_map_gauss_init.emplace( std::piecewise_construct, std::forward_as_tuple( i ),
+                                      std::forward_as_tuple( this, "MapGaussInit" + std::to_string( i ),
+                                                             "Gaussian mean=0, sigma=1, atomic", Axis{ 50, -5, 5 } ) );
+          }
+
+          return sc;
+        }
+
         StatusCode execute( const EventContext& ) const override {
           // some random number generators, just to provide numbers
           static Rndm::Numbers Gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
@@ -137,6 +151,12 @@ namespace Gaudi {
             prof_gaussVflatVgauss_buf[{ flat, gauss, gauss2 }] += gauss3;
           }
 
+          // maps of histograms
+          for ( int i : { 1, 2, 3 } ) {
+            ++m_map_gauss_construct.at( i )[gauss];
+            ++m_map_gauss_init.at( i )[gauss];
+          }
+
           if ( m_nCalls.nEntries() == 0 ) always() << "Filling Histograms...... Please be patient !" << endmsg;
           ++m_nCalls;
           return StatusCode::SUCCESS;
@@ -261,6 +281,21 @@ namespace Gaudi {
             "ProfGaussFlatGaussBuf",
             "Profile, Gaussian V Flat V Gaussian, buffered",
             { { 10, -5, 5 }, { 10, -5, 5 }, { 10, -5, 5 } } };
+
+        // map of histograms that is filled on construction
+        mutable std::map<int, Gaudi::Accumulators::Histogram<1>> m_map_gauss_construct = [this]() {
+          std::map<int, Gaudi::Accumulators::Histogram<1>> map;
+          for ( int i : { 1, 2, 3 } ) {
+            using Axis = Gaudi::Accumulators::Axis<decltype( map )::mapped_type::AxisArithmeticType>;
+            map.emplace( std::piecewise_construct, std::forward_as_tuple( i ),
+                         std::forward_as_tuple( this, "MapGaussConstruct" + std::to_string( i ),
+                                                "Gaussian mean=0, sigma=1, atomic", Axis{ 50, -5, 5 } ) );
+          }
+          return map;
+        }();
+
+        // map of histograms that is filled at initialization (e.g. because it depends on properties)
+        mutable std::map<int, Gaudi::Accumulators::Histogram<1>> m_map_gauss_init;
       };
       DECLARE_COMPONENT( GaudiHistoAlgorithm )
     } // namespace Counter
diff --git a/GaudiExamples/tests/qmtest/refs/Histograms.ref b/GaudiExamples/tests/qmtest/refs/Histograms.ref
index 984b911c7c..388fd735f3 100644
--- a/GaudiExamples/tests/qmtest/refs/Histograms.ref
+++ b/GaudiExamples/tests/qmtest/refs/Histograms.ref
@@ -2,8 +2,8 @@
 # <-- End of file '/home/rmatev/stack/Gaudi/GaudiExamples/options/Histograms.py'
 ApplicationMgr    SUCCESS
 ====================================================================================================================================
-                                                   Welcome to ApplicationMgr (GaudiCoreSvc v36r4)
-                                          running on n4050101 on Thu Mar 17 12:37:21 2022
+                                                   Welcome to ApplicationMgr (GaudiCoreSvc v36r5)
+                                          running on n4050101 on Thu Jun  9 09:11:00 2022
 ====================================================================================================================================
 ApplicationMgr       INFO Application Manager Configured successfully
 SimpleHistos        DEBUG Property update for OutputLevel : new value = 2
@@ -134,38 +134,44 @@ SimpleHistos        DEBUG Booked 1D Histogram : ID='test1' Path=SimpleHistos Tit
 SimpleHistos         INFO GaudiHistoAlgorithm:: Filling Histograms...... Please be patient !
 SimpleCounterHi...SUCCESS Filling Histograms...... Please be patient !
 Gaudi::Monitori...   INFO Writing counters to JSON file counters.json
-SimpleCounterHi...   INFO Number of counters : 31
+SimpleCounterHi...   INFO Number of counters : 37
  |    Counter                                      |     #     |    sum     | mean/eff^* | rms/err^*  |     min     |     max     |
- | "Gauss"                                         |     49813 |
+ | "Gauss"                                         |     50000 |
  | "GaussBuf"                                      |    500000 |
- | "GaussFlat"                                     |     49813 |
+ | "GaussFlat"                                     |     50000 |
  | "GaussFlatBuf"                                  |    500000 |
- | "GaussFlatGauss"                                |     50102 |
+ | "GaussFlatGauss"                                |     50000 |
  | "GaussFlatGaussBuf"                             |    500000 |
  | "GaussFlatGaussInt"                             |     50000 |
  | "GaussFlatGaussNA"                              |     50000 |
- | "GaussFlatGaussW"                               |     50000 |
+ | "GaussFlatGaussW"                               |     24836 |
  | "GaussFlatInt"                                  |     50000 |
  | "GaussFlatNA"                                   |     50000 |
- | "GaussFlatW"                                    |     50000 |
+ | "GaussFlatW"                                    |     24592 |
  | "GaussInt"                                      |     50000 |
  | "GaussNA"                                       |     50000 |
- | "GaussW"                                        |     50000 |
- | "ProfGauss"                                     |    100000 |
+ | "GaussW"                                        |     24981 |
+ | "MapGaussConstruct1"                            |     50000 |
+ | "MapGaussConstruct2"                            |     50000 |
+ | "MapGaussConstruct3"                            |     50000 |
+ | "MapGaussInit1"                                 |     50000 |
+ | "MapGaussInit2"                                 |     50000 |
+ | "MapGaussInit3"                                 |     50000 |
+ | "ProfGauss"                                     |     50000 |
  | "ProfGaussBuf"                                  |    500000 |
- | "ProfGaussFlat"                                 |    100000 |
+ | "ProfGaussFlat"                                 |     50000 |
  | "ProfGaussFlatBuf"                              |    500000 |
- | "ProfGaussFlatGauss"                            |    100000 |
+ | "ProfGaussFlatGauss"                            |     50000 |
  | "ProfGaussFlatGaussBuf"                         |    500000 |
  | "ProfGaussFlatGaussInt"                         |     50000 |
  | "ProfGaussFlatGaussNA"                          |     50000 |
- | "ProfGaussFlatGaussW"                           |     50000 |
+ | "ProfGaussFlatGaussW"                           |     24836 |
  | "ProfGaussFlatInt"                              |     50000 |
  | "ProfGaussFlatNA"                               |     50000 |
- | "ProfGaussFlatW"                                |     50000 |
+ | "ProfGaussFlatW"                                |     24592 |
  | "ProfGaussInt"                                  |     50000 |
  | "ProfGaussNA"                                   |     50000 |
- | "ProfGaussW"                                    |     50000 |
+ | "ProfGaussW"                                    |     24981 |
  | "calls"                                         |     50000 |
 ApplicationMgr       INFO Application Manager Stopped successfully
 SimpleHistos      SUCCESS Booked 30 Histogram(s) : 1D=10 2D=5 3D=3 1DProf=9 2DProf=3
@@ -213,11 +219,11 @@ EventLoopMgr         INFO Histograms converted successfully according to request
 *****Chrono*****     INFO ****************************************************************************************************
 *****Chrono*****     INFO  The Final CPU consumption ( Chrono ) Table (ordered)
 *****Chrono*****     INFO ****************************************************************************************************
-1DForcedNumericID    INFO Time User   : Tot=    0 [us] Ave/Min/Max=       0(+-       0)/       0/       0 [us] #=49999
-1DForcedAlphaID      INFO Time User   : Tot=   20 [ms] Ave/Min/Max=  0.0004(+-  0.0632)/       0/      10 [ms] #=49999
+1DForcedAlphaID      INFO Time User   : Tot=    0 [us] Ave/Min/Max=       0(+-       0)/       0/       0 [us] #=49999
+1DOldStyle           INFO Time User   : Tot=   10 [ms] Ave/Min/Max=  0.0002(+-  0.0447)/       0/      10 [ms] #=49999
+1DForcedNumericID    INFO Time User   : Tot=   10 [ms] Ave/Min/Max=  0.0002(+-  0.0447)/       0/      10 [ms] #=49999
 1DAutoID             INFO Time User   : Tot=   40 [ms] Ave/Min/Max=  0.0008(+-  0.0894)/       0/      10 [ms] #=49999
-1DOldStyle           INFO Time User   : Tot=   60 [ms] Ave/Min/Max=  0.0012(+-    0.11)/       0/      10 [ms] #=49999
-ChronoStatSvc        INFO Time User   : Tot= 3.36  [s]  #=  1
+ChronoStatSvc        INFO Time User   : Tot= 3.14  [s]  #=  1
 *****Chrono*****     INFO ****************************************************************************************************
 ChronoStatSvc.f...   INFO  Service finalized successfully
 ApplicationMgr       INFO Application Manager Finalized successfully
diff --git a/GaudiExamples/tests/qmtest/refs/config2/Histograms_wg.ref b/GaudiExamples/tests/qmtest/refs/config2/Histograms_wg.ref
index b59c3df392..46d71e2418 100644
--- a/GaudiExamples/tests/qmtest/refs/config2/Histograms_wg.ref
+++ b/GaudiExamples/tests/qmtest/refs/config2/Histograms_wg.ref
@@ -2,8 +2,8 @@
 # <-- End of file '/home/rmatev/stack/Gaudi/GaudiExamples/options/Histograms_with_global.py'
 ApplicationMgr    SUCCESS
 ====================================================================================================================================
-                                                   Welcome to ApplicationMgr (GaudiCoreSvc v36r4)
-                                          running on n4050101 on Thu Mar 17 12:37:18 2022
+                                                   Welcome to ApplicationMgr (GaudiCoreSvc v36r5)
+                                          running on n4050101 on Thu Jun  9 09:10:57 2022
 ====================================================================================================================================
 ApplicationMgr       INFO Application Manager Configured successfully
 SimpleHistos        DEBUG Property update for OutputLevel : new value = 2
@@ -135,38 +135,44 @@ SimpleHistos        DEBUG Monitoring histogram 'test1' desc = 'Forced Alpha ID t
 SimpleHistos        DEBUG Booked 1D Histogram : ID='test1' Path=SimpleHistos Title='Forced Alpha ID time test'
 SimpleHistos         INFO GaudiHistoAlgorithm:: Filling Histograms...... Please be patient !
 SimpleCounterHi...SUCCESS Filling Histograms...... Please be patient !
-SimpleCounterHi...   INFO Number of counters : 31
+SimpleCounterHi...   INFO Number of counters : 37
  |    Counter                                      |     #     |    sum     | mean/eff^* | rms/err^*  |     min     |     max     |
- | "Gauss"                                         |     49813 |
+ | "Gauss"                                         |     50000 |
  | "GaussBuf"                                      |    500000 |
- | "GaussFlat"                                     |     49813 |
+ | "GaussFlat"                                     |     50000 |
  | "GaussFlatBuf"                                  |    500000 |
- | "GaussFlatGauss"                                |     50102 |
+ | "GaussFlatGauss"                                |     50000 |
  | "GaussFlatGaussBuf"                             |    500000 |
  | "GaussFlatGaussInt"                             |     50000 |
  | "GaussFlatGaussNA"                              |     50000 |
- | "GaussFlatGaussW"                               |     50000 |
+ | "GaussFlatGaussW"                               |     24836 |
  | "GaussFlatInt"                                  |     50000 |
  | "GaussFlatNA"                                   |     50000 |
- | "GaussFlatW"                                    |     50000 |
+ | "GaussFlatW"                                    |     24592 |
  | "GaussInt"                                      |     50000 |
  | "GaussNA"                                       |     50000 |
- | "GaussW"                                        |     50000 |
- | "ProfGauss"                                     |    100000 |
+ | "GaussW"                                        |     24981 |
+ | "MapGaussConstruct1"                            |     50000 |
+ | "MapGaussConstruct2"                            |     50000 |
+ | "MapGaussConstruct3"                            |     50000 |
+ | "MapGaussInit1"                                 |     50000 |
+ | "MapGaussInit2"                                 |     50000 |
+ | "MapGaussInit3"                                 |     50000 |
+ | "ProfGauss"                                     |     50000 |
  | "ProfGaussBuf"                                  |    500000 |
- | "ProfGaussFlat"                                 |    100000 |
+ | "ProfGaussFlat"                                 |     50000 |
  | "ProfGaussFlatBuf"                              |    500000 |
- | "ProfGaussFlatGauss"                            |    100000 |
+ | "ProfGaussFlatGauss"                            |     50000 |
  | "ProfGaussFlatGaussBuf"                         |    500000 |
  | "ProfGaussFlatGaussInt"                         |     50000 |
  | "ProfGaussFlatGaussNA"                          |     50000 |
- | "ProfGaussFlatGaussW"                           |     50000 |
+ | "ProfGaussFlatGaussW"                           |     24836 |
  | "ProfGaussFlatInt"                              |     50000 |
  | "ProfGaussFlatNA"                               |     50000 |
- | "ProfGaussFlatW"                                |     50000 |
+ | "ProfGaussFlatW"                                |     24592 |
  | "ProfGaussInt"                                  |     50000 |
  | "ProfGaussNA"                                   |     50000 |
- | "ProfGaussW"                                    |     50000 |
+ | "ProfGaussW"                                    |     24981 |
  | "calls"                                         |     50000 |
 ApplicationMgr       INFO Application Manager Stopped successfully
 SimpleHistos      SUCCESS Booked 30 Histogram(s) : 1D=10 2D=5 3D=3 1DProf=9 2DProf=3
@@ -214,11 +220,11 @@ EventLoopMgr         INFO Histograms converted successfully according to request
 *****Chrono*****     INFO ****************************************************************************************************
 *****Chrono*****     INFO  The Final CPU consumption ( Chrono ) Table (ordered)
 *****Chrono*****     INFO ****************************************************************************************************
-1DForcedNumericID    INFO Time User   : Tot=    0 [us] Ave/Min/Max=       0(+-       0)/       0/       0 [us] #=49999
-1DOldStyle           INFO Time User   : Tot=    0 [us] Ave/Min/Max=       0(+-       0)/       0/       0 [us] #=49999
-1DAutoID             INFO Time User   : Tot=   10 [ms] Ave/Min/Max=  0.0002(+-  0.0447)/       0/      10 [ms] #=49999
-1DForcedAlphaID      INFO Time User   : Tot=   20 [ms] Ave/Min/Max=  0.0004(+-  0.0632)/       0/      10 [ms] #=49999
-ChronoStatSvc        INFO Time User   : Tot= 3.13  [s]  #=  1
+1DOldStyle           INFO Time User   : Tot=   10 [ms] Ave/Min/Max=  0.0002(+-  0.0447)/       0/      10 [ms] #=49999
+1DForcedNumericID    INFO Time User   : Tot=   30 [ms] Ave/Min/Max=  0.0006(+-  0.0775)/       0/      10 [ms] #=49999
+1DForcedAlphaID      INFO Time User   : Tot=   30 [ms] Ave/Min/Max=  0.0006(+-  0.0775)/       0/      10 [ms] #=49999
+1DAutoID             INFO Time User   : Tot=   30 [ms] Ave/Min/Max=  0.0006(+-  0.0775)/       0/      10 [ms] #=49999
+ChronoStatSvc        INFO Time User   : Tot= 3.04  [s]  #=  1
 *****Chrono*****     INFO ****************************************************************************************************
 ChronoStatSvc.f...   INFO  Service finalized successfully
 ApplicationMgr       INFO Application Manager Finalized successfully
-- 
GitLab


From bdee4443fb81a5d3c2c3f23da8b804d071cc8cc9 Mon Sep 17 00:00:00 2001
From: Rosen Matev <rosen.matev@cern.ch>
Date: Thu, 9 Jun 2022 12:11:56 +0200
Subject: [PATCH 3/3] Name type for axes specification and use in examples

---
 .../src/Histograms/CounterHistos.cpp          | 28 +++++++++----------
 .../include/Gaudi/Accumulators/Histogram.h    |  3 +-
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/GaudiExamples/src/Histograms/CounterHistos.cpp b/GaudiExamples/src/Histograms/CounterHistos.cpp
index 86a962e2a3..321ed349c4 100644
--- a/GaudiExamples/src/Histograms/CounterHistos.cpp
+++ b/GaudiExamples/src/Histograms/CounterHistos.cpp
@@ -74,17 +74,15 @@ namespace Gaudi {
         using Gaudi::Algorithm::Algorithm;
 
         StatusCode initialize() override {
-          const StatusCode sc = Algorithm::initialize();
-          if ( sc.isFailure() ) return sc;
-
-          for ( int i : { 1, 2, 3 } ) {
-            using Axis = Gaudi::Accumulators::Axis<decltype( m_map_gauss_init )::mapped_type::AxisArithmeticType>;
-            m_map_gauss_init.emplace( std::piecewise_construct, std::forward_as_tuple( i ),
-                                      std::forward_as_tuple( this, "MapGaussInit" + std::to_string( i ),
-                                                             "Gaussian mean=0, sigma=1, atomic", Axis{ 50, -5, 5 } ) );
-          }
-
-          return sc;
+          return Algorithm::initialize().andThen( [&] {
+            for ( int i : { 1, 2, 3 } ) {
+              using AxesSpecType = decltype( m_map_prof_gauss_init )::mapped_type::AxesSpecType;
+              m_map_prof_gauss_init.emplace( std::piecewise_construct, std::forward_as_tuple( i ),
+                                             std::forward_as_tuple( this, "MapGaussInit" + std::to_string( i ),
+                                                                    "Gaussian mean=0, sigma=1, atomic",
+                                                                    AxesSpecType( { 50, -5, 5 }, { 50, -5, 5 } ) ) );
+            }
+          } );
         }
 
         StatusCode execute( const EventContext& ) const override {
@@ -154,7 +152,7 @@ namespace Gaudi {
           // maps of histograms
           for ( int i : { 1, 2, 3 } ) {
             ++m_map_gauss_construct.at( i )[gauss];
-            ++m_map_gauss_init.at( i )[gauss];
+            m_map_prof_gauss_init.at( i )[gauss] += gauss3;
           }
 
           if ( m_nCalls.nEntries() == 0 ) always() << "Filling Histograms...... Please be patient !" << endmsg;
@@ -286,16 +284,16 @@ namespace Gaudi {
         mutable std::map<int, Gaudi::Accumulators::Histogram<1>> m_map_gauss_construct = [this]() {
           std::map<int, Gaudi::Accumulators::Histogram<1>> map;
           for ( int i : { 1, 2, 3 } ) {
-            using Axis = Gaudi::Accumulators::Axis<decltype( map )::mapped_type::AxisArithmeticType>;
+            using AxesSpecType = decltype( map )::mapped_type::AxesSpecType;
             map.emplace( std::piecewise_construct, std::forward_as_tuple( i ),
                          std::forward_as_tuple( this, "MapGaussConstruct" + std::to_string( i ),
-                                                "Gaussian mean=0, sigma=1, atomic", Axis{ 50, -5, 5 } ) );
+                                                "Gaussian mean=0, sigma=1, atomic", AxesSpecType( { 50, -5, 5 } ) ) );
           }
           return map;
         }();
 
         // map of histograms that is filled at initialization (e.g. because it depends on properties)
-        mutable std::map<int, Gaudi::Accumulators::Histogram<1>> m_map_gauss_init;
+        mutable std::map<int, Gaudi::Accumulators::ProfileHistogram<2>> m_map_prof_gauss_init;
       };
       DECLARE_COMPONENT( GaudiHistoAlgorithm )
     } // namespace Counter
diff --git a/GaudiKernel/include/Gaudi/Accumulators/Histogram.h b/GaudiKernel/include/Gaudi/Accumulators/Histogram.h
index e33fff7a63..032c34ef71 100644
--- a/GaudiKernel/include/Gaudi/Accumulators/Histogram.h
+++ b/GaudiKernel/include/Gaudi/Accumulators/Histogram.h
@@ -265,8 +265,9 @@ namespace Gaudi::Accumulators {
   public:
     using BaseAccumulator    = BaseAccumulatorT<Atomicity, Arithmetic>;
     using AxisArithmeticType = typename InputType::AxisArithmeticType;
+    using AxesSpecType       = GetTuple_t<Axis<AxisArithmeticType>, ND::value>;
     template <std::size_t... Is>
-    HistogramingAccumulatorInternal( GetTuple_t<Axis<AxisArithmeticType>, ND::value> axis, std::index_sequence<Is...> )
+    HistogramingAccumulatorInternal( AxesSpecType axis, std::index_sequence<Is...> )
         : m_axis{ std::get<Is>( axis )... }
         , m_totNBins{ computeTotNBins() }
         , m_value( new BaseAccumulator[m_totNBins] ) {
-- 
GitLab