ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoopTest
Root
UnitTestAlg1.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
//
8
// includes
9
//
10
11
#include <
EventLoopTest/UnitTestAlg1.h
>
12
13
#include <
EventLoop/Job.h
>
14
#include <
EventLoop/OutputStream.h
>
15
#include <
EventLoop/Worker.h
>
16
#include <
RootCoreUtils/Assert.h
>
17
#include <TFile.h>
18
#include <TH1.h>
19
#include <TTree.h>
20
#include <TObjString.h>
21
22
#include <
AsgMessaging/MsgStream.h
>
23
#include <
AsgMessaging/MsgStreamMacros.h
>
24
25
//
26
// method implementations
27
//
28
29
ClassImp
(
EL::UnitTestAlg1
)
30
31
namespace
EL
32
{
33
void
UnitTestAlg1 ::
34
testInvariant ()
const
35
{}
36
37
38
39
UnitTestAlg1 ::
40
UnitTestAlg1 (
const
std::string& branchName)
41
: makeOutput (
true
),
42
m_name (branchName),
43
m_branch (0),
44
m_value (0),
// m_hist (0),
45
m_tree (0),
46
m_hasInitialize (
false
),
47
m_hasHistInitialize (
false
)
48
{
49
RCU_NEW_INVARIANT
(
this
);
50
}
51
52
53
54
StatusCode
UnitTestAlg1 ::
55
setupJob (Job& job)
56
{
57
RCU_CHANGE_INVARIANT
(
this
);
58
59
if
(makeOutput)
60
{
61
OutputStream out (
"out"
);
62
job.outputAdd (out);
63
}
64
{
65
OutputStream out (
"out_empty"
);
66
job.outputAdd (out);
67
}
68
return
StatusCode::SUCCESS;
69
}
70
71
72
73
StatusCode
UnitTestAlg1 ::
74
changeInput (
bool
firstFile)
75
{
76
RCU_CHANGE_INVARIANT
(
this
);
77
78
if
(firstFile)
79
getCallbacks()->Fill (CB_CHANGE_INPUT_FIRST);
80
else
81
getCallbacks()->Fill (CB_CHANGE_INPUT_OTHER);
82
83
RCU_ASSERT
(wk()->
tree
() != 0);
84
m_branch = wk()->tree()->GetBranch (m_name.c_str());
85
if
(m_branch == 0)
86
{
87
ATH_MSG_ERROR
(
"failed to find branch "
<< m_name);
88
return
StatusCode::FAILURE;
89
}
90
m_branch->SetAddress (&m_value);
91
RCU_ASSERT_SOFT
(firstFile == m_fileName.empty());
92
m_fileName = wk()->inputFile()->GetName();
93
return
StatusCode::SUCCESS;
94
}
95
96
97
98
StatusCode
UnitTestAlg1 ::
99
histInitialize ()
100
{
101
RCU_CHANGE_INVARIANT
(
this
);
102
103
getCallbacks()->Fill (CB_HIST_INITIALIZE);
104
105
RCU_ASSERT_SOFT
(!m_hasHistInitialize);
106
107
book (TH1F ((m_name +
"2"
).c_str(), m_name.c_str(), 50, 0, 50));
108
book (TH1F (
"file_executes"
,
"file executes"
, 1, 0, 1));
109
m_hasHistInitialize =
true
;
110
return
StatusCode::SUCCESS;
111
}
112
113
114
115
StatusCode
UnitTestAlg1 ::
116
initialize ()
117
{
118
RCU_CHANGE_INVARIANT
(
this
);
119
120
getCallbacks()->Fill (CB_INITIALIZE);
121
122
RCU_ASSERT_SOFT
(m_hasHistInitialize);
123
RCU_ASSERT_SOFT
(!m_hasInitialize);
124
125
RCU_ASSERT_SOFT
(wk()->
tree
()->
GetEntries
() > wk()->treeEntry());
126
RCU_ASSERT_SOFT
(m_fileName == wk()->inputFile()->GetName());
127
128
wk()->addOutput (
/*m_hist = */
new
TH1F (m_name.c_str(), m_name.c_str(),
129
50, 0, 50));
130
if
(makeOutput)
131
{
132
TFile *
file
= wk()->getOutputFile (
"out"
);
133
m_tree =
new
TTree (
"tree"
,
"test output"
);
134
m_tree->SetDirectory (
file
);
135
m_tree->Branch (m_name.c_str(), &m_value, (m_name +
"/I"
).c_str());
136
}
137
m_hasInitialize =
true
;
138
return
StatusCode::SUCCESS;
139
}
140
141
142
143
StatusCode
UnitTestAlg1 ::
144
fileExecute ()
145
{
146
RCU_CHANGE_INVARIANT
(
this
);
147
148
getCallbacks()->Fill (CB_FILE_EXECUTE);
149
150
RCU_ASSERT_SOFT
(m_hasHistInitialize);
151
hist (
"file_executes"
)->Fill (0);
152
return
StatusCode::SUCCESS;
153
}
154
155
156
157
StatusCode
UnitTestAlg1 ::
158
execute ()
159
{
160
RCU_CHANGE_INVARIANT
(
this
);
161
162
getCallbacks()->Fill (CB_EXECUTE);
163
164
RCU_ASSERT_SOFT
(m_hasInitialize);
165
166
m_branch->GetEntry (wk()->treeEntry());
167
hist(m_name)->Fill (m_value);
168
if
(makeOutput)
169
m_tree->Fill ();
170
171
setMsgLevel (MSG::INFO);
172
if
(++ m_calls < 3)
173
ATH_MSG_INFO
(
"message test"
);
174
175
return
StatusCode::SUCCESS;
176
}
177
178
179
180
StatusCode
UnitTestAlg1 ::
181
finalize ()
182
{
183
RCU_CHANGE_INVARIANT
(
this
);
184
185
getCallbacks()->Fill (CB_FINALIZE);
186
187
RCU_ASSERT_SOFT
(m_hasInitialize);
188
wk()->addOutput (
new
TH1F (
"beta/dir/hist"
,
"directory test"
, 10, 0, 10));
189
wk()->addOutputList (
"alpha"
,
new
TObjString (
"alpha"
));
190
return
StatusCode::SUCCESS;
191
}
192
193
194
195
StatusCode
UnitTestAlg1 ::
196
histFinalize ()
197
{
198
RCU_CHANGE_INVARIANT
(
this
);
199
200
getCallbacks()->Fill (CB_HIST_FINALIZE);
201
202
RCU_ASSERT_SOFT
(m_hasHistInitialize);
203
wk()->addOutput (
new
TH1F (
"beta/dir/hist"
,
"directory test"
, 10, 0, 10));
204
wk()->addOutputList (
"alpha"
,
new
TObjString (
"alpha"
));
205
return
StatusCode::SUCCESS;
206
}
207
208
209
210
TH1 *UnitTestAlg1 ::
211
getCallbacks ()
212
{
213
if
(m_callbacks ==
nullptr
)
214
{
215
m_callbacks =
new
TH1F (
"callbacks"
,
"callbacks"
, CB_HIST_FINALIZE + 1,
216
0, CB_HIST_FINALIZE + 1);
217
wk()->addOutput (m_callbacks);
218
}
219
return
m_callbacks;
220
}
221
}
Assert.h
RCU_ASSERT
#define RCU_ASSERT(x)
Definition
Assert.h:210
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_ASSERT_SOFT
#define RCU_ASSERT_SOFT(x)
Definition
Assert.h:155
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
MsgStreamMacros.h
MsgStream.h
Job.h
OutputStream.h
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition
TRTCalib_makeplots.cxx:4025
ClassImp
ClassImp(EL::UnitTestAlg1) namespace EL
Definition
UnitTestAlg1.cxx:29
UnitTestAlg1.h
Worker.h
EL::UnitTestAlg1
Definition
UnitTestAlg1.h:25
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
tree
TChain * tree
Definition
tile_monitor.h:30
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0