ATLAS Offline Software
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>
15 #include <EventLoop/OutputStream.h>
16 #include <EventLoop/Worker.h>
17 #include <RootCoreUtils/Assert.h>
18 #include <RootCoreUtils/ThrowMsg.h>
20 #include <TFile.h>
21 #include <TH1.h>
22 #include <TTree.h>
23 
24 #include <AsgMessaging/MsgStream.h>
27 
28 //
29 // method implementations
30 //
31 
33 
34 namespace EL
35 {
37  testInvariant () const
38  {
39  RCU_INVARIANT (this != 0);
40  }
41 
42 
43 
46  {
47  RCU_NEW_INVARIANT (this);
48  }
49 
50 
51 
54  {
55  RCU_DESTROY_INVARIANT (this);
56 
58  {
59  ANA_MSG_FATAL ("never got completely finalized");
60  RCU_THROW_MSG ("never got completely finalized");
61  }
62  }
63 
64 
65 
67  setupJob (Job& job)
68  {
69  RCU_CHANGE_INVARIANT (this);
70 
71  job.useXAOD ();
72 
73  return StatusCode::SUCCESS;
74  }
75 
76 
77 
79  changeInput (bool /*firstFile*/)
80  {
82  RCU_CHANGE_INVARIANT (this);
83  ANA_MSG_INFO ("changeInput");
87  return StatusCode::SUCCESS;
88  }
89 
90 
91 
94  {
96  RCU_CHANGE_INVARIANT (this);
97  ANA_MSG_INFO ("histInitialize");
100  return StatusCode::SUCCESS;
101  }
102 
103 
104 
106  initialize ()
107  {
109  RCU_CHANGE_INVARIANT (this);
110  ANA_MSG_INFO ("initialize");
113  return StatusCode::SUCCESS;
114  }
115 
116 
117 
119  fileExecute ()
120  {
122  RCU_CHANGE_INVARIANT (this);
123  ANA_MSG_INFO ("fileExecute");
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 
146  execute ()
147  {
149  RCU_CHANGE_INVARIANT (this);
150  ANA_MSG_DEBUG ("execute");
152  return StatusCode::SUCCESS;
153  }
154 
155 
156 
158  finalize ()
159  {
161  RCU_CHANGE_INVARIANT (this);
162  ANA_MSG_INFO ("finalize");
165  return StatusCode::SUCCESS;
166  }
167 
168 
169 
171  histFinalize ()
172  {
174  RCU_CHANGE_INVARIANT (this);
175  ANA_MSG_INFO ("histFinalize");
178  return StatusCode::SUCCESS;
179  }
180 
181 
182 
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 }
grepfile.info
info
Definition: grepfile.py:38
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
EL::UnitTestAlgXAOD::changeInput
virtual StatusCode changeInput(bool firstFile) override
effects: do all changes to work with a new input file, e.g.
EL::UnitTestAlgXAOD::State::HIST_FINALIZED
@ HIST_FINALIZED
Job.h
EL::UnitTestAlgXAOD::initialize
virtual StatusCode initialize() override
effects: do everything that needs to be done before running the algorithm, e.g.
tree
TChain * tree
Definition: tile_monitor.h:30
EL::UnitTestAlgXAOD::State::INITIALIZED
@ INITIALIZED
OutputStream.h
EL::UnitTestAlgXAOD::UnitTestAlgXAOD
UnitTestAlgXAOD()
effects: standard constructor guarantee: strong failures: low level errors II
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
Assert.h
UnitTestAlgXAOD.h
EL::UnitTestAlgXAOD::histFinalize
virtual StatusCode histFinalize() override
effects: this is a post-initialization routine that is called after finalize has been called.
EL::UnitTestAlgXAOD::setupJob
virtual StatusCode setupJob(Job &job) override
effects: give the algorithm a chance to intialize the job with anything this algorithm needs.
EL::UnitTestAlgXAOD::execute
virtual StatusCode execute() override
effects: process the next event guarantee: basic failures: algorithm dependent rationale: the virtual...
EL::UnitTestAlgXAOD::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
EL::Algorithm::evtStore
asg::SgTEvent * evtStore() const
get the (main) event store for this algorithm
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
MessageCheck.h
macros for messaging and checking status codes
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
EL::UnitTestAlgXAOD::m_state
State m_state
Definition: UnitTestAlgXAOD.h:147
EL::Algorithm::wk
IWorker * wk() const
description: the worker that is controlling us guarantee: no-fail
EL::UnitTestAlgXAOD::State::START
@ START
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
EL::UnitTestAlgXAOD::State::HIST_INITIALIZED
@ HIST_INITIALIZED
ANA_MSG_FATAL
#define ANA_MSG_FATAL(xmsg)
Macro printing fatal messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:296
EL::UnitTestAlgXAOD::~UnitTestAlgXAOD
virtual ~UnitTestAlgXAOD()
effects: non-standard destructor guarantee: basic failures: not fully finalized
ThrowMsg.h
EL::UnitTestAlgXAOD::histInitialize
virtual StatusCode histInitialize() override
effects: this is a pre-initialization routine that is called before changeInput is called.
ClassImp
ClassImp(EL::UnitTestAlgXAOD) namespace EL
Definition: UnitTestAlgXAOD.cxx:32
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
EL::UnitTestAlgXAOD::testWorkerState
StatusCode testWorkerState(bool validEvent, std::set< State > validStates) const
check if the state of inputs on the worker is valid right now
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
Worker.h
EL::UnitTestAlgXAOD::State::INPUT_CHANGED
@ INPUT_CHANGED
EL::UnitTestAlgXAOD::fileExecute
virtual StatusCode fileExecute() override
effects: do all the processing that needs to be done once per file guarantee: basic failures: algorit...
MsgStreamMacros.h
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
EL::UnitTestAlgXAOD::finalize
virtual StatusCode finalize() override
effects: do everything that needs to be done after completing work on this worker guarantee: basic fa...
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
EL::UnitTestAlgXAOD::State::FINALIZED
@ FINALIZED
MsgStream.h
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233
EL::UnitTestAlgXAOD
Definition: UnitTestAlgXAOD.h:23