ATLAS Offline Software
Loading...
Searching...
No Matches
UnitTestAlg2.cxx File Reference
#include <EventLoopTest/UnitTestAlg2.h>
#include <EventLoop/Job.h>
#include <EventLoop/OutputStream.h>
#include <EventLoop/Worker.h>
#include <RootCoreUtils/Assert.h>
#include <RootCoreUtils/ThrowMsg.h>
#include <TEfficiency.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::UnitTestAlg2) namespace EL

Function Documentation

◆ ClassImp()

ClassImp ( EL::UnitTestAlg2 )

Definition at line 38 of file UnitTestAlg2.cxx.

41{
42 void UnitTestAlg2 ::
43 testInvariant () const
44 {
45 RCU_INVARIANT (this != 0);
46 }
47
48
49
50 UnitTestAlg2 ::
51 UnitTestAlg2 (const std::string& name,
52 ISvcLocator* pSvcLocator)
53 : AnaAlgorithm (name, pSvcLocator),
54 makeOutput (true),
55 m_name ("el_n"),
56 m_value (0),// m_hist (0),
57 m_tree (0),
58 m_hasInitialize (false)
59 {
60 declareProperty ("property", m_property, "test property");
61 declareProperty ("string_property", m_string_property, "test string property");
62 declareProperty ("toolHandle", m_toolHandle, "ToolHandle property");
63
64 RCU_NEW_INVARIANT (this);
65 }
66
67
68
69 ::StatusCode UnitTestAlg2 ::
70 initialize ()
71 {
73
74 getCallbacks()->Fill (CB_INITIALIZE);
75
76 RCU_ASSERT_SOFT (!m_hasInitialize);
77
78 // test that we can create and then retrieve a TEfficiency
79 // histogram
80 ANA_CHECK (book (TEfficiency ("efficiency", "dummy efficiency hist", 50, 0, 50)));
81 (void) hist<TEfficiency> ("efficiency");
82 (void) histeff ("efficiency");
83
84 ANA_CHECK (book (TH1F ((m_name + "2_2").c_str(), m_name.c_str(), 50, 0, 50)));
85 ANA_CHECK (book (TH1F ("file_executes_2", "file executes", 1, 0, 1)));
86
87 ANA_CHECK (book (TH1F ("test_property", "test_property", 1, 0, 1)));
88 hist("test_property")->Fill (0.5, m_property);
89
90 // if (wk()->metaData()->castDouble ("jobOpt") != 42)
91 // RCU_THROW_MSG ("failed to read meta-data from job options");
92
93 // if (wk()->metaData()->castString ("mymeta") != "test")
94 // RCU_THROW_MSG ("failed to read meta-data from worker");
95
96 wk()->addOutput (/*m_hist = */new TH1F (m_name.c_str(), m_name.c_str(),
97 50, 0, 50));
98 if (makeOutput)
99 {
100 TFile *file = wk()->getOutputFile ("out");
101 m_tree = new TTree ("tree2", "test output");
102 m_tree->SetDirectory (file);
103 m_tree->Branch (m_name.c_str(), &m_value, (m_name + "/I").c_str());
104 }
105 m_hasInitialize = true;
106 return ::StatusCode::SUCCESS;
107 }
108
109
110
111 ::StatusCode UnitTestAlg2 ::
112 execute ()
113 {
115
116 getCallbacks()->Fill (CB_EXECUTE);
117
118 RCU_ASSERT_SOFT (m_hasInitialize);
119
120 RCU_ASSERT_SOFT (wk()->tree()->GetEntries() > wk()->treeEntry());
121 // RCU_ASSERT_SOFT (m_fileName == wk()->inputFile()->GetName());
122
123 RCU_ASSERT (wk()->tree() != 0);
124 m_branch = wk()->tree()->GetBranch (m_name.c_str());
125 if (m_branch == 0)
126 RCU_THROW_MSG ("failed to find branch " + m_name);
127 m_branch->SetAddress (&m_value);
128
129 RCU_ASSERT (m_branch != nullptr);
130 RCU_ASSERT (wk() != nullptr);
131 m_branch->GetEntry (wk()->treeEntry());
132 hist(m_name)->Fill (m_value);
133 if (makeOutput)
134 m_tree->Fill ();
135
136 msg().setLevel (MSG::INFO);
137 if (++ m_calls < 3)
138 ATH_MSG_INFO ("message test");
139
140 return ::StatusCode::SUCCESS;
141 }
142
143
144
145 ::StatusCode UnitTestAlg2 ::
146 finalize ()
147 {
149
150 getCallbacks()->Fill (CB_FINALIZE);
151
152 RCU_ASSERT_SOFT (m_hasInitialize);
153 wk()->addOutput (new TH1F ("beta/dir/hist2", "directory test", 10, 0, 10));
154 wk()->addOutputList ("alpha2", new TObjString ("alpha2"));
155 return ::StatusCode::SUCCESS;
156 }
157
158
159
160 TH1 *UnitTestAlg2 ::
161 getCallbacks ()
162 {
163 if (m_callbacks == nullptr)
164 {
165 m_callbacks = new TH1F ("callbacks2", "callbacks", CB_FINALIZE + 1,
166 0, CB_FINALIZE + 1);
167 wk()->addOutput (m_callbacks);
168 }
169 return m_callbacks;
170 }
171}
#define RCU_INVARIANT(x)
Definition Assert.h:201
#define RCU_ASSERT(x)
Definition Assert.h:222
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_ASSERT_SOFT(x)
Definition Assert.h:167
#define ATH_MSG_INFO(x)
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
TGraphErrors * GetEntries(TH2F *histo)
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
MsgStream & msg
Definition testRead.cxx:32
TChain * tree
TFile * file