ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoopTest
Root
UnitTestAlg.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/UnitTestAlg.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::UnitTestAlg
)
30
31
namespace
EL
32
{
33
void
UnitTestAlg ::
34
testInvariant ()
const
35
{}
36
37
38
39
UnitTestAlg ::
40
UnitTestAlg (
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
UnitTestAlg ::
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
return
StatusCode::SUCCESS;
65
}
66
67
68
69
StatusCode
UnitTestAlg ::
70
changeInput (
bool
firstFile)
71
{
72
RCU_CHANGE_INVARIANT
(
this
);
73
74
RCU_ASSERT
(wk()->
tree
() != 0);
75
m_branch = wk()->tree()->GetBranch (m_name.c_str());
76
if
(m_branch == 0)
77
{
78
ATH_MSG_ERROR
(
"failed to find branch "
<< m_name);
79
return
StatusCode::FAILURE;
80
}
81
m_branch->SetAddress (&m_value);
82
RCU_ASSERT_SOFT
(firstFile == m_fileName.empty());
83
m_fileName = wk()->inputFile()->GetName();
84
return
StatusCode::SUCCESS;
85
}
86
87
88
89
StatusCode
UnitTestAlg ::
90
histInitialize ()
91
{
92
RCU_CHANGE_INVARIANT
(
this
);
93
94
RCU_ASSERT_SOFT
(!m_hasHistInitialize);
95
96
book (TH1F ((m_name +
"2"
).c_str(), m_name.c_str(), 50, 0, 50));
97
book (TH1F (
"file_executes"
,
"file executes"
, 1, 0, 1));
98
m_hasHistInitialize =
true
;
99
return
StatusCode::SUCCESS;
100
}
101
102
103
104
StatusCode
UnitTestAlg ::
105
initialize ()
106
{
107
RCU_CHANGE_INVARIANT
(
this
);
108
109
RCU_ASSERT_SOFT
(m_hasHistInitialize);
110
RCU_ASSERT_SOFT
(!m_hasInitialize);
111
112
RCU_ASSERT_SOFT
(wk()->
tree
()->
GetEntries
() > wk()->treeEntry());
113
RCU_ASSERT_SOFT
(m_fileName == wk()->inputFile()->GetName());
114
115
if
(wk()->metaData()->castDouble (
"jobOpt"
) != 42)
116
{
117
ATH_MSG_ERROR
(
"failed to read meta-data from job options"
);
118
return
StatusCode::FAILURE;
119
}
120
121
if
(wk()->metaData()->castString (
"mymeta"
) !=
"test"
)
122
{
123
ATH_MSG_ERROR
(
"failed to read meta-data from worker"
);
124
return
StatusCode::FAILURE;
125
}
126
127
wk()->addOutput (
/*m_hist = */
new
TH1F (m_name.c_str(), m_name.c_str(),
128
50, 0, 50));
129
if
(makeOutput)
130
{
131
TFile *
file
= wk()->getOutputFile (
"out"
);
132
m_tree =
new
TTree (
"tree"
,
"test output"
);
133
m_tree->SetDirectory (
file
);
134
m_tree->Branch (m_name.c_str(), &m_value, (m_name +
"/I"
).c_str());
135
}
136
m_hasInitialize =
true
;
137
return
StatusCode::SUCCESS;
138
}
139
140
141
142
StatusCode
UnitTestAlg ::
143
fileExecute ()
144
{
145
RCU_CHANGE_INVARIANT
(
this
);
146
147
RCU_ASSERT_SOFT
(m_hasHistInitialize);
148
hist (
"file_executes"
)->Fill (0);
149
return
StatusCode::SUCCESS;
150
}
151
152
153
154
StatusCode
UnitTestAlg ::
155
execute ()
156
{
157
RCU_CHANGE_INVARIANT
(
this
);
158
159
RCU_ASSERT_SOFT
(m_hasInitialize);
160
161
m_branch->GetEntry (wk()->treeEntry());
162
hist(m_name)->Fill (m_value);
163
if
(makeOutput)
164
m_tree->Fill ();
165
166
setMsgLevel (MSG::INFO);
167
if
(++ m_calls < 3)
168
ATH_MSG_INFO
(
"message test"
);
169
170
return
StatusCode::SUCCESS;
171
}
172
173
174
175
StatusCode
UnitTestAlg ::
176
finalize ()
177
{
178
RCU_CHANGE_INVARIANT
(
this
);
179
RCU_ASSERT_SOFT
(m_hasInitialize);
180
wk()->addOutput (
new
TH1F (
"beta/dir/hist"
,
"directory test"
, 10, 0, 10));
181
wk()->addOutputList (
"alpha"
,
new
TObjString (
"alpha"
));
182
return
StatusCode::SUCCESS;
183
}
184
185
186
187
StatusCode
UnitTestAlg ::
188
histFinalize ()
189
{
190
RCU_CHANGE_INVARIANT
(
this
);
191
RCU_ASSERT_SOFT
(m_hasHistInitialize);
192
wk()->addOutput (
new
TH1F (
"beta/dir/hist"
,
"directory test"
, 10, 0, 10));
193
wk()->addOutputList (
"alpha"
,
new
TObjString (
"alpha"
));
194
return
StatusCode::SUCCESS;
195
}
196
}
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::UnitTestAlg) namespace EL
Definition
UnitTestAlg.cxx:29
UnitTestAlg.h
Worker.h
EL::UnitTestAlg
Definition
UnitTestAlg.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