ATLAS Offline Software
Functions
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  )

Definition at line 37 of file UnitTestAlg.cxx.

40 {
41  void UnitTestAlg ::
42  testInvariant () const
43  {
44  RCU_INVARIANT (this != 0);
45  }
46 
47 
48 
49  UnitTestAlg ::
50  UnitTestAlg (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 
64  StatusCode UnitTestAlg ::
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  return StatusCode::SUCCESS;
75  }
76 
77 
78 
79  StatusCode UnitTestAlg ::
80  changeInput (bool firstFile)
81  {
82  RCU_CHANGE_INVARIANT (this);
83 
84  RCU_ASSERT (wk()->tree() != 0);
85  m_branch = wk()->tree()->GetBranch (m_name.c_str());
86  if (m_branch == 0)
87  RCU_THROW_MSG ("failed to find branch " + m_name);
88  m_branch->SetAddress (&m_value);
89  RCU_ASSERT_SOFT (firstFile == m_fileName.empty());
90  m_fileName = wk()->inputFile()->GetName();
91  return StatusCode::SUCCESS;
92  }
93 
94 
95 
96  StatusCode UnitTestAlg ::
97  histInitialize ()
98  {
99  RCU_CHANGE_INVARIANT (this);
100 
101  RCU_ASSERT_SOFT (!m_hasHistInitialize);
102 
103  book (TH1F ((m_name + "2").c_str(), m_name.c_str(), 50, 0, 50));
104  book (TH1F ("file_executes", "file executes", 1, 0, 1));
105  m_hasHistInitialize = true;
106  return StatusCode::SUCCESS;
107  }
108 
109 
110 
112  initialize ()
113  {
114  RCU_CHANGE_INVARIANT (this);
115 
116  RCU_ASSERT_SOFT (m_hasHistInitialize);
117  RCU_ASSERT_SOFT (!m_hasInitialize);
118 
119  RCU_ASSERT_SOFT (wk()->tree()->GetEntries() > wk()->treeEntry());
120  RCU_ASSERT_SOFT (m_fileName == wk()->inputFile()->GetName());
121 
122  if (wk()->metaData()->castDouble ("jobOpt") != 42)
123  RCU_THROW_MSG ("failed to read meta-data from job options");
124 
125  if (wk()->metaData()->castString ("mymeta") != "test")
126  RCU_THROW_MSG ("failed to read meta-data from worker");
127 
128  wk()->addOutput (/*m_hist = */new TH1F (m_name.c_str(), m_name.c_str(),
129  50, 0, 50));
130  if (makeOutput)
131  {
132  TFile *file = wk()->getOutputFile ("out");
133  m_tree = new TTree ("tree", "test output");
134  m_tree->SetDirectory (file);
135  m_tree->Branch (m_name.c_str(), &m_value, (m_name + "/I").c_str());
136  }
137  m_hasInitialize = true;
138  return StatusCode::SUCCESS;
139  }
140 
141 
142 
143  StatusCode UnitTestAlg ::
144  fileExecute ()
145  {
146  RCU_CHANGE_INVARIANT (this);
147 
148  RCU_ASSERT_SOFT (m_hasHistInitialize);
149  hist ("file_executes")->Fill (0);
150  return StatusCode::SUCCESS;
151  }
152 
153 
154 
156  execute ()
157  {
158  RCU_CHANGE_INVARIANT (this);
159 
160  RCU_ASSERT_SOFT (m_hasInitialize);
161 
162  m_branch->GetEntry (wk()->treeEntry());
163  hist(m_name)->Fill (m_value);
164  if (makeOutput)
165  m_tree->Fill ();
166 
167  setMsgLevel (MSG::INFO);
168  if (++ m_calls < 3)
169  ATH_MSG_INFO ("message test");
170 
171  return StatusCode::SUCCESS;
172  }
173 
174 
175 
177  finalize ()
178  {
179  RCU_CHANGE_INVARIANT (this);
180  RCU_ASSERT_SOFT (m_hasInitialize);
181  wk()->addOutput (new TH1F ("beta/dir/hist", "directory test", 10, 0, 10));
182  wk()->addOutputList ("alpha", new TObjString ("alpha"));
183  return StatusCode::SUCCESS;
184  }
185 
186 
187 
188  StatusCode UnitTestAlg ::
189  histFinalize ()
190  {
191  RCU_CHANGE_INVARIANT (this);
192  RCU_ASSERT_SOFT (m_hasHistInitialize);
193  wk()->addOutput (new TH1F ("beta/dir/hist", "directory test", 10, 0, 10));
194  wk()->addOutputList ("alpha", new TObjString ("alpha"));
195  return StatusCode::SUCCESS;
196  }
197 }
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
plotmaker.hist
hist
Definition: plotmaker.py:148
initialize
void initialize()
Definition: run_EoverP.cxx:894
tree
TChain * tree
Definition: tile_monitor.h:30
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition: TRTCalib_makeplots.cxx:4019
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
RCU_ASSERT_SOFT
#define RCU_ASSERT_SOFT(x)
Definition: Assert.h:167
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
file
TFile * file
Definition: tile_monitor.h:29
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
INav4MomDumper_jobOptions.OutputStream
OutputStream
Definition: INav4MomDumper_jobOptions.py:20
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
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
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233