ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
MultiDraw
Root
Formula.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
//
8
// includes
9
//
10
11
#include <
MultiDraw/Formula.h
>
12
13
#include <memory>
14
#include <sstream>
15
#include <TTree.h>
16
#include <TTreeFormula.h>
17
#include <TTreeFormulaManager.h>
18
#include <
EventLoop/Job.h
>
19
#include <
EventLoop/StatusCode.h
>
20
#include <
EventLoop/IWorker.h
>
21
#include <
RootCoreUtils/Assert.h
>
22
23
#include <stdexcept>
24
25
//
26
// method implementations
27
//
28
29
namespace
MD
30
{
31
void
Formula ::
32
testInvariant ()
const
33
{
34
if
(!
m_formula
.empty())
35
{
36
RCU_INVARIANT
(!
m_name
.empty());
37
38
if
(
m_tree
!= 0)
39
{
40
RCU_INVARIANT
(
m_manager
!= 0);
41
if
(
m_ndata
> 0)
42
{
43
RCU_INVARIANT
(
m_cache
.size() >= std::size_t (
m_ndata
));
44
RCU_INVARIANT
(
m_read
.size() >= std::size_t (
m_ndata
));
45
}
46
}
else
47
{
48
RCU_INVARIANT
(
m_form
== 0);
49
RCU_INVARIANT
(
m_manager
== 0);
50
}
51
}
else
52
{
53
RCU_INVARIANT
(
m_name
.empty());
54
RCU_INVARIANT
(
m_tree
== 0);
55
RCU_INVARIANT
(
m_form
== 0);
56
RCU_INVARIANT
(
m_manager
== 0);
57
}
58
}
59
60
61
62
Formula ::
63
Formula ()
64
:
m_tree
(0),
m_form
(0),
m_manager
(0),
m_ndim
(-1),
65
m_entry
(-1),
m_ndata
(0)
66
{
67
RCU_NEW_INVARIANT
(
this
);
68
}
69
70
71
72
Formula ::
73
Formula (
const
std::string& name,
const
std::string&
formula
, TTree *
tree
)
74
:
m_formula
(
formula
),
m_name
(name),
75
m_tree
(0),
m_form
(0),
m_manager
(0),
m_ndim
(-1),
76
m_entry
(-1),
m_ndata
(0)
77
{
78
RCU_NEW_INVARIANT
(
this
);
79
80
reset
(
tree
);
81
}
82
83
84
85
Formula ::
86
~Formula ()
87
{
88
RCU_DESTROY_INVARIANT
(
this
);
89
90
delete
m_form
;
91
m_form
= 0;
92
}
93
94
95
96
void
Formula ::
97
reset (TTree *
tree
)
98
{
99
RCU_CHANGE_INVARIANT
(
this
);
100
RCU_REQUIRE
(!
formula
().
empty
());
101
102
delete
m_form
;
103
m_form
= 0;
104
m_manager
= 0;
105
m_ndim
= -1;
106
m_entry
= -1;
107
m_ndata
= 0;
108
m_tree
= 0;
109
110
m_tree
=
tree
;
111
m_form
=
new
TTreeFormula (
m_name
.c_str(),
m_formula
.c_str(),
tree
);
112
113
m_form
->SetQuickLoad (kTRUE);
114
m_manager
=
new
TTreeFormulaManager;
115
m_manager
->Add (
m_form
);
116
m_manager
->Sync ();
117
if
(
m_manager
->GetMultiplicity () == -1)
118
tree
->SetBit (TTree::kForceRead);
119
if
(
m_form
->GetNdim() <= 0)
120
m_ndim
= -1;
121
else
if
(
m_form
->GetMultiplicity() == 0)
122
m_ndim
= 0;
123
else
if
(
m_manager
->GetMultiplicity() == 1 &&
m_form
->GetMultiplicity() == 1)
124
m_ndim
= 1;
125
else
if
(
m_manager
->GetMultiplicity() == -1 &&
m_form
->GetMultiplicity() == 1)
126
m_ndim
= 0;
127
128
129
}
130
131
132
133
const
std::string& Formula ::
134
formula ()
const
135
{
136
RCU_READ_INVARIANT
(
this
);
137
return
m_formula
;
138
}
139
140
141
142
bool
Formula ::
143
valid ()
const
144
{
145
RCU_READ_INVARIANT
(
this
);
146
return
!
m_formula
.empty() &&
m_ndim
>= 0;
147
}
148
149
150
151
int
Formula ::
152
ndim ()
const
153
{
154
RCU_READ_INVARIANT
(
this
);
155
RCU_REQUIRE_SOFT
(
valid
());
156
return
m_ndim
;
157
}
158
159
160
161
std::size_t Formula ::
162
ndata ()
const
163
{
164
RCU_READ_INVARIANT
(
this
);
165
RCU_REQUIRE_SOFT
(
valid
());
166
167
if
(
m_ndim
< 0)
168
throw
std::runtime_error (
"invalid formula: "
+
m_formula
);
169
if
(
m_tree
->GetReadEntry() !=
m_entry
)
170
{
171
m_entry
= -1;
172
m_ndata
=
m_manager
->GetNdata();
173
if
(
m_ndata
> 0)
174
{
175
if
(
m_read
.size() < std::size_t (
m_ndata
))
176
m_read
.resize (
m_ndata
);
177
for
(std::size_t iter = 0, end =
m_ndata
; iter != end; ++ iter)
178
m_read
[iter] =
false
;
179
180
if
(
m_cache
.size() < std::size_t (
m_ndata
))
181
m_cache
.resize (
m_ndata
);
182
m_cache
[0] =
m_form
->EvalInstance (0);
183
m_read
[0] =
true
;
184
m_entry
=
m_tree
->GetReadEntry();
185
}
186
}
187
if
(
m_ndata
< 0)
188
throw
std::runtime_error (
"failed to read formula: "
+
m_formula
);
189
return
m_ndata
;
190
}
191
192
193
194
Double_t Formula ::
195
value (std::size_t data)
const
196
{
197
RCU_READ_INVARIANT
(
this
);
198
RCU_REQUIRE_SOFT
(
valid
());
199
RCU_REQUIRE_SOFT
(data <
ndata
());
200
201
if
(!
m_read
[data])
202
{
203
m_cache
[data] =
m_form
->EvalInstance (data);
204
m_read
[data] =
true
;
205
}
206
return
m_cache
[data];
207
}
208
}
Assert.h
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition
Assert.h:187
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition
Assert.h:223
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition
Assert.h:219
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition
Assert.h:196
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition
Assert.h:141
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
Formula.h
IWorker.h
Job.h
StatusCode.h
empty
static const Attributes_t empty
Definition
XmlStreamer.cxx:16
MD::Formula::formula
const std::string & formula() const
description: the formula used guarantee: no-fail
Definition
Formula.cxx:134
MD::Formula::m_entry
Long64_t m_entry
description: the last entry we read
Definition
Formula.h:137
MD::Formula::m_manager
TTreeFormulaManager * m_manager
description: the manager used
Definition
Formula.h:128
MD::Formula::m_form
TTreeFormula * m_form
description the formula used
Definition
Formula.h:124
MD::Formula::m_name
std::string m_name
description: the name we use for the formula
Definition
Formula.h:116
MD::Formula::m_tree
TTree * m_tree
description: the tree we are connected to
Definition
Formula.h:120
MD::Formula::m_ndim
int m_ndim
description: the number of array dimensions we need to loop over, or -1 if we are in error
Definition
Formula.h:133
MD::Formula::m_cache
std::vector< Double_t > m_cache
description: the cache of data entries
Definition
Formula.h:145
MD::Formula::valid
bool valid() const
returns: whether the formula is valid guarantee: no-fail
Definition
Formula.cxx:143
MD::Formula::ndata
std::size_t ndata() const
returns: the number of data entries for the formula with the given index guarantee: strong failures: ...
Definition
Formula.cxx:162
MD::Formula::m_formula
std::string m_formula
description: members directly corresponding to accessors
Definition
Formula.h:112
MD::Formula::reset
void reset(TTree *tree)
effects: reset this formula to a new tree guarantee: strong failures: out of memory II failures: TTre...
Definition
Formula.cxx:97
MD::Formula::m_ndata
Int_t m_ndata
description: the number of data entries
Definition
Formula.h:141
MD::Formula::m_read
std::vector< bool > m_read
description: whether we read the given data entry
Definition
Formula.h:149
MD
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
AlgCFlow.h:22
tree
TChain * tree
Definition
tile_monitor.h:30
Generated on
for ATLAS Offline Software by
1.17.0