ATLAS Offline Software
Loading...
Searching...
No Matches
UnitTestAlg1.cxx File Reference
#include <EventLoopTest/UnitTestAlg1.h>
#include <EventLoop/Job.h>
#include <EventLoop/OutputStream.h>
#include <EventLoop/Worker.h>
#include <RootCoreUtils/Assert.h>
#include <TFile.h>
#include <TH1.h>
#include <TTree.h>
#include <TObjString.h>
#include <AsgMessaging/MsgStream.h>
#include <AsgMessaging/MsgStreamMacros.h>

Go to the source code of this file.

Functions

 ClassImp (EL::UnitTestAlg1) namespace EL

Function Documentation

◆ ClassImp()

ClassImp ( EL::UnitTestAlg1 )
Author
Nils Krumnack

Definition at line 29 of file UnitTestAlg1.cxx.

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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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}
#define RCU_ASSERT(x)
Definition Assert.h:210
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_ASSERT_SOFT(x)
Definition Assert.h:155
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
TGraphErrors * GetEntries(TH2F *histo)
std::string m_name
The primary name part of this expression.
virtual StatusCode book()
Declare tuple variables.
ID3PD * m_tree
Pointer to the ID3PD object used.
::StatusCode StatusCode
StatusCode definition for legacy code.
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
TChain * tree
TFile * file