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 <RootCoreUtils/ThrowMsg.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 30 of file UnitTestAlg1.cxx.

33{
34 void UnitTestAlg1 ::
35 testInvariant () const
36 {
37 RCU_INVARIANT (this != 0);
38 }
39
40
41
42 UnitTestAlg1 ::
43 UnitTestAlg1 (const std::string& branchName)
44 : makeOutput (true),
45 m_name (branchName),
46 m_branch (0),
47 m_value (0),// m_hist (0),
48 m_tree (0),
49 m_hasInitialize (false),
50 m_hasHistInitialize (false)
51 {
52 RCU_NEW_INVARIANT (this);
53 }
54
55
56
57 StatusCode UnitTestAlg1 ::
58 setupJob (Job& job)
59 {
61
62 if (makeOutput)
63 {
64 OutputStream out ("out");
65 job.outputAdd (out);
66 }
67 {
68 OutputStream out ("out_empty");
69 job.outputAdd (out);
70 }
71 return StatusCode::SUCCESS;
72 }
73
74
75
76 StatusCode UnitTestAlg1 ::
77 changeInput (bool firstFile)
78 {
80
81 if (firstFile)
82 getCallbacks()->Fill (CB_CHANGE_INPUT_FIRST);
83 else
84 getCallbacks()->Fill (CB_CHANGE_INPUT_OTHER);
85
86 RCU_ASSERT (wk()->tree() != 0);
87 m_branch = wk()->tree()->GetBranch (m_name.c_str());
88 if (m_branch == 0)
89 RCU_THROW_MSG ("failed to find branch " + m_name);
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 // if (wk()->metaData()->castDouble ("jobOpt") != 42)
129 // RCU_THROW_MSG ("failed to read meta-data from job options");
130
131 // if (wk()->metaData()->castString ("mymeta") != "test")
132 // RCU_THROW_MSG ("failed to read meta-data from worker");
133
134 wk()->addOutput (/*m_hist = */new TH1F (m_name.c_str(), m_name.c_str(),
135 50, 0, 50));
136 if (makeOutput)
137 {
138 TFile *file = wk()->getOutputFile ("out");
139 m_tree = new TTree ("tree", "test output");
140 m_tree->SetDirectory (file);
141 m_tree->Branch (m_name.c_str(), &m_value, (m_name + "/I").c_str());
142 }
143 m_hasInitialize = true;
144 return StatusCode::SUCCESS;
145 }
146
147
148
149 StatusCode UnitTestAlg1 ::
150 fileExecute ()
151 {
153
154 getCallbacks()->Fill (CB_FILE_EXECUTE);
155
156 RCU_ASSERT_SOFT (m_hasHistInitialize);
157 hist ("file_executes")->Fill (0);
158 return StatusCode::SUCCESS;
159 }
160
161
162
163 StatusCode UnitTestAlg1 ::
164 execute ()
165 {
167
168 getCallbacks()->Fill (CB_EXECUTE);
169
170 RCU_ASSERT_SOFT (m_hasInitialize);
171
172 m_branch->GetEntry (wk()->treeEntry());
173 hist(m_name)->Fill (m_value);
174 if (makeOutput)
175 m_tree->Fill ();
176
177 setMsgLevel (MSG::INFO);
178 if (++ m_calls < 3)
179 ATH_MSG_INFO ("message test");
180
181 return StatusCode::SUCCESS;
182 }
183
184
185
186 StatusCode UnitTestAlg1 ::
187 finalize ()
188 {
190
191 getCallbacks()->Fill (CB_FINALIZE);
192
193 RCU_ASSERT_SOFT (m_hasInitialize);
194 wk()->addOutput (new TH1F ("beta/dir/hist", "directory test", 10, 0, 10));
195 wk()->addOutputList ("alpha", new TObjString ("alpha"));
196 return StatusCode::SUCCESS;
197 }
198
199
200
201 StatusCode UnitTestAlg1 ::
202 histFinalize ()
203 {
205
206 getCallbacks()->Fill (CB_HIST_FINALIZE);
207
208 RCU_ASSERT_SOFT (m_hasHistInitialize);
209 wk()->addOutput (new TH1F ("beta/dir/hist", "directory test", 10, 0, 10));
210 wk()->addOutputList ("alpha", new TObjString ("alpha"));
211 return StatusCode::SUCCESS;
212 }
213
214
215
216 TH1 *UnitTestAlg1 ::
217 getCallbacks ()
218 {
219 if (m_callbacks == nullptr)
220 {
221 m_callbacks = new TH1F ("callbacks", "callbacks", CB_HIST_FINALIZE + 1,
222 0, CB_HIST_FINALIZE + 1);
223 wk()->addOutput (m_callbacks);
224 }
225 return m_callbacks;
226 }
227}
#define RCU_INVARIANT(x)
Definition Assert.h:196
#define RCU_ASSERT(x)
Definition Assert.h:217
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:226
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:228
#define RCU_ASSERT_SOFT(x)
Definition Assert.h:162
#define ATH_MSG_INFO(x)
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
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