Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
ana::HistCache Class Reference

Helper for Spectrum. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-01-22/CAFAna/Core/HistCache.h"

Static Public Member Functions

static TH1D * New (const std::string &title, const Binning &bins)
 
static TH1F * NewF (const std::string &title, const Binning &bins)
 
static TH1D * New (const std::string &title, const TAxis *bins)
 
static TH1F * NewF (const std::string &title, const TAxis *bins)
 
static TH1D * Copy (const TH1D *h)
 
static TH1F * Copy (const TH1F *h)
 
static TH2D * NewTH2D (const std::string &title, const Binning &bins)
 
static TH2D * NewTH2D (const std::string &title, const TAxis *bins)
 
static TH2D * NewTH2D (const std::string &title, const Binning &xbins, const Binning &ybins)
 The following two TH2D functions can have flexible y-axis. More...
 
static TH2D * NewTH2D (const std::string &title, const TAxis *xbins, const TAxis *ybins)
 
static TH2F * NewTH2F (const std::string &title, const Binning &bins)
 
static TH2F * NewTH2F (const std::string &title, const TAxis *bins)
 
static TH2F * NewTH2F (const std::string &title, const Binning &xbins, const Binning &ybins)
 The following two TH2F functions can have flexible y-axis. More...
 
static TH2F * NewTH2F (const std::string &title, const TAxis *xbins, const TAxis *ybins)
 
static TH2D * Copy (const TH2D *h)
 
static TH2F * Copy (const TH2F *h)
 
static TH3D * NewTH3D (const std::string &title, const Binning &xbins, const Binning &ybins, const Binning &zbins)
 For TH3D. More...
 
static TH3D * NewTH3D (const std::string &title, const TAxis *xbins, const TAxis *ybins, const TAxis *zbins)
 
static TH3D * Copy (const TH3D *h)
 
static void Delete (TH1D *&h)
 
static void Delete (TH1F *&h)
 
static void Delete (TH2D *&h)
 
static void Delete (TH2F *&h)
 
static void Delete (TH3D *&h)
 
static void PrintStats ()
 
static void ClearCache ()
 
static void LeakAll ()
 for debugging shutdown crashes More...
 

Static Protected Member Functions

static void CheckMemoryUse ()
 

Static Protected Attributes

static std::multimap< int, std::unique_ptr< TH1D > > fgMap
 
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
 
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
 
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
 
static std::multimap< std::pair< int, int >, std::unique_ptr< TH3D > > fgMap3D
 
static int fgOut = 0
 
static int fgIn = 0
 
static long fgEstMemUsage = 0
 

Detailed Description

Helper for Spectrum.

ROOT's handling of allocations, and especially deletions, can be very slow. It keeps everything in a big map that it then has to lookups in. This class provides a simple cache of histograms, recycling an old histogram of the same binning instead of creating a new one.

Allocate new histograms with New, and return them to the cache with Delete.

Definition at line 27 of file HistCache.h.

Member Function Documentation

void ana::HistCache::CheckMemoryUse ( )
staticprotected

Definition at line 294 of file HistCache.cxx.

References om::cerr, ClearCache(), allTimeWatchdog::endl, fgEstMemUsage, submit_hadd::l, and PrintStats().

Referenced by Delete().

295  {
296  if(fgEstMemUsage > 500l*1024*1024){
297  std::cerr << "Warning! HistCache memory usage exceeds 500MB. "
298  << "That probably means histograms are being returned "
299  << "to the cache that weren't originally handed out by it. "
300  << std::endl;
301  PrintStats();
302  std::cerr << "Now clearing cache. This could take a long time..."
303  << std::endl;
304  ClearCache();
305  std::cerr << "Done clearing cache" << std::endl;
306  }
307  }
OStream cerr
Definition: OStream.cxx:7
static long fgEstMemUsage
Definition: HistCache.h:82
static void PrintStats()
Definition: HistCache.cxx:323
static void ClearCache()
Definition: HistCache.cxx:310
void ana::HistCache::ClearCache ( )
static

