ATLAS Offline Software
Loading...
Searching...
No Matches
UnitTestAlg.cxx File Reference
#include <EventLoopTest/UnitTestAlg.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::UnitTestAlg) namespace EL

Function Documentation

◆ ClassImp()

ClassImp ( EL::UnitTestAlg )
Author
Nils Krumnack

Definition at line 30 of file UnitTestAlg.cxx.

33{
34 void UnitTestAlg ::
35 testInvariant () const
36 {
37 RCU_INVARIANT (this != 0);
38 }
39
40
41
42 UnitTestAlg ::
43 UnitTestAlg (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 UnitTestAlg ::
58 setupJob (Job& job)
59 {
61
62 if (makeOutput)
63 {
64 OutputStream out ("out");
65 job.outputAdd (out);
66 }
67 return StatusCode::SUCCESS;
68 }
69
70
71
72 StatusCode UnitTestAlg ::
73 changeInput (bool firstFile)
74 {
76
77 RCU_ASSERT (wk()->tree() != 0);
78 m_branch = wk()->tree()->GetBranch (m_name.c_str());
79 if (m_branch == 0)
80 RCU_THROW_MSG ("failed to find branch " + m_name);
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 {
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 {
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 RCU_THROW_MSG ("failed to read meta-data from job options");
117
118 if (wk()->metaData()->castString ("mymeta") != "test")
119 RCU_THROW_MSG ("failed to read meta-data from worker");
120
121 wk()->addOutput (/*m_hist = */new TH1F (m_name.c_str(), m_name.c_str(),
122 50, 0, 50));
123 if (makeOutput)
124 {
125 TFile *file = wk()->getOutputFile ("out");
126 m_tree = new TTree ("tree", "test output");
127 m_tree->SetDirectory (file);
128 m_tree->Branch (m_name.c_str(), &m_value, (m_name + "/I").c_str());
129 }
130 m_hasInitialize = true;
131 return StatusCode::SUCCESS;
132 }
133
134
135
136 StatusCode UnitTestAlg ::
137 fileExecute ()
138 {
140
141 RCU_ASSERT_SOFT (m_hasHistInitialize);
142 hist ("file_executes")->Fill (0);
143 return StatusCode::SUCCESS;
144 }
145
146
147
148 StatusCode UnitTestAlg ::
149 execute ()
150 {
152
153 RCU_ASSERT_SOFT (m_hasInitialize);
154
155 m_branch->GetEntry (wk()->treeEntry());
156 hist(m_name)->Fill (m_value);
157 if (makeOutput)
158 m_tree->Fill ();
159
160 setMsgLevel (MSG::INFO);
161 if (++ m_calls < 3)
162 ATH_MSG_INFO ("message test");
163
164 return StatusCode::SUCCESS;
165 }
166
167
168
169 StatusCode UnitTestAlg ::
170 finalize ()
171 {
173 RCU_ASSERT_SOFT (m_hasInitialize);
174 wk()->addOutput (new TH1F ("beta/dir/hist", "directory test", 10, 0, 10));
175 wk()->addOutputList ("alpha", new TObjString ("alpha"));
176 return StatusCode::SUCCESS;
177 }
178
179
180
181 StatusCode UnitTestAlg ::
182 histFinalize ()
183 {
185 RCU_ASSERT_SOFT (m_hasHistInitialize);
186 wk()->addOutput (new TH1F ("beta/dir/hist", "directory test", 10, 0, 10));
187 wk()->addOutputList ("alpha", new TObjString ("alpha"));
188 return StatusCode::SUCCESS;
189 }
190}
#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.
TChain * tree
TFile * file