All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HistCache.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tuple>
4 #include <map>
5 #include <string>
6 
8 
9 class TAxis;
10 class TH1D;
11 class TH2D;
12 
13 namespace ana
14 {
15  /// \brief Helper for \ref Spectrum
16  ///
17  /// ROOT's handling of allocations, and especially deletions, can be very
18  /// slow. It keeps everything in a big map that it then has to lookups
19  /// in. This class provides a simple cache of histograms, recycling an old
20  /// histogram of the same binning instead of creating a new one.
21  ///
22  /// Allocate new histograms with \ref New, and return them to the cache with
23  /// \ref Delete.
24  class HistCache
25  {
26  public:
27  static TH1D* New(const std::string& title, const Binning& bins);
28  static TH1D* New(const std::string& title, const TAxis* bins);
29  static TH1D* Copy(const TH1D* h);
30 
31  static TH2D* NewTH2D(const std::string& title, const Binning& xbins, const Binning& ybins);
32  static TH2D* NewTH2D(const std::string& title, const TAxis* xbins, const TAxis* ybins);
33  static TH2D* Copy(const TH2D* h);
34 
35  static void Delete(TH1D*& h);
36  static void Delete(TH2D*& h);
37  static void PrintStats();
38  static void ClearCache();
39  protected:
40  static void CheckMemoryUse();
41 
42  // Key to the maps is Binning::ID()
43  static std::multimap<int, std::unique_ptr<TH1D>> fgMap;
44  static std::multimap<std::pair<int, int>, std::unique_ptr<TH2D>> fgMap2D;
45 
46  static int fgOut, fgIn;
47 
48  static long fgEstMemUsage;
49  static long fgMemHandedOut;
50  };
51 }
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:44
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:18
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:76
static long fgEstMemUsage
Definition: HistCache.h:48
Helper for Spectrum.
Definition: HistCache.h:24
process_name opflashCryoW ana
while getopts h
static TH2D * NewTH2D(const std::string &title, const Binning &xbins, const Binning &ybins)
Definition: HistCache.cxx:50
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
static int fgOut
Definition: HistCache.h:46
static long fgMemHandedOut
Definition: HistCache.h:49
static int fgIn
Definition: HistCache.h:46
static void PrintStats()
Definition: HistCache.cxx:152
static void CheckMemoryUse()
Definition: HistCache.cxx:126
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:21
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:43
static void ClearCache()
Definition: HistCache.cxx:142