Definition at line 310 of file HistCache.cxx.

References fgEstMemUsage, fgIn, fgMap, fgMap2D, fgMap2F, fgMap3D, fgMapF, and fgOut.

Referenced by CheckMemoryUse(), LeakAll(), NDDataMC(), nue_data_mc_validation(), nue_fd_mc_validation(), numu_data_mc_validation(), ana::PredictionSystJoint2018::PredictionSystJoint2018(), ana::PredictionSystJointDemo::PredictionSystJointDemo(), UnfoldAllVars(), and ana::PredictionSystNueSecondAna::Wrapped().

311  {
312  fgMap.clear();
313  fgMapF.clear();
314  fgMap2D.clear();
315  fgMap2F.clear();
316  fgMap3D.clear();
317  fgEstMemUsage = 0;
318  fgOut = 0;
319  fgIn = 0;
320  }
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:76
static long fgEstMemUsage
Definition: HistCache.h:82
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:75
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:77
static int fgOut
Definition: HistCache.h:80
static std::multimap< std::pair< int, int >, std::unique_ptr< TH3D > > fgMap3D
Definition: HistCache.h:78
static int fgIn
Definition: HistCache.h:80
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:74
TH1D * ana::HistCache::Copy ( const TH1D *  h)
static
TH1F * ana::HistCache::Copy ( const TH1F *  h)
static

Definition at line 183 of file HistCache.cxx.

References demo3::h, NewF(), and runNovaSAM::ret.

