ATLAS Offline Software
UnitTestAlg1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 
14 //
15 // includes
16 //
17 
19 
20 #include <EventLoop/Job.h>
21 #include <EventLoop/OutputStream.h>
22 #include <EventLoop/Worker.h>
23 #include <RootCoreUtils/Assert.h>
24 #include <RootCoreUtils/ThrowMsg.h>
25 #include <TFile.h>
26 #include <TH1.h>
27 #include <TTree.h>
28 #include <TObjString.h>
29 
30 #include <AsgMessaging/MsgStream.h>
32 
33 //
34 // method implementations
35 //
36 
38 
39 namespace EL
40 {
41  void UnitTestAlg1 ::
42  testInvariant () const
43  {
44  RCU_INVARIANT (this != 0);
45  }
46 
47 
48 
50  UnitTestAlg1 (const std::string& branchName)
51  : makeOutput (true),
52  m_name (branchName),
53  m_branch (0),
54  m_value (0),// m_hist (0),
55  m_tree (0),
56  m_hasInitialize (false),
57  m_hasHistInitialize (false)
58  {
59  RCU_NEW_INVARIANT (this);
60  }
61 
62 
63 
65  setupJob (Job& job)
66  {
67  RCU_CHANGE_INVARIANT (this);
68 
69  if (makeOutput)
70  {
71  OutputStream out ("out");
72  job.outputAdd (out);
73  }
74  {
75  OutputStream out ("out_empty");
76  job.outputAdd (out);
77  }
78  return StatusCode::SUCCESS;
79  }
80 
81 
82 
84  changeInput (bool firstFile)
85  {
86  RCU_CHANGE_INVARIANT (this);
87 
88  if (firstFile)
90  else
92 
93  RCU_ASSERT (wk()->tree() != 0);
94  m_branch = wk()->tree()->GetBranch (m_name.c_str());
95  if (m_branch == 0)
96  RCU_THROW_MSG ("failed to find branch " + m_name);
97  m_branch->SetAddress (&m_value);
98  RCU_ASSERT_SOFT (firstFile == m_fileName.empty());
99  m_fileName = wk()->inputFile()->GetName();
100  return StatusCode::SUCCESS;
101  }
102 
103 
104 
107  {
108  RCU_CHANGE_INVARIANT (this);
109 
111 
113 
114  book (TH1F ((m_name + "2").c_str(), m_name.c_str(), 50, 0, 50));
115  book (TH1F ("file_executes", "file executes", 1, 0, 1));
116  m_hasHistInitialize = true;
117  return StatusCode::SUCCESS;
118  }
119 
120 
121 
123  initialize ()
124  {
125  RCU_CHANGE_INVARIANT (this);
126 
128 
131 
132  RCU_ASSERT_SOFT (wk()->tree()->GetEntries() > wk()->treeEntry());
133  RCU_ASSERT_SOFT (m_fileName == wk()->inputFile()->GetName());
134 
135  // if (wk()->metaData()->castDouble ("jobOpt") != 42)
136  // RCU_THROW_MSG ("failed to read meta-data from job options");
137 
138  // if (wk()->metaData()->castString ("mymeta") != "test")
139  // RCU_THROW_MSG ("failed to read meta-data from worker");
140 
141  wk()->addOutput (/*m_hist = */new TH1F (m_name.c_str(), m_name.c_str(),
142  50, 0, 50));
143  if (makeOutput)
144  {
145  TFile *file = wk()->getOutputFile ("out");
146  m_tree = new TTree ("tree", "test output");
147  m_tree->SetDirectory (file);
148  m_tree->Branch (m_name.c_str(), &m_value, (m_name + "/I").c_str());
149  }
150  m_hasInitialize = true;
151  return StatusCode::SUCCESS;
152  }
153 
154 
155 
157  fileExecute ()
158  {
159  RCU_CHANGE_INVARIANT (this);
160 
162 
164  hist ("file_executes")->Fill (0);
165  return StatusCode::SUCCESS;
166  }
167 
168 
169 
171  execute ()
172  {
173  RCU_CHANGE_INVARIANT (this);
174 
176 
178 
179  m_branch->GetEntry (wk()->treeEntry());
180  hist(m_name)->Fill (m_value);
181  if (makeOutput)
182  m_tree->Fill ();
183 
184  setMsgLevel (MSG::INFO);
185  if (++ m_calls < 3)
186  ATH_MSG_INFO ("message test");
187 
188  return StatusCode::SUCCESS;
189  }
190 
191 
192 
194  finalize ()
195  {
196  RCU_CHANGE_INVARIANT (this);
197 
199 
201  wk()->addOutput (new TH1F ("beta/dir/hist", "directory test", 10, 0, 10));
202  wk()->addOutputList ("alpha", new TObjString ("alpha"));
203  return StatusCode::SUCCESS;
204  }
205 
206 
207 
209  histFinalize ()
210  {
211  RCU_CHANGE_INVARIANT (this);
212 
214 
216  wk()->addOutput (new TH1F ("beta/dir/hist", "directory test", 10, 0, 10));
217  wk()->addOutputList ("alpha", new TObjString ("alpha"));
218  return StatusCode::SUCCESS;
219  }
220 
221 
222 
224  getCallbacks ()
225  {
226  if (m_callbacks == nullptr)
227  {
228  m_callbacks = new TH1F ("callbacks", "callbacks", CB_HIST_FINALIZE + 1,
229  0, CB_HIST_FINALIZE + 1);
230  wk()->addOutput (m_callbacks);
231  }
232  return m_callbacks;
233  }
234 }
EL::UnitTestAlg1::CB_CHANGE_INPUT_OTHER
@ CB_CHANGE_INPUT_OTHER
Definition: UnitTestAlg1.h:63
ClassImp
ClassImp(EL::UnitTestAlg1) namespace EL
Definition: UnitTestAlg1.cxx:37
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
EL::Algorithm::setMsgLevel
void setMsgLevel(int level)
set the message level for the message stream for this object
EL::UnitTestAlg1::CB_EXECUTE
@ CB_EXECUTE
Definition: UnitTestAlg1.h:66
EL::UnitTestAlg1::m_value
Int_t m_value
description: the value we are reading from the branch
Definition: UnitTestAlg1.h:170
EL::UnitTestAlg1::fileExecute
virtual StatusCode fileExecute() override
effects: do all the processing that needs to be done once per file guarantee: basic failures: algorit...
Job.h
tree
TChain * tree
Definition: tile_monitor.h:30
EL::IHistogramWorker::addOutput
virtual void addOutput(TObject *output_swallow)=0
effects: add an object to the output.
OutputStream.h
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
EL::UnitTestAlg1::m_hasInitialize
bool m_hasInitialize
whether initialize has been called
Definition: UnitTestAlg1.h:186
EL::Algorithm::hist
TH1 * hist(const std::string &name) const
get the histogram with the given name
Assert.h
EL::UnitTestAlg1::finalize
virtual StatusCode finalize() override
effects: do everything that needs to be done after completing work on this worker guarantee: basic fa...
EL::UnitTestAlg1::m_callbacks
TH1 * m_callbacks
Definition: UnitTestAlg1.h:196
EL::IWorker::addOutputList
virtual void addOutputList(const std::string &name, TObject *output_swallow)=0
effects: add a given object to the output.
EL::UnitTestAlg1::UnitTestAlg1
UnitTestAlg1(const std::string &branchName="el_n")
effects: standard constructor.
EL::IWorker::inputFile
virtual TFile * inputFile() const =0
description: the file we are reading the current tree from guarantee: no-fail
RCU_ASSERT_SOFT
#define RCU_ASSERT_SOFT(x)
Definition: Assert.h:167
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
EL::UnitTestAlg1::histFinalize
virtual StatusCode histFinalize() override
effects: this is a post-initialization routine that is called after finalize has been called.
EL::UnitTestAlg1::m_hasHistInitialize
bool m_hasHistInitialize
whether histInitialize has been called
Definition: UnitTestAlg1.h:190
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EL::UnitTestAlg1::setupJob
virtual StatusCode setupJob(Job &job) override
effects: give the algorithm a chance to intialize the job with anything this algorithm needs.
file
TFile * file
Definition: tile_monitor.h:29
EL::UnitTestAlg1::makeOutput
bool makeOutput
description: whether I create an output n-tuple
Definition: UnitTestAlg1.h:55
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
EL::UnitTestAlg1::initialize
virtual StatusCode initialize() override
effects: do everything that needs to be done before running the algorithm, e.g.
EL::Algorithm::wk
IWorker * wk() const
description: the worker that is controlling us guarantee: no-fail
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
EL::UnitTestAlg1::CB_HIST_INITIALIZE
@ CB_HIST_INITIALIZE
Definition: UnitTestAlg1.h:65
EL::UnitTestAlg1::execute
virtual StatusCode execute() override
effects: process the next event guarantee: basic failures: algorithm dependent rationale: the virtual...
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
EL::UnitTestAlg1::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
INav4MomDumper_jobOptions.OutputStream
OutputStream
Definition: INav4MomDumper_jobOptions.py:20
EL::UnitTestAlg1::CB_FINALIZE
@ CB_FINALIZE
Definition: UnitTestAlg1.h:68
EL::UnitTestAlg1::m_fileName
std::string m_fileName
the name of the file (for testing changeInput)
Definition: UnitTestAlg1.h:182
EL::UnitTestAlg1::m_branch
TBranch * m_branch
description: the branch we are using
Definition: UnitTestAlg1.h:166
EL::UnitTestAlg1
Definition: UnitTestAlg1.h:34
ThrowMsg.h
EL::UnitTestAlg1::CB_CHANGE_INPUT_FIRST
@ CB_CHANGE_INPUT_FIRST
Definition: UnitTestAlg1.h:62
EL::UnitTestAlg1::CB_INITIALIZE
@ CB_INITIALIZE
Definition: UnitTestAlg1.h:64
EL::UnitTestAlg1::m_tree
TTree * m_tree
description: the histogram we are creating
Definition: UnitTestAlg1.h:178
EL::UnitTestAlg1::histInitialize
virtual StatusCode histInitialize() override
effects: this is a pre-initialization routine that is called before changeInput is called.
TH1F
Definition: rootspy.cxx:320
EL::Algorithm::book
void book(const TH1 &hist)
book the given histogram
TH1
Definition: rootspy.cxx:268
Worker.h
MsgStreamMacros.h
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
EL::IWorker::getOutputFile
virtual TFile * getOutputFile(const std::string &label) const =0
effects: get the output file that goes into the dataset with the given label.
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
EL::UnitTestAlg1::CB_FILE_EXECUTE
@ CB_FILE_EXECUTE
Definition: UnitTestAlg1.h:67
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
EL::UnitTestAlg1::m_calls
unsigned m_calls
Definition: UnitTestAlg1.h:193
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
EL::UnitTestAlg1::m_name
std::string m_name
description: the name of the variable we are using
Definition: UnitTestAlg1.h:162
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
EL::UnitTestAlg1::CB_HIST_FINALIZE
@ CB_HIST_FINALIZE
Definition: UnitTestAlg1.h:69
UnitTestAlg1.h
EL::IWorker::tree
virtual TTree * tree() const =0
description: the tree we are running on guarantee: no-fail
EL::UnitTestAlg1::changeInput
virtual StatusCode changeInput(bool firstFile) override
effects: do all changes to work with a new input file, e.g.
EL::UnitTestAlg1::getCallbacks
TH1 * getCallbacks()
MsgStream.h
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233