ATLAS Offline Software
Tools
LWHists
src
LWBinLabels.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
7
// //
8
// Implementation of class LWBinLabels //
9
// //
10
// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11
// Initial version: May 2009 //
12
// //
14
15
#include "
LWBinLabels.h
"
16
#include "
LWPools.h
"
17
#include "
LWStrUtils.h
"
18
#include "TAxis.h"
19
#include <algorithm>
20
21
//____________________________________________________________________
22
LWBinLabels::LWBinLabels
()
23
: m_size(0),
24
m_allocated(4),
25
m_list(
LWPools
::acquire<
Entry
>(4))
26
{
27
}
28
29
//____________________________________________________________________
30
LWBinLabels::~LWBinLabels
()
31
{
32
for
(
unsigned
i
= 0;
i
<
m_size
; ++
i
)
33
LWStrUtils::releaseString
(
m_list
[
i
].
second
);
34
LWPools::release<Entry>(
m_list
,
m_allocated
);
35
}
36
37
//____________________________________________________________________
38
void
LWBinLabels::apply
(TAxis*
a
)
const
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
}
45
46
//____________________________________________________________________
47
const
char
*
LWBinLabels::getBinLabel
(
unsigned
bin
)
const
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
}
56
57
//____________________________________________________________________
58
void
LWBinLabels::setBinLabel
(
unsigned
bin
,
const
char
*
label
)
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;
68
LWStrUtils::setStringFromInput
(
label
,
e
.second);
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:
78
LWStrUtils::setStringFromInput
(
label
,
m_list
[i_lower].
second
);
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);
92
LWStrUtils::setStringFromInput
(
label
,
e
.second);
93
m_list
[i_lower] =
e
;
94
++
m_size
;
95
}
96
97
98
//____________________________________________________________________
99
void
LWBinLabels::grow
()
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
}
python.SystemOfUnits.second
int second
Definition:
SystemOfUnits.py:120
LWPools.h
LWStrUtils.h
LWBinLabels::setBinLabel
void setBinLabel(unsigned bin, const char *label)
Definition:
LWBinLabels.cxx:58
PlotCalibFromCool.label
label
Definition:
PlotCalibFromCool.py:78
LWStrUtils::releaseString
static void releaseString(char *&c)
Definition:
LWStrUtils.h:70
LWPools
Definition:
LWPools.h:29
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
LWBinLabels.h
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
LWBinLabels::~LWBinLabels
~LWBinLabels()
Definition:
LWBinLabels.cxx:30
DeMoScan.first
bool first
Definition:
DeMoScan.py:534
LWBinLabels::getBinLabel
const char * getBinLabel(unsigned bin) const
Definition:
LWBinLabels.cxx:47
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
LWBinLabels::apply
void apply(TAxis *) const
Definition:
LWBinLabels.cxx:38
LWBinLabels::LWBinLabels
LWBinLabels()
Definition:
LWBinLabels.cxx:22
Generated on Tue Jul 2 2024 21:20:57 for ATLAS Offline Software by
1.8.18