LDMX Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
framework::HistogramPool Class Reference

Singleton class used to create and pool histograms. More...

#include <Histograms.h>

Public Member Functions

 HistogramPool (HistogramPool const &)=delete
 Hide copy constructor.
 
void operator= (HistogramPool const &)=delete
 Hide assignment operator.
 
void insert (const std::string &name, TH1 *hist)
 Insert a histogram into the pool.
 
TH1 * get (const std::string &name)
 Get a histogram using its name.
 

Static Public Member Functions

static HistogramPoolgetInstance ()
 Access the single instance of HistogramPool by reference.
 

Private Member Functions

 HistogramPool ()
 Private constructor to prevent instantiation.
 

Private Attributes

std::unordered_map< std::string, TH1 * > histograms_
 Container for all histograms.
 

Detailed Description

Singleton class used to create and pool histograms.

Helpful for managing all those TH1 pointers by name instead of using variables.

Definition at line 27 of file Histograms.h.

Constructor & Destructor Documentation

◆ HistogramPool()

framework::HistogramPool::HistogramPool ( )
private

Private constructor to prevent instantiation.

Sets some style options as well.

Definition at line 19 of file Histograms.cxx.

19 {
20 gStyle->SetOptStat(1);
21 gStyle->SetGridColor(17);
22 gStyle->SetFrameBorderMode(0);
23 gStyle->SetTitleOffset(1.2, "yx");
24 gStyle->SetTitleFontSize(25);
25
26 gStyle->SetPadBottomMargin(0.1);
27 gStyle->SetPadTopMargin(0.01);
28 gStyle->SetPadLeftMargin(0.1);
29 gStyle->SetPadRightMargin(0.09);
30 gStyle->SetPadGridX(1);
31 gStyle->SetPadGridY(1);
32 gStyle->SetPadTickX(1);
33 gStyle->SetPadTickY(1);
34
35 gStyle->SetHistLineWidth(2);
36}

Member Function Documentation

◆ get()

TH1 * framework::HistogramPool::get ( const std::string &  name)

Get a histogram using its name.

Checks if histogram exists.

Returns
Retrieve the histogram named "name" from the pool.

Definition at line 46 of file Histograms.cxx.

46 {
47 auto histo = histograms_.find(name);
48 if (histo == histograms_.end()) {
49 EXCEPTION_RAISE("InvalidArg", "Histogram " + name + " not found in pool.");
50 }
51
52 return histograms_[name];
53}
std::unordered_map< std::string, TH1 * > histograms_
Container for all histograms.
Definition Histograms.h:30

References histograms_.

Referenced by framework::HistogramHelper::get().

◆ getInstance()

HistogramPool & framework::HistogramPool::getInstance ( )
static

Access the single instance of HistogramPool by reference.

Definition at line 38 of file Histograms.cxx.

38 {
39 // Create an instance of HistogramPool if needed
40 // Guarnteed to be destroyed, instantiaed on first use
41 static HistogramPool instance;
42
43 return instance;
44}
HistogramPool()
Private constructor to prevent instantiation.

Referenced by framework::HistogramHelper::create(), framework::HistogramHelper::create(), framework::HistogramHelper::create(), framework::HistogramHelper::create(), and framework::HistogramHelper::get().

◆ insert()

void framework::HistogramPool::insert ( const std::string &  name,
TH1 *  hist 
)
inline

Insert a histogram into the pool.

Note
Does not check for any doubling of names!

Definition at line 54 of file Histograms.h.

54{ histograms_[name] = hist; }

References histograms_.

Referenced by framework::HistogramHelper::create(), framework::HistogramHelper::create(), framework::HistogramHelper::create(), and framework::HistogramHelper::create().

Member Data Documentation

◆ histograms_

std::unordered_map<std::string, TH1*> framework::HistogramPool::histograms_
private

Container for all histograms.

Definition at line 30 of file Histograms.h.

Referenced by get(), and insert().


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