ATLAS Offline Software
Loading...
Searching...
No Matches
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
12
13#include <EventLoop/Job.h>
15#include <EventLoop/Worker.h>
17#include <TFile.h>
18#include <TH1.h>
19#include <TTree.h>
20#include <TObjString.h>
21
24
25//
26// method implementations
27//
28
30
31namespace 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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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}
#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)
ClassImp(EL::UnitTestAlg) namespace EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
TChain * tree
TFile * file