ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
LWBinLabels Class Reference

#include <LWBinLabels.h>

Collaboration diagram for LWBinLabels:

Public Member Functions

 LWBinLabels ()
 
 ~LWBinLabels ()
 
const char * getBinLabel (unsigned bin) const
 
void setBinLabel (unsigned bin, const char *label)
 
void apply (TAxis *) const
 
unsigned size () const
 

Private Types

typedef std::pair< unsigned, char * > Entry
 

Private Member Functions

 LWBinLabels (const LWBinLabels &)
 
LWBinLabelsoperator= (const LWBinLabels &)
 
void grow ()
 

Static Private Member Functions

static bool cmp (const Entry &e1, const Entry &e2)
 

Private Attributes

unsigned m_size
 
unsigned m_allocated
 
Entrym_list
 

Detailed Description

Definition at line 25 of file LWBinLabels.h.

Member Typedef Documentation

◆ Entry

typedef std::pair<unsigned,char*> LWBinLabels::Entry
private

Definition at line 43 of file LWBinLabels.h.

Constructor & Destructor Documentation

◆ LWBinLabels() [1/2]

LWBinLabels::LWBinLabels ( )

Definition at line 22 of file LWBinLabels.cxx.

23  : m_size(0),
24  m_allocated(4),
25  m_list(LWPools::acquire<Entry>(4))
26 {
27 }

◆ ~LWBinLabels()

LWBinLabels::~LWBinLabels ( )

Definition at line 30 of file LWBinLabels.cxx.

31 {
32  for (unsigned i = 0; i < m_size; ++i)
34  LWPools::release<Entry>(m_list,m_allocated);
35 }

◆ LWBinLabels() [2/2]

LWBinLabels::LWBinLabels ( const LWBinLabels )
private

Member Function Documentation

◆ apply()

void LWBinLabels::apply ( TAxis *  a) const

Definition at line 38 of file LWBinLabels.cxx.

39 {
40  for (unsigned i = 0; i < m_size; ++i) {
41  Entry&e = m_list[i];
42  a->SetBinLabel(e.first,e.second);
43  }
44 }

◆ cmp()

static bool LWBinLabels::cmp ( const Entry e1,
const Entry e2 
)
inlinestaticprivate

Definition at line 46 of file LWBinLabels.h.

46 { return e1.first<e2.first; }

◆ getBinLabel()

const char * LWBinLabels::getBinLabel ( unsigned  bin) const

Definition at line 47 of file LWBinLabels.cxx.

48 {
49  const Entry* list = m_list;
50  unsigned i = std::lower_bound(list,list+m_size,Entry(bin,0),cmp)-list;
51  if (i>=m_size)
52  return "";
53  const Entry & e = m_list[i];
54  return e.first == bin && e.second ? e.second : "";
55 }

◆ grow()

void LWBinLabels::grow ( )
private

Definition at line 99 of file LWBinLabels.cxx.

100 {
101  assert(m_allocated==m_size);
102  unsigned l = std::min<unsigned>(m_size+4,static_cast<unsigned>(m_allocated*1.5+0.5));
103  Entry * new_list = LWPools::acquire<Entry>(l);
104  std::copy (m_list, m_list + m_size, new_list);
105  LWPools::release<Entry>(m_list,m_allocated);
106  m_list = new_list;
107  m_allocated = l;
108 }

◆ operator=()

LWBinLabels& LWBinLabels::operator= ( const LWBinLabels )
private

◆ setBinLabel()

void LWBinLabels::setBinLabel ( unsigned  bin,
const char *  label 
)

Definition at line 58 of file LWBinLabels.cxx.

59 {
60  //Usually we just need to append:
61  if (m_size==0||bin>m_list[m_size-1].first) {
62  if (m_allocated==m_size)
63  grow();
64  assert(m_allocated>m_size);
65  Entry& e = m_list[m_size];
66  e.first = bin;
67  e.second = 0;
69  ++m_size;
70  return;
71  }
72 
73  //Ok, we can't just append, so we must peek inside:
74  unsigned i_lower = std::lower_bound(m_list,m_list+m_size,Entry(bin,0),cmp)-m_list;
75 
76  if (m_list[i_lower].first==bin) {
77  //We are updating an existing entry:
79  return;
80  }
81 
82  //We must insert in the middle!
83  if (m_allocated==m_size)
84  grow();
85 
86  //Move higher ones up:
87  for (unsigned i = m_size; i>i_lower; --i)
88  m_list[i] = m_list[i-1];
89 
90  //Insert:
91  Entry e(bin,0);
93  m_list[i_lower] = e;
94  ++m_size;
95 }

◆ size()

unsigned LWBinLabels::size ( ) const
inline

Definition at line 35 of file LWBinLabels.h.

35 { return m_size; }

Member Data Documentation

◆ m_allocated

unsigned LWBinLabels::m_allocated
private

Definition at line 42 of file LWBinLabels.h.

◆ m_list

Entry* LWBinLabels::m_list
private

Definition at line 44 of file LWBinLabels.h.

◆ m_size

unsigned LWBinLabels::m_size
private

Definition at line 41 of file LWBinLabels.h.


The documentation for this class was generated from the following files:
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
egammaEnergyPositionAllSamples::e1
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
LWStrUtils::releaseString
static void releaseString(char *&c)
Definition: LWStrUtils.h:70
bin
Definition: BinsDiffFromStripMedian.h:43
LWBinLabels::m_list
Entry * m_list
Definition: LWBinLabels.h:44
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
LWBinLabels::m_size
unsigned m_size
Definition: LWBinLabels.h:41
LWBinLabels::Entry
std::pair< unsigned, char * > Entry
Definition: LWBinLabels.h:43
lumiFormat.i
int i
Definition: lumiFormat.py:92
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
LWStrUtils::setStringFromInput
static void setStringFromInput(const char *input, char *&target)
Definition: LWStrUtils.h:58
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
a
TList * a
Definition: liststreamerinfos.cxx:10
egammaEnergyPositionAllSamples::e2
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
DeMoScan.first
bool first
Definition: DeMoScan.py:534
LWBinLabels::grow
void grow()
Definition: LWBinLabels.cxx:99
LWBinLabels::cmp
static bool cmp(const Entry &e1, const Entry &e2)
Definition: LWBinLabels.h:46
calibdata.copy
bool copy
Definition: calibdata.py:27
LWBinLabels::m_allocated
unsigned m_allocated
Definition: LWBinLabels.h:42