184  {
185  TH1F* ret = NewF(h->GetTitle(), h->GetXaxis());
186  *ret = *h;
187  return ret;
188  }
static TH1F * NewF(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:46
h
Definition: demo3.py:41
TH2D * ana::HistCache::Copy ( const TH2D *  h)
static

Definition at line 191 of file HistCache.cxx.

References demo3::h, NewTH2D(), and runNovaSAM::ret.

192  {
193  TH2D* ret = NewTH2D(h->GetTitle(), h->GetXaxis(), h->GetYaxis());
194  *ret = *h;
195  return ret;
196  }
static TH2D * NewTH2D(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:80
h
Definition: demo3.py:41
TH2F * ana::HistCache::Copy ( const TH2F *  h)
static

Definition at line 199 of file HistCache.cxx.

References demo3::h, NewTH2F(), and runNovaSAM::ret.

200  {
201  TH2F* ret = NewTH2F(h->GetTitle(), h->GetXaxis(), h->GetYaxis());
202  *ret = *h;
203  return ret;
204  }
static TH2F * NewTH2F(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:92
h
Definition: demo3.py:41
TH3D * ana::HistCache::Copy ( const TH3D *  h)
static

Definition at line 207 of file HistCache.cxx.

References demo3::h, NewTH3D(), and runNovaSAM::ret.

208  {
209  TH3D* ret = NewTH3D(h->GetTitle(), h->GetXaxis(), h->GetYaxis(), h->GetZaxis());
210  *ret = *h;
211  return ret;
212  }
static TH3D * NewTH3D(const std::string &title, const Binning &xbins, const Binning &ybins, const Binning &zbins)
For TH3D.
Definition: HistCache.cxx:152
h
Definition: demo3.py:41
void ana::HistCache::Delete ( TH1D *&  h)
static

Definition at line 215 of file HistCache.cxx.

References CheckMemoryUse(), fgEstMemUsage, fgIn, fgMap, ana::Binning::FromTAxis(), and demo3::h.

Referenced by ana::CovarianceMatrix::BuildFullCovMx(), ana::OscCovMxExperiment::ChiSq(), ana::SingleSampleExperiment::ChiSq(), ana::CovMxExperiment::ChiSq(), ana::PredictionCombinePeriods::ComponentCC(), ana::PredictionInterp::ComponentDerivative(), ana::CovMxManager::CovMxManager(), ana::PredictionAddRock::Derivative(), ana::SingleSampleExperiment::Derivative(), DrawSurfacePoint(), ana::PredictionInterp::FitSumComponent(), ana::CovMxSurface::GetContours(), ana::PredictionNueRebinSA::Inflate(), ana::CovarianceMatrix::LoadFrom(), ana::BinnedLkhdExperiment::LogLikelihood(), MakeCovMx(), MakeFileSystMatrix(), MakeGENIEMatrix(), ana::PredictionExtendToPeripheral::MergePeripheral(), ana::PredictionExtendToPeripheral::MergePeripheralOsc(), ana::OscCurve::operator=(), ana::Ratio::operator=(), ana::ReweightableSpectrum::operator=(), ana::OscillatableSpectrum::operator=(), ana::Spectrum::operator=(), ana::OscillatableSpectrum::Oscillated(), ana::PredictionCombinePeriods::PredictComponentSyst(), ana::PredictionNumuFAHadE::PredictComponentSyst(), ana::CovarianceMatrix::PredictCovMx(), ana::PredictionScaleComp::PredictSyst(), ana::Ratio::Ratio(), ana::PredictionNueRebinSA::Reduce(), ana::PredictionExtendToPeripheral::ReduceHelper(), ana::PredictionExtendToPeripheral::ReduceHelperNC(), ana::ReweightableSpectrum::ReweightToRecoSpectrum(), ana::ReweightableSpectrum::ReweightToTrueSpectrum(), ana::CovarianceMatrix::SaveTo(), ana::SpectrumStan::SpectrumStan(), ana::CovMxSurface::~CovMxSurface(), ana::OscCurve::~OscCurve(), ana::OscillatableSpectrum::~OscillatableSpectrum(), ana::Ratio::~Ratio(), ana::ReweightableSpectrum::~ReweightableSpectrum(), ana::SingleSampleExperiment::~SingleSampleExperiment(), and ana::Spectrum::~Spectrum().

216  {
217  if(!h) return;
218 
219  ++fgIn;
220 
221  fgMap.emplace(Binning::FromTAxis(h->GetXaxis()).ID(),
222  std::unique_ptr<TH1D>(h));
223 
224  fgEstMemUsage += 16*h->GetNbinsX();
225  CheckMemoryUse();
226 
227  h = 0;
228  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static long fgEstMemUsage
Definition: HistCache.h:82
static int fgIn
Definition: HistCache.h:80
static void CheckMemoryUse()
Definition: HistCache.cxx:294
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:74
h
Definition: demo3.py:41
void ana::HistCache::Delete ( TH1F *&  h)
static

Definition at line 231 of file HistCache.cxx.

References CheckMemoryUse(), fgEstMemUsage, fgIn, fgMapF, ana::Binning::FromTAxis(), and demo3::h.

232  {
233  if(!h) return;
234 
235  ++fgIn;
236 
237  fgMapF.emplace(Binning::FromTAxis(h->GetXaxis()).ID(),
238  std::unique_ptr<TH1F>(h));
239 
240  fgEstMemUsage += 8*h->GetNbinsX();
241  CheckMemoryUse();
242 
243  h = 0;
244  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static long fgEstMemUsage
Definition: HistCache.h:82
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:75
static int fgIn
Definition: HistCache.h:80
static void CheckMemoryUse()
Definition: HistCache.cxx:294
h
Definition: demo3.py:41
void ana::HistCache::Delete ( TH2D *&  h)
static

Definition at line 247 of file HistCache.cxx.

References CheckMemoryUse(), fgEstMemUsage, fgIn, fgMap2D, and ana::Binning::FromTAxis().

248  {
249  if(!h) return;
250 
251  ++fgIn;
252 
253  fgMap2D.emplace(std::pair<int, int>(Binning::FromTAxis(h->GetXaxis()).ID(), Binning::FromTAxis(h->GetYaxis()).ID()),
254  std::unique_ptr<TH2D>(h));
255 
256  fgEstMemUsage += 16*h->GetNbinsX()*h->GetNbinsY();
257  CheckMemoryUse();
258 
259  h = 0;
260  }
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:76
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static long fgEstMemUsage
Definition: HistCache.h:82
static int fgIn
Definition: HistCache.h:80
static void CheckMemoryUse()
Definition: HistCache.cxx:294
h
Definition: demo3.py:41
void ana::HistCache::Delete ( TH2F *&  h)
static

Definition at line 263 of file HistCache.cxx.

References CheckMemoryUse(), fgEstMemUsage, fgIn, fgMap2F, and ana::Binning::FromTAxis().

264  {
265  if(!h) return;
266 
267  ++fgIn;
268 
269  fgMap2F.emplace(std::pair<int, int>(Binning::FromTAxis(h->GetXaxis()).ID(), Binning::FromTAxis(h->GetYaxis()).ID()),
270  std::unique_ptr<TH2F>(h));
271 
272  fgEstMemUsage += 8*h->GetNbinsX()*h->GetNbinsY();
273  CheckMemoryUse();
274 
275  h = 0;
276  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static long fgEstMemUsage
Definition: HistCache.h:82
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:77
static int fgIn
Definition: HistCache.h:80
static void CheckMemoryUse()
Definition: HistCache.cxx:294
h
Definition: demo3.py:41
void ana::HistCache::Delete ( TH3D *&  h)
static

Definition at line 279 of file HistCache.cxx.

References CheckMemoryUse(), fgEstMemUsage, fgIn, fgMap3D, and ana::Binning::FromTAxis().

280  {
281  if(!h) return;
282 
283  ++fgIn;
284 
285  fgMap3D.emplace(std::pair<int, int>(Binning::FromTAxis(h->GetXaxis()).ID(), Binning::FromTAxis(h->GetYaxis()).ID()),
286  std::unique_ptr<TH3D>(h));
287 
288  fgEstMemUsage += 16*h->GetNbinsX()*h->GetNbinsY()*h->GetNbinsZ();
289  CheckMemoryUse();
290 
291  h = 0;
292  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static long fgEstMemUsage
Definition: HistCache.h:82
static std::multimap< std::pair< int, int >, std::unique_ptr< TH3D > > fgMap3D
Definition: HistCache.h:78
static int fgIn
Definition: HistCache.h:80
static void CheckMemoryUse()
Definition: HistCache.cxx:294
h
Definition: demo3.py:41
void ana::HistCache::LeakAll ( )
static

for debugging shutdown crashes

Definition at line 343 of file HistCache.cxx.

References ClearCache(), fgMap, fgMap2D, fgMap2F, fgMap3D, fgMapF, and it.

344  {
345  for(auto& it: fgMap) it.second.release();
346  for(auto& it: fgMapF) it.second.release();
347  for(auto& it: fgMap2D) it.second.release();
348  for(auto& it: fgMap2F) it.second.release();
349  for(auto& it: fgMap3D) it.second.release();
350 
351  ClearCache();
352  }
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:76
set< int >::iterator it
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:75
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:77
static std::multimap< std::pair< int, int >, std::unique_ptr< TH3D > > fgMap3D
Definition: HistCache.h:78
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:74
static void ClearCache()
Definition: HistCache.cxx:310
TH1D * ana::HistCache::New ( const std::string &  title,
const Binning bins 
)
static

Definition at line 24 of file HistCache.cxx.

References ana::bins, fgEstMemUsage, fgMap, fgOut, ana::Binning::ID(), it, ana::MakeTH1D(), ana::Binning::NBins(), runNovaSAM::ret, and ana::UniqueName().

Referenced by ana::Spectrum::ConstructHistogram(), Copy(), ana::FakeDecomp::Decompose(), ana::PredictionInterp::FitSumComponent(), GetCosmics(), ana::CovarianceMatrix::GetUniverse(), ana::PredictionNueRebinSA::Inflate(), ana::PredictionExtendToPeripheral::MergePeripheral(), New(), ana::OscCurve::OscCurve(), ana::Ratio::Ratio(), ana::PredictionNueRebinSA::Reduce(), ana::PredictionExtendToPeripheral::ReduceHelperNC(), ana::CovarianceMatrix::SaveTo(), ana::Spectrum::Spectrum(), SplitFakeData(), ana::Spectrum::ToTH1(), ana::ReweightableSpectrum::UnWeighted(), ana::ReweightableSpectrum::WeightedBy(), and ana::ReweightableSpectrum::WeightingVariable().

25  {
26  ++fgOut;
27 
28  // Look in the cache
29  auto it = fgMap.find(bins.ID());
30  if(it != fgMap.end()){
31  TH1D* ret = it->second.release();
32  fgMap.erase(it);
33  ret->Reset();
34  ret->SetTitle(title.c_str());
35 
36  fgEstMemUsage -= 16*bins.NBins();
37 
38  return ret;
39  }
40 
41  // If not, create a new one directly
42  return MakeTH1D(UniqueName().c_str(), title.c_str(), bins);
43  }
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:82
static int fgOut
Definition: HistCache.h:80
TH1D * MakeTH1D(const char *name, const char *title, const Binning &bins)
Definition: Utilities.cxx:333
const Binning bins
Definition: NumuCC_CPiBin.h:8
int NBins() const
Definition: Binning.h:25
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:74
int ID() const
Definition: Binning.h:40
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
TH1D * ana::HistCache::New ( const std::string &  title,
const TAxis *  bins 
)
static

Definition at line 68 of file HistCache.cxx.

References ana::Binning::FromTAxis(), and New().

69  {
70  return New(title, Binning::FromTAxis(bins));
71  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
const Binning bins
Definition: NumuCC_CPiBin.h:8
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:24
TH1F * ana::HistCache::NewF ( const std::string &  title,
const Binning bins 
)
static

Definition at line 46 of file HistCache.cxx.

References ana::bins, fgEstMemUsage, fgMapF, fgOut, ana::Binning::ID(), it, ana::MakeTH1F(), ana::Binning::NBins(), runNovaSAM::ret, and ana::UniqueName().

Referenced by ana::Spectrum::ConstructHistogram(), Copy(), NewF(), ana::ReweightableSpectrum::UnWeighted(), ana::ReweightableSpectrum::WeightedBy(), and ana::ReweightableSpectrum::WeightingVariable().

47  {
48  ++fgOut;
49 
50  // Look in the cache
51  auto it = fgMapF.find(bins.ID());
52  if(it != fgMapF.end()){
53  TH1F* ret = it->second.release();
54  fgMapF.erase(it);
55  ret->Reset();
56  ret->SetTitle(title.c_str());
57 
58  fgEstMemUsage -= 8*bins.NBins();
59 
60  return ret;
61  }
62 
63  // If not, create a new one directly
64  return MakeTH1F(UniqueName().c_str(), title.c_str(), bins);
65  }
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:82
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:75
static int fgOut
Definition: HistCache.h:80
const Binning bins
Definition: NumuCC_CPiBin.h:8
int NBins() const
Definition: Binning.h:25
int ID() const
Definition: Binning.h:40
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
TH1F * MakeTH1F(const char *name, const char *title, const Binning &bins)
Definition: Utilities.cxx:339
TH1F * ana::HistCache::NewF ( const std::string &  title,
const TAxis *  bins 
)
static

Definition at line 74 of file HistCache.cxx.

References ana::Binning::FromTAxis(), and NewF().

75  {
77  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static TH1F * NewF(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:46
const Binning bins
Definition: NumuCC_CPiBin.h:8
TH2D * ana::HistCache::NewTH2D ( const std::string &  title,
const Binning bins 
)
static

WARNING - the first two TH2D functions are kept for backward compatibility, they take kTrueEnergyBins on the y-axis.

Definition at line 80 of file HistCache.cxx.

References ana::kTrueEnergyBins.

Referenced by Copy(), ana::CovMxSurface::CovMxSurface(), ana::PredictionExtendToPeripheral::MergePeripheralOsc(), NewTH2D(), ana::OscillatableSpectrum::OscillatableSpectrum(), ana::PredictionNueRebinSA::Reduce(), ana::PredictionExtendToPeripheral::ReduceHelper(), ana::ReweightableSpectrum::ReweightableSpectrum(), and ana::ReweightableSpectrum::ToTH2().

81  {
83  }
static TH2D * NewTH2D(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:80
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:69
const Binning bins
Definition: NumuCC_CPiBin.h:8
TH2D * ana::HistCache::NewTH2D ( const std::string &  title,
const TAxis *  bins 
)
static

Definition at line 86 of file HistCache.cxx.

References ana::Binning::FromTAxis(), and NewTH2D().

87  {
89  }
static TH2D * NewTH2D(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:80
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
const Binning bins
Definition: NumuCC_CPiBin.h:8
TH2D * ana::HistCache::NewTH2D ( const std::string &  title,
const Binning xbins,
const Binning ybins 
)
static

The following two TH2D functions can have flexible y-axis.

Definition at line 104 of file HistCache.cxx.

References fgEstMemUsage, fgMap2D, fgOut, ana::Binning::ID(), it, ana::MakeTH2D(), ana::Binning::NBins(), runNovaSAM::ret, ana::UniqueName(), xbins, and ybins.

105  {
106  ++fgOut;
107  std::pair<int, int> IDs (xbins.ID(), ybins.ID());
108  auto it = fgMap2D.find(IDs);
109  if(it != fgMap2D.end()){
110  TH2D* ret = it->second.release();
111  fgMap2D.erase(it);
112  ret->Reset();
113  ret->SetTitle(title.c_str());
114  fgEstMemUsage -= 16*xbins.NBins()*ybins.NBins();
115  return ret;
116  }
117 
118  return MakeTH2D(UniqueName().c_str(), title.c_str(), xbins, ybins);
119  }
const Binning ybins
Definition: sa_fd_arrays.h:137
TH2D * MakeTH2D(const char *name, const char *title, const Binning &binsx, const Binning &binsy)
Definition: Utilities.cxx:345
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:76
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:82
static int fgOut
Definition: HistCache.h:80
const int xbins
Definition: MakePlots.C:82
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
TH2D * ana::HistCache::NewTH2D ( const std::string &  title,
const TAxis *  xbins,
const TAxis *  ybins 
)
static

Definition at line 140 of file HistCache.cxx.

References ana::Binning::FromTAxis(), and NewTH2D().

141  {
143  }
const Binning ybins
Definition: sa_fd_arrays.h:137
static TH2D * NewTH2D(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:80
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
const int xbins
Definition: MakePlots.C:82
TH2F * ana::HistCache::NewTH2F ( const std::string &  title,
const Binning bins 
)
static

Definition at line 92 of file HistCache.cxx.

References ana::kTrueEnergyBins.

Referenced by Copy(), NewTH2F(), ana::OscillatableSpectrum::OscillatableSpectrum(), and ana::ReweightableSpectrum::ReweightableSpectrum().

93  {
95  }
static TH2F * NewTH2F(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:92
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:69
const Binning bins
Definition: NumuCC_CPiBin.h:8
TH2F * ana::HistCache::NewTH2F ( const std::string &  title,
const TAxis *  bins 
)
static

Definition at line 98 of file HistCache.cxx.

References ana::Binning::FromTAxis(), and NewTH2F().

99  {
101  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static TH2F * NewTH2F(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:92
const Binning bins
Definition: NumuCC_CPiBin.h:8
TH2F * ana::HistCache::NewTH2F ( const std::string &  title,
const Binning xbins,
const Binning ybins 
)
static

The following two TH2F functions can have flexible y-axis.

Definition at line 122 of file HistCache.cxx.

References fgEstMemUsage, fgMap2F, fgOut, ana::Binning::ID(), it, ana::MakeTH2F(), ana::Binning::NBins(), runNovaSAM::ret, ana::UniqueName(), xbins, and ybins.

123  {
124  ++fgOut;
125  std::pair<int, int> IDs (xbins.ID(), ybins.ID());
126  auto it = fgMap2F.find(IDs);
127  if(it != fgMap2F.end()){
128  TH2F* ret = it->second.release();
129  fgMap2F.erase(it);
130  ret->Reset();
131  ret->SetTitle(title.c_str());
132  fgEstMemUsage -= 8*xbins.NBins()*ybins.NBins();
133  return ret;
134  }
135 
136  return MakeTH2F(UniqueName().c_str(), title.c_str(), xbins, ybins);
137  }
const Binning ybins
Definition: sa_fd_arrays.h:137
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:82
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:77
static int fgOut
Definition: HistCache.h:80
TH2F * MakeTH2F(const char *name, const char *title, const Binning &binsx, const Binning &binsy)
Definition: Utilities.cxx:353
const int xbins
Definition: MakePlots.C:82
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
TH2F * ana::HistCache::NewTH2F ( const std::string &  title,
const TAxis *  xbins,
const TAxis *  ybins 
)
static

Definition at line 146 of file HistCache.cxx.

References ana::Binning::FromTAxis(), and NewTH2F().

147  {
149  }
const Binning ybins
Definition: sa_fd_arrays.h:137
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static TH2F * NewTH2F(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:92
const int xbins
Definition: MakePlots.C:82
TH3D * ana::HistCache::NewTH3D ( const std::string &  title,
const Binning xbins,
const Binning ybins,
const Binning zbins 
)
static

For TH3D.

Definition at line 152 of file HistCache.cxx.

References fgEstMemUsage, fgMap3D, fgOut, ana::Binning::ID(), it, ana::MakeTH3D(), ana::Binning::NBins(), runNovaSAM::ret, ana::UniqueName(), xbins, ybins, and ana::zbins.

Referenced by Copy(), and ana::ReweightableSpectrum::ReweightableSpectrum().

153  {
154  ++fgOut;
155  std::pair<int, int> IDs (xbins.ID(), ybins.ID());
156  auto it = fgMap3D.find(IDs);
157  if(it != fgMap3D.end()){
158  TH3D* ret = it->second.release();
159  fgMap3D.erase(it);
160  ret->Reset();
161  ret->SetTitle(title.c_str());
162  fgEstMemUsage -= 16*xbins.NBins()*ybins.NBins()*zbins.NBins();
163  return ret;
164  }
165 
166  return MakeTH3D(UniqueName().c_str(), title.c_str(), xbins, ybins, zbins);
167  }
const Binning ybins
Definition: sa_fd_arrays.h:137
TH3D * MakeTH3D(const char *name, const char *title, const Binning &binsx, const Binning &binsy, const Binning &binsz)
Definition: Utilities.cxx:362
set< int >::iterator it
const Binning zbins
Definition: NumuCCIncBins.h:21
static long fgEstMemUsage
Definition: HistCache.h:82
static int fgOut
Definition: HistCache.h:80
static std::multimap< std::pair< int, int >, std::unique_ptr< TH3D > > fgMap3D
Definition: HistCache.h:78
const int xbins
Definition: MakePlots.C:82
int NBins() const
Definition: Binning.h:25
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
TH3D * ana::HistCache::NewTH3D ( const std::string &  title,
const TAxis *  xbins,
const TAxis *  ybins,
const TAxis *  zbins 
)
static

Definition at line 169 of file HistCache.cxx.

References ana::Binning::FromTAxis(), ana::MakeTH3D(), and ana::UniqueName().

170  {
172  }
const Binning ybins
Definition: sa_fd_arrays.h:137
TH3D * MakeTH3D(const char *name, const char *title, const Binning &binsx, const Binning &binsy, const Binning &binsz)
Definition: Utilities.cxx:362
const Binning zbins
Definition: NumuCCIncBins.h:21
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
const int xbins
Definition: MakePlots.C:82
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
void ana::HistCache::PrintStats ( )
static

Definition at line 323 of file HistCache.cxx.

References om::cout, allTimeWatchdog::endl, fgEstMemUsage, fgIn, fgMap, fgMap2D, fgMap2F, fgMap3D, fgMapF, fgOut, it, and caf_analysis::keys.

Referenced by CheckMemoryUse().

324  {
325  // Count number of unique keys
326  std::set<int> keys;
327  for(auto& it: fgMap) keys.insert(it.first);
328  for(auto& it: fgMapF) keys.insert(it.first);
329  std::set<std::pair<int, int>> keys2;
330  for(auto& it: fgMap2D) keys2.insert(it.first);
331  for(auto& it: fgMap2F) keys2.insert(it.first);
332  for(auto& it: fgMap3D) keys2.insert(it.first);
333 
334  std::cout << "Gave out " << fgOut << " histograms, got back "
335  << fgIn << " of them (" << fgOut-fgIn << " lost), in "
336  << keys.size()+keys2.size() << " different shapes." << std::endl
337  << "Holding " << fgMap.size()+fgMap2D.size()
338  << " histograms for an estimated memory usage of "
339  << fgEstMemUsage << " bytes." << std::endl;
340  }
keys
Reco plots.
Definition: caf_analysis.py:46
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:76
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:82
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:75
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:77
static int fgOut
Definition: HistCache.h:80
static std::multimap< std::pair< int, int >, std::unique_ptr< TH3D > > fgMap3D
Definition: HistCache.h:78
OStream cout
Definition: OStream.cxx:6
static int fgIn
Definition: HistCache.h:80
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:74

Member Data Documentation

long ana::HistCache::fgEstMemUsage = 0
staticprotected

Definition at line 82 of file HistCache.h.

Referenced by CheckMemoryUse(), ClearCache(), Delete(), New(), NewF(), NewTH2D(), NewTH2F(), NewTH3D(), and PrintStats().

int ana::HistCache::fgIn = 0
staticprotected

Definition at line 80 of file HistCache.h.

Referenced by ClearCache(), Delete(), and PrintStats().

std::multimap< int, std::unique_ptr< TH1D > > ana::HistCache::fgMap
staticprotected

Definition at line 74 of file HistCache.h.

Referenced by ClearCache(), Delete(), LeakAll(), New(), and PrintStats().

std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > ana::HistCache::fgMap2D
staticprotected

Definition at line 76 of file HistCache.h.

Referenced by ClearCache(), Delete(), LeakAll(), NewTH2D(), and PrintStats().

std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > ana::HistCache::fgMap2F
staticprotected

Definition at line 77 of file HistCache.h.

Referenced by ClearCache(), Delete(), LeakAll(), NewTH2F(), and PrintStats().

std::multimap< std::pair< int, int >, std::unique_ptr< TH3D > > ana::HistCache::fgMap3D
staticprotected

Definition at line 78 of file HistCache.h.

Referenced by ClearCache(), Delete(), LeakAll(), NewTH3D(), and PrintStats().

std::multimap< int, std::unique_ptr< TH1F > > ana::HistCache::fgMapF
staticprotected

Definition at line 75 of file HistCache.h.

Referenced by ClearCache(), Delete(), LeakAll(), NewF(), and PrintStats().

int ana::HistCache::fgOut = 0
staticprotected

Definition at line 80 of file HistCache.h.

Referenced by ClearCache(), New(), NewF(), NewTH2D(), NewTH2F(), NewTH3D(), and PrintStats().


The documentation for this class was generated from the following files: