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-08-14/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 TH1D * Copy (const TH1D *h, const Binning &bins)
 
static TH1F * Copy (const TH1F *h)
 
static TH1F * Copy (const TH1F *h, const Binning &bins)
 
static TH2D * NewTH2D (const std::string &title, const Binning &xbins, const Binning &ybins)
 
static TH2D * NewTH2D (const std::string &title, const TAxis *xbins, const TAxis *ybins)
 
static TH2F * NewTH2F (const std::string &title, const Binning &xbins, const Binning &ybins)
 
static TH2F * NewTH2F (const std::string &title, const TAxis *xbins, const TAxis *ybins)
 
static TH2D * Copy (const TH2D *h)
 
static TH2D * Copy (const TH2D *h, const Binning &binsX, const Binning &binsY)
 
static TH2F * Copy (const TH2F *h)
 
static TH2F * Copy (const TH2F *h, const Binning &binsX, const Binning &binsY)
 
static void Delete (TH1D *&h)
 
static void Delete (TH1D *&h, const Binning &bins)
 
static void Delete (TH1F *&h)
 
static void Delete (TH1F *&h, const Binning &bins)
 
static void Delete (TH2D *&h)
 
static void Delete (TH2D *&h, const Binning &binsX, const Binning &binsY)
 
static void Delete (TH2F *&h)
 
static void Delete (TH2F *&h, const Binning &binsX, const Binning &binsY)
 
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 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 26 of file HistCache.h.

Member Function Documentation

void ana::HistCache::CheckMemoryUse ( )
staticprotected

Definition at line 344 of file HistCache.cxx.

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

Referenced by Delete().

345  {
346  if(fgEstMemUsage > 500l*1024*1024){
347  std::cerr << "Warning! HistCache memory usage exceeds 500MB. "
348  << "That probably means histograms are being returned "
349  << "to the cache that weren't originally handed out by it. "
350  << std::endl;
351  PrintStats();
352  std::cerr << "Now clearing cache. This could take a long time..."
353  << std::endl;
354  ClearCache();
355  std::cerr << "Done clearing cache" << std::endl;
356  }
357  }
OStream cerr
Definition: OStream.cxx:7
static long fgEstMemUsage
Definition: HistCache.h:74
static void PrintStats()
Definition: HistCache.cxx:372
static void ClearCache()
Definition: HistCache.cxx:360
void ana::HistCache::ClearCache ( )
static

Definition at line 360 of file HistCache.cxx.

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

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

361  {
362  fgMap.clear();
363  fgMapF.clear();
364  fgMap2D.clear();
365  fgMap2F.clear();
366  fgEstMemUsage = 0;
367  fgOut = 0;
368  fgIn = 0;
369  }
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:69
static long fgEstMemUsage
Definition: HistCache.h:74
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:68
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:70
static int fgOut
Definition: HistCache.h:72
static int fgIn
Definition: HistCache.h:72
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:67
TH1D * ana::HistCache::Copy ( const TH1D *  h)
static
TH1D * ana::HistCache::Copy ( const TH1D *  h,
const Binning bins 
)
static

Definition at line 147 of file HistCache.cxx.

References ana::assert(), ana::bins, make_syst_table_plots::h, ana::Binning::NBins(), New(), and runNovaSAM::ret.

148  {
149  assert(bins.NBins() == h->GetNbinsX());
150 
151  TH1D* ret = New(h->GetTitle(), bins);
152  *ret = *h;
153  ret->SetDirectory(0);
154  return ret;
155  }
const Binning bins
Definition: NumuCC_CPiBin.h:8
int NBins() const
Definition: Binning.h:25
assert(nhit_max >=nhit_nbins)
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:22
TH1F * ana::HistCache::Copy ( const TH1F *  h)
static

Definition at line 158 of file HistCache.cxx.

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

159  {
160  TH1F* ret = NewF(h->GetTitle(), h->GetXaxis());
161  *ret = *h;
162  ret->SetDirectory(0);
163  return ret;
164  }
static TH1F * NewF(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:46
TH1F * ana::HistCache::Copy ( const TH1F *  h,
const Binning bins 
)
static

Definition at line 167 of file HistCache.cxx.

References ana::assert(), ana::bins, make_syst_table_plots::h, ana::Binning::NBins(), NewF(), and runNovaSAM::ret.

168  {
169  assert(bins.NBins() == h->GetNbinsX());
170 
171  TH1F* ret = NewF(h->GetTitle(), bins);
172  *ret = *h;
173  ret->SetDirectory(0);
174  return ret;
175  }
static TH1F * NewF(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:46
const Binning bins
Definition: NumuCC_CPiBin.h:8
int NBins() const
Definition: Binning.h:25
assert(nhit_max >=nhit_nbins)
TH2D * ana::HistCache::Copy ( const TH2D *  h)
static

Definition at line 178 of file HistCache.cxx.

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

179  {
180  TH2D* ret = NewTH2D(h->GetTitle(), h->GetXaxis(), h->GetYaxis());
181  *ret = *h;
182  ret->SetDirectory(0);
183  return ret;
184  }
static TH2D * NewTH2D(const std::string &title, const Binning &xbins, const Binning &ybins)
Definition: HistCache.cxx:82
TH2D * ana::HistCache::Copy ( const TH2D *  h,
const Binning binsX,
const Binning binsY 
)
static

Definition at line 187 of file HistCache.cxx.

References ana::assert(), make_syst_table_plots::h, ana::Binning::NBins(), NewTH2D(), and runNovaSAM::ret.

188  {
189  assert(binsX.NBins() == h->GetNbinsX());
190  assert(binsY.NBins() == h->GetNbinsY());
191 
192  TH2D* ret = NewTH2D(h->GetTitle(), binsX, binsY);
193  *ret = *h;
194  ret->SetDirectory(0);
195  return ret;
196  }
static TH2D * NewTH2D(const std::string &title, const Binning &xbins, const Binning &ybins)
Definition: HistCache.cxx:82
assert(nhit_max >=nhit_nbins)
TH2F * ana::HistCache::Copy ( const TH2F *  h)
static

Definition at line 199 of file HistCache.cxx.

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

200  {
201  TH2F* ret = NewTH2F(h->GetTitle(), h->GetXaxis(), h->GetYaxis());
202  *ret = *h;
203  ret->SetDirectory(0);
204  return ret;
205  }
static TH2F * NewTH2F(const std::string &title, const Binning &xbins, const Binning &ybins)
Definition: HistCache.cxx:104
TH2F * ana::HistCache::Copy ( const TH2F *  h,
const Binning binsX,
const Binning binsY 
)
static

Definition at line 208 of file HistCache.cxx.

References ana::assert(), make_syst_table_plots::h, ana::Binning::NBins(), NewTH2F(), and runNovaSAM::ret.

209  {
210  assert(binsX.NBins() == h->GetNbinsX());
211  assert(binsY.NBins() == h->GetNbinsY());
212 
213  TH2F* ret = NewTH2F(h->GetTitle(), binsX, binsY);
214  *ret = *h;
215  ret->SetDirectory(0);
216  return ret;
217  }
static TH2F * NewTH2F(const std::string &title, const Binning &xbins, const Binning &ybins)
Definition: HistCache.cxx:104
assert(nhit_max >=nhit_nbins)
void ana::HistCache::Delete ( TH1D *&  h)
static

Definition at line 220 of file HistCache.cxx.

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

Referenced by ana::PredictionSyst3Flavor2020::AddNormSyst(), ana::CovarianceMatrix::BuildFullCovMx(), ana::OscCovMxExperiment::ChiSq(), ana::SingleSampleExperiment::ChiSq(), ana::CovMxExperiment::ChiSq(), ana::PredictionCombinePeriods::ComponentCC(), ana::CovMxManager::CovMxManager(), Delete(), ana::PredictionAddRock::Derivative(), ana::SingleSampleExperiment::Derivative(), DrawSurfacePoint(), ana::PredictionInterp::FitSumComponent(), ana::CovMxSurface::GetContours(), ana::CovarianceMatrix::LoadFrom(), ana::SingleSampleExperiment::LogLikelihood(), MakeCovMx(), MakeFileSystMatrix(), MakeGENIEMatrix(), ana::PredictionExtendToPeripheral::MergePeripheral(), ana::PredictionExtendToPeripheral::MergePeripheralOsc(), ana::Ratio::operator=(), ana::ReweightableSpectrum::operator=(), ana::OscillatableSpectrum::operator=(), ana::Spectrum::operator=(), ana::OscillatableSpectrum::Oscillated(), ana::SingleSampleExperiment::PredHistIncCosmics(), ana::PredictionCombinePeriods::PredictComponentSyst(), ana::CovarianceMatrix::PredictCovMx(), ana::PredictionScaleComp::PredictSyst(), ana::Ratio::Ratio(), ana::PredictionExtendToPeripheral::ReduceHelper(), ana::PredictionExtendToPeripheral::ReduceHelperNC(), ana::ReweightableSpectrum::ReweightToRecoSpectrum(), ana::ReweightableSpectrum::ReweightToTrueSpectrum(), ana::CovarianceMatrix::SaveTo(), ana::SingleSampleExperiment::SingleSampleExperiment(), 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().

221  {
222  if(!h) return;
223 
224  assert(!h->GetDirectory());
225 
226  HistCache::Delete(h, Binning::FromTAxis(h->GetXaxis()));
227  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static void Delete(TH1D *&h)
Definition: HistCache.cxx:220
assert(nhit_max >=nhit_nbins)
void ana::HistCache::Delete ( TH1D *&  h,
const Binning bins 
)
static

Definition at line 230 of file HistCache.cxx.

References ana::assert(), CheckMemoryUse(), fgEstMemUsage, fgIn, fgMap, make_syst_table_plots::h, ana::Binning::ID(), and ana::Binning::NBins().

231  {
232  if(!h) return;
233 
234  assert(!h->GetDirectory());
235 
236  assert(h->GetNbinsX() == bins.NBins());
237 
238  ++fgIn;
239 
240  fgMap.emplace(bins.ID(), std::unique_ptr<TH1D>(h));
241 
242  fgEstMemUsage += 16*h->GetNbinsX();
243  CheckMemoryUse();
244 
245  h = 0;
246  }
static long fgEstMemUsage
Definition: HistCache.h:74
const Binning bins
Definition: NumuCC_CPiBin.h:8
static int fgIn
Definition: HistCache.h:72
int NBins() const
Definition: Binning.h:25
static void CheckMemoryUse()
Definition: HistCache.cxx:344
assert(nhit_max >=nhit_nbins)
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:67
int ID() const
Definition: Binning.h:40
void ana::HistCache::Delete ( TH1F *&  h)
static

Definition at line 249 of file HistCache.cxx.

References ana::assert(), Delete(), and ana::Binning::FromTAxis().

250  {
251  if(!h) return;
252 
253  assert(!h->GetDirectory());
254 
255  HistCache::Delete(h, Binning::FromTAxis(h->GetXaxis()));
256  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static void Delete(TH1D *&h)
Definition: HistCache.cxx:220
assert(nhit_max >=nhit_nbins)
void ana::HistCache::Delete ( TH1F *&  h,
const Binning bins 
)
static

Definition at line 259 of file HistCache.cxx.

References ana::assert(), CheckMemoryUse(), fgEstMemUsage, fgIn, fgMapF, make_syst_table_plots::h, ana::Binning::ID(), and ana::Binning::NBins().

260  {
261  if(!h) return;
262 
263  assert(!h->GetDirectory());
264 
265  assert(bins.NBins() == h->GetNbinsX());
266 
267  ++fgIn;
268 
269  fgMapF.emplace(bins.ID(), std::unique_ptr<TH1F>(h));
270 
271  fgEstMemUsage += 8*h->GetNbinsX();
272  CheckMemoryUse();
273 
274  h = 0;
275  }
static long fgEstMemUsage
Definition: HistCache.h:74
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:68
const Binning bins
Definition: NumuCC_CPiBin.h:8
static int fgIn
Definition: HistCache.h:72
int NBins() const
Definition: Binning.h:25
static void CheckMemoryUse()
Definition: HistCache.cxx:344
assert(nhit_max >=nhit_nbins)
int ID() const
Definition: Binning.h:40
void ana::HistCache::Delete ( TH2D *&  h)
static

Definition at line 278 of file HistCache.cxx.

References ana::assert(), Delete(), and ana::Binning::FromTAxis().

279  {
280  if(!h) return;
281 
282  assert(!h->GetDirectory());
283 
285  Binning::FromTAxis(h->GetXaxis()),
286  Binning::FromTAxis(h->GetYaxis()));
287  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static void Delete(TH1D *&h)
Definition: HistCache.cxx:220
assert(nhit_max >=nhit_nbins)
void ana::HistCache::Delete ( TH2D *&  h,
const Binning binsX,
const Binning binsY 
)
static

Definition at line 290 of file HistCache.cxx.

References ana::assert(), CheckMemoryUse(), fgEstMemUsage, fgIn, fgMap2D, ana::Binning::ID(), make_pair(), and ana::Binning::NBins().

291  {
292  if(!h) return;
293 
294  assert(!h->GetDirectory());
295 
296  assert(binsX.NBins() == h->GetNbinsX());
297  assert(binsY.NBins() == h->GetNbinsY());
298 
299  ++fgIn;
300 
301  fgMap2D.emplace(std::make_pair(binsX.ID(), binsY.ID()),
302  std::unique_ptr<TH2D>(h));
303 
304  fgEstMemUsage += 16*h->GetNbinsX()*h->GetNbinsY();
305  CheckMemoryUse();
306 
307  h = 0;
308  }
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:69
static long fgEstMemUsage
Definition: HistCache.h:74
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:335
static int fgIn
Definition: HistCache.h:72
static void CheckMemoryUse()
Definition: HistCache.cxx:344
assert(nhit_max >=nhit_nbins)
void ana::HistCache::Delete ( TH2F *&  h)
static

Definition at line 311 of file HistCache.cxx.

References ana::assert(), Delete(), and ana::Binning::FromTAxis().

312  {
313  if(!h) return;
314 
315  assert(!h->GetDirectory());
316 
318  Binning::FromTAxis(h->GetXaxis()),
319  Binning::FromTAxis(h->GetYaxis()));
320  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static void Delete(TH1D *&h)
Definition: HistCache.cxx:220
assert(nhit_max >=nhit_nbins)
void ana::HistCache::Delete ( TH2F *&  h,
const Binning binsX,
const Binning binsY 
)
static

Definition at line 323 of file HistCache.cxx.

References ana::assert(), CheckMemoryUse(), fgEstMemUsage, fgIn, fgMap2F, ana::Binning::ID(), make_pair(), and ana::Binning::NBins().

324  {
325  if(!h) return;
326 
327  assert(!h->GetDirectory());
328 
329  assert(binsX.NBins() == h->GetNbinsX());
330  assert(binsY.NBins() == h->GetNbinsY());
331 
332  ++fgIn;
333 
334  fgMap2F.emplace(std::make_pair(binsX.ID(), binsY.ID()),
335  std::unique_ptr<TH2F>(h));
336 
337  fgEstMemUsage += 8*h->GetNbinsX()*h->GetNbinsY();
338  CheckMemoryUse();
339 
340  h = 0;
341  }
static long fgEstMemUsage
Definition: HistCache.h:74
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:335
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:70
static int fgIn
Definition: HistCache.h:72
static void CheckMemoryUse()
Definition: HistCache.cxx:344
assert(nhit_max >=nhit_nbins)
void ana::HistCache::LeakAll ( )
static

for debugging shutdown crashes

Definition at line 391 of file HistCache.cxx.

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

392  {
393  for(auto& it: fgMap) it.second.release();
394  for(auto& it: fgMapF) it.second.release();
395  for(auto& it: fgMap2D) it.second.release();
396  for(auto& it: fgMap2F) it.second.release();
397 
398  ClearCache();
399  }
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:69
set< int >::iterator it
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:68
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:70
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:67
static void ClearCache()
Definition: HistCache.cxx:360
TH1D * ana::HistCache::New ( const std::string &  title,
const Binning bins 
)
static

Definition at line 22 of file HistCache.cxx.

References ana::assert(), 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::PredictionExtendToPeripheral::MergePeripheral(), New(), ana::OscCurve::OscCurve(), ana::Ratio::Ratio(), ana::PredictionExtendToPeripheral::ReduceHelperNC(), ana::CovarianceMatrix::SaveTo(), ana::Spectrum::Spectrum(), SplitFakeData(), ana::Spectrum::ToTH1(), ana::ReweightableSpectrum::UnWeighted(), ana::ReweightableSpectrum::WeightedBy(), and ana::ReweightableSpectrum::WeightingVariable().

23  {
24  ++fgOut;
25 
26  // Look in the cache
27  auto it = fgMap.find(bins.ID());
28  if(it != fgMap.end()){
29  TH1D* ret = it->second.release();
30  fgMap.erase(it);
31  ret->Reset();
32  ret->SetTitle(title.c_str());
33 
34  fgEstMemUsage -= 16*bins.NBins();
35 
36  assert(bins.NBins() == ret->GetNbinsX());
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:74
static int fgOut
Definition: HistCache.h:72
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
assert(nhit_max >=nhit_nbins)
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:67
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 70 of file HistCache.cxx.

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

71  {
72  return New(title, Binning::FromTAxis(bins));
73  }
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:22
TH1F * ana::HistCache::NewF ( const std::string &  title,
const Binning bins 
)
static

Definition at line 46 of file HistCache.cxx.

References ana::assert(), 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  assert(bins.NBins() == ret->GetNbinsX());
61 
62  return ret;
63  }
64 
65  // If not, create a new one directly
66  return MakeTH1F(UniqueName().c_str(), title.c_str(), bins);
67  }
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:74
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:68
static int fgOut
Definition: HistCache.h:72
const Binning bins
Definition: NumuCC_CPiBin.h:8
int NBins() const
Definition: Binning.h:25
assert(nhit_max >=nhit_nbins)
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 76 of file HistCache.cxx.

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

77  {
79  }
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 xbins,
const Binning ybins 
)
static

Definition at line 82 of file HistCache.cxx.

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

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

83  {
84  ++fgOut;
85  std::pair<int, int> IDs (xbins.ID(), ybins.ID());
86  auto it = fgMap2D.find(IDs);
87  if(it != fgMap2D.end()){
88  TH2D* ret = it->second.release();
89  fgMap2D.erase(it);
90  ret->Reset();
91  ret->SetTitle(title.c_str());
92  fgEstMemUsage -= 16*xbins.NBins()*ybins.NBins();
93 
94  assert(xbins.NBins() == ret->GetNbinsX());
95  assert(ybins.NBins() == ret->GetNbinsY());
96 
97  return ret;
98  }
99 
100  return MakeTH2D(UniqueName().c_str(), title.c_str(), xbins, ybins);
101  }
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:69
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:74
static int fgOut
Definition: HistCache.h:72
const Binning ybins
const int xbins
Definition: MakePlots.C:82
assert(nhit_max >=nhit_nbins)
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 126 of file HistCache.cxx.

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

127  {
129  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static TH2D * NewTH2D(const std::string &title, const Binning &xbins, const Binning &ybins)
Definition: HistCache.cxx:82
const Binning ybins
const int xbins
Definition: MakePlots.C:82
TH2F * ana::HistCache::NewTH2F ( const std::string &  title,
const Binning xbins,
const Binning ybins 
)
static

Definition at line 104 of file HistCache.cxx.

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

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

105  {
106  ++fgOut;
107  std::pair<int, int> IDs (xbins.ID(), ybins.ID());
108  auto it = fgMap2F.find(IDs);
109  if(it != fgMap2F.end()){
110  TH2F* ret = it->second.release();
111  fgMap2F.erase(it);
112  ret->Reset();
113  ret->SetTitle(title.c_str());
114  fgEstMemUsage -= 8*xbins.NBins()*ybins.NBins();
115 
116  assert(xbins.NBins() == ret->GetNbinsX());
117  assert(ybins.NBins() == ret->GetNbinsY());
118 
119  return ret;
120  }
121 
122  return MakeTH2F(UniqueName().c_str(), title.c_str(), xbins, ybins);
123  }
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:74
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:70
static int fgOut
Definition: HistCache.h:72
TH2F * MakeTH2F(const char *name, const char *title, const Binning &binsx, const Binning &binsy)
Definition: Utilities.cxx:353
const Binning ybins
const int xbins
Definition: MakePlots.C:82
assert(nhit_max >=nhit_nbins)
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 132 of file HistCache.cxx.

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

133  {
135  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static TH2F * NewTH2F(const std::string &title, const Binning &xbins, const Binning &ybins)
Definition: HistCache.cxx:104
const Binning ybins
const int xbins
Definition: MakePlots.C:82
void ana::HistCache::PrintStats ( )
static

Definition at line 372 of file HistCache.cxx.

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

Referenced by CheckMemoryUse().

373  {
374  // Count number of unique keys
375  std::set<int> keys;
376  for(auto& it: fgMap) keys.insert(it.first);
377  for(auto& it: fgMapF) keys.insert(it.first);
378  std::set<std::pair<int, int>> keys2;
379  for(auto& it: fgMap2D) keys2.insert(it.first);
380  for(auto& it: fgMap2F) keys2.insert(it.first);
381 
382  std::cout << "Gave out " << fgOut << " histograms, got back "
383  << fgIn << " of them (" << fgOut-fgIn << " lost), in "
384  << keys.size()+keys2.size() << " different shapes." << std::endl
385  << "Holding " << fgMap.size()+fgMap2D.size()
386  << " histograms for an estimated memory usage of "
387  << fgEstMemUsage << " bytes." << std::endl;
388  }
keys
Reco plots.
Definition: caf_analysis.py:46
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2D > > fgMap2D
Definition: HistCache.h:69
set< int >::iterator it
static long fgEstMemUsage
Definition: HistCache.h:74
static std::multimap< int, std::unique_ptr< TH1F > > fgMapF
Definition: HistCache.h:68
static std::multimap< std::pair< int, int >, std::unique_ptr< TH2F > > fgMap2F
Definition: HistCache.h:70
static int fgOut
Definition: HistCache.h:72
OStream cout
Definition: OStream.cxx:6
static int fgIn
Definition: HistCache.h:72
static std::multimap< int, std::unique_ptr< TH1D > > fgMap
Definition: HistCache.h:67

Member Data Documentation

long ana::HistCache::fgEstMemUsage = 0
staticprotected

Definition at line 74 of file HistCache.h.

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

int ana::HistCache::fgIn = 0
staticprotected

Definition at line 72 of file HistCache.h.

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

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

Definition at line 67 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 69 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 70 of file HistCache.h.

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

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

Definition at line 68 of file HistCache.h.

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

int ana::HistCache::fgOut = 0
staticprotected

Definition at line 72 of file HistCache.h.

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


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