ATLAS Offline Software
Loading...
Searching...
No Matches
UnitTestAlgXAOD.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8//
9// includes
10//
11
13
14#include <EventLoop/Job.h>
16#include <EventLoop/Worker.h>
20#include <TFile.h>
21#include <TH1.h>
22#include <TTree.h>
23
27
28//
29// method implementations
30//
31
33
34namespace EL
35{
36 void UnitTestAlgXAOD ::
37 testInvariant () const
38 {
39 RCU_INVARIANT (this != 0);
40 }
41
42
43
44 UnitTestAlgXAOD ::
45 UnitTestAlgXAOD ()
46 {
47 RCU_NEW_INVARIANT (this);
48 }
49
50
51
52 UnitTestAlgXAOD ::
53 ~UnitTestAlgXAOD ()
54 {
56
57 if (m_state != State::START && m_state != State::HIST_FINALIZED)
58 {
59 ANA_MSG_FATAL ("never got completely finalized");
60 RCU_THROW_MSG ("never got completely finalized");
61 }
62 }
63
64
65
66 StatusCode UnitTestAlgXAOD ::
67 setupJob (Job& job)
68 {
70
71 job.useXAOD ();
72
73 return StatusCode::SUCCESS;
74 }
75
76
77
78 StatusCode UnitTestAlgXAOD ::
79 changeInput (bool /*firstFile*/)
80 {
83 ANA_MSG_INFO ("changeInput");
84 ANA_CHECK (testWorkerState (true, {State::HIST_INITIALIZED, State::INITIALIZED, State::INPUT_CHANGED}));
85 if (m_state == State::HIST_INITIALIZED)
86 m_state = State::INPUT_CHANGED;
87 return StatusCode::SUCCESS;
88 }
89
90
91
92 StatusCode UnitTestAlgXAOD ::
93 histInitialize ()
94 {
97 ANA_MSG_INFO ("histInitialize");
98 ANA_CHECK (testWorkerState (false, {State::START}));
99 m_state = State::HIST_INITIALIZED;
100 return StatusCode::SUCCESS;
101 }
102
103
104
105 StatusCode UnitTestAlgXAOD ::
106 initialize ()
107 {
110 ANA_MSG_INFO ("initialize");
111 ANA_CHECK (testWorkerState (true, {State::INPUT_CHANGED}));
112 m_state = State::INITIALIZED;
113 return StatusCode::SUCCESS;
114 }
115
116
117
118 StatusCode UnitTestAlgXAOD ::
119 fileExecute ()
120 {
123 ANA_MSG_INFO ("fileExecute");
124 ANA_CHECK (testWorkerState (false, {State::HIST_INITIALIZED, State::INPUT_CHANGED, State::INITIALIZED}));
125
126 // in principle I should check here that TEvent is connected to a
127 // good file, but I'm not sure how, just checking that I can
128 // retrieve EventInfo, which is not guaranteed, as the input file
129 // may be empty, but none of the test files is
130
131 if (wk()->inputFile() == nullptr)
132 {
133 ANA_MSG_ERROR ("didn't find input file");
134 return StatusCode::FAILURE;
135 }
136
137 const xAOD::EventInfo *info {nullptr};
138 ANA_CHECK (evtStore()->retrieve (info, "EventInfo"));
139
140 return StatusCode::SUCCESS;
141 }
142
143
144
145 StatusCode UnitTestAlgXAOD ::
146 execute ()
147 {
150 ANA_MSG_DEBUG ("execute");
151 ANA_CHECK (testWorkerState (true, {State::INITIALIZED}));
152 return StatusCode::SUCCESS;
153 }
154
155
156
157 StatusCode UnitTestAlgXAOD ::
158 finalize ()
159 {
162 ANA_MSG_INFO ("finalize");
163 ANA_CHECK (testWorkerState (false, {State::INITIALIZED}));
164 m_state = State::FINALIZED;
165 return StatusCode::SUCCESS;
166 }
167
168
169
170 StatusCode UnitTestAlgXAOD ::
171 histFinalize ()
172 {
175 ANA_MSG_INFO ("histFinalize");
176 ANA_CHECK (testWorkerState (false, {State::FINALIZED, State::HIST_FINALIZED}));
177 m_state = State::HIST_FINALIZED;
178 return StatusCode::SUCCESS;
179 }
180
181
182
183 StatusCode UnitTestAlgXAOD ::
184 testWorkerState (bool validEvent, std::set<State> validStates) const
185 {
186 if (validStates.find (m_state) == validStates.end())
187 {
188 ANA_MSG_ERROR ("invalid state: " << unsigned (m_state));
189 return StatusCode::FAILURE;
190 }
191
192 if (wk()->xaodEvent() == nullptr)
193 {
194 ANA_MSG_ERROR ("didn't find TEvent");
195 return StatusCode::FAILURE;
196 }
197
198 if (wk()->xaodStore() == nullptr)
199 {
200 ANA_MSG_ERROR ("didn't find TStore");
201 return StatusCode::FAILURE;
202 }
203
204 if (validEvent)
205 {
206 if (wk()->tree() == nullptr)
207 {
208 ANA_MSG_ERROR ("didn't find tree");
209 return StatusCode::FAILURE;
210 }
211
212 if (wk()->treeEntry() < 0 ||
213 wk()->treeEntry() >= wk()->tree()->GetEntries())
214 {
215 ANA_MSG_ERROR ("invalid tree entry");
216 return StatusCode::FAILURE;
217 }
218
219 const xAOD::EventInfo *info {nullptr};
220 ANA_CHECK (evtStore()->retrieve (info, "EventInfo"));
221 }
222 return StatusCode::SUCCESS;
223 }
224}
#define RCU_INVARIANT(x)
Definition Assert.h:201
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
macros for messaging and checking status codes
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_MSG_FATAL(xmsg)
Macro printing fatal messages.
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
TGraphErrors * GetEntries(TH2F *histo)
ClassImp(EL::UnitTestAlgXAOD) namespace EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
EventInfo_v1 EventInfo
Definition of the latest event info version.
TChain * tree