ATLAS Offline Software
Loading...
Searching...
No Matches
UnitTestAlg2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//
8// includes
9//
10
12
13#include <EventLoop/Job.h>
15#include <EventLoop/Worker.h>
17#include <TEfficiency.h>
18#include <TFile.h>
19#include <TH1.h>
20#include <TTree.h>
21#include <TObjString.h>
22
25
26//
27// method implementations
28//
29
31
32namespace EL
33{
34 void UnitTestAlg2 ::
35 testInvariant () const
36 {}
37
38
39
40 UnitTestAlg2 ::
41 UnitTestAlg2 (const std::string& name,
42 ISvcLocator* pSvcLocator)
43 : AnaAlgorithm (name, pSvcLocator),
44 makeOutput (true),
45 m_name ("el_n"),
46 m_value (0),// m_hist (0),
47 m_tree (0),
48 m_hasInitialize (false)
49 {
50 declareProperty ("property", m_property, "test property");
51 declareProperty ("string_property", m_string_property, "test string property");
52 declareProperty ("toolHandle", m_toolHandle, "ToolHandle property");
53
54 RCU_NEW_INVARIANT (this);
55 }
56
57
58
59 ::StatusCode UnitTestAlg2 ::
60 initialize ()
61 {
63
64 getCallbacks()->Fill (CB_INITIALIZE);
65
66 RCU_ASSERT_SOFT (!m_hasInitialize);
67
68 // test that we can create and then retrieve a TEfficiency
69 // histogram
70 ANA_CHECK (book (TEfficiency ("efficiency", "dummy efficiency hist", 50, 0, 50)));
71 (void) hist<TEfficiency> ("efficiency");
72 (void) histeff ("efficiency");
73
74 ANA_CHECK (book (TH1F ((m_name + "2_2").c_str(), m_name.c_str(), 50, 0, 50)));
75 ANA_CHECK (book (TH1F ("file_executes_2", "file executes", 1, 0, 1)));
76
77 ANA_CHECK (book (TH1F ("test_property", "test_property", 1, 0, 1)));
78 hist("test_property")->Fill (0.5, m_property);
79
80 wk()->addOutput (/*m_hist = */new TH1F (m_name.c_str(), m_name.c_str(),
81 50, 0, 50));
82 if (makeOutput)
83 {
84 TFile *file = wk()->getOutputFile ("out");
85 m_tree = new TTree ("tree2", "test output");
86 m_tree->SetDirectory (file);
87 m_tree->Branch (m_name.c_str(), &m_value, (m_name + "/I").c_str());
88 }
89 m_hasInitialize = true;
90 return ::StatusCode::SUCCESS;
91 }
92
93
94
95 ::StatusCode UnitTestAlg2 ::
96 execute ()
97 {
99
100 getCallbacks()->Fill (CB_EXECUTE);
101
102 RCU_ASSERT_SOFT (m_hasInitialize);
103
104 RCU_ASSERT_SOFT (wk()->tree()->GetEntries() > wk()->treeEntry());
105 // RCU_ASSERT_SOFT (m_fileName == wk()->inputFile()->GetName());
106
107 RCU_ASSERT (wk()->tree() != 0);
108 m_branch = wk()->tree()->GetBranch (m_name.c_str());
109 if (m_branch == 0)
110 {
111 ATH_MSG_ERROR ("failed to find branch " << m_name);
112 return StatusCode::FAILURE;
113 }
114 m_branch->SetAddress (&m_value);
115
116 RCU_ASSERT (m_branch != nullptr);
117 RCU_ASSERT (wk() != nullptr);
118 m_branch->GetEntry (wk()->treeEntry());
119 hist(m_name)->Fill (m_value);
120 if (makeOutput)
121 m_tree->Fill ();
122
123 msg().setLevel (MSG::INFO);
124 if (++ m_calls < 3)
125 ATH_MSG_INFO ("message test");
126
127 return ::StatusCode::SUCCESS;
128 }
129
130
131
132 ::StatusCode UnitTestAlg2 ::
133 finalize ()
134 {
136
137 getCallbacks()->Fill (CB_FINALIZE);
138
139 RCU_ASSERT_SOFT (m_hasInitialize);
140 wk()->addOutput (new TH1F ("beta/dir/hist2", "directory test", 10, 0, 10));
141 wk()->addOutputList ("alpha2", new TObjString ("alpha2"));
142 return ::StatusCode::SUCCESS;
143 }
144
145
146
147 TH1 *UnitTestAlg2 ::
148 getCallbacks ()
149 {
150 if (m_callbacks == nullptr)
151 {
152 m_callbacks = new TH1F ("callbacks2", "callbacks", CB_FINALIZE + 1,
153 0, CB_FINALIZE + 1);
154 wk()->addOutput (m_callbacks);
155 }
156 return m_callbacks;
157 }
158}
#define RCU_ASSERT(x)
Definition Assert.h:210
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_ASSERT_SOFT(x)
Definition Assert.h:155
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
#define ANA_CHECK(EXP)
check whether the given expression was successful
TGraphErrors * GetEntries(TH2F *histo)
ClassImp(EL::UnitTestAlg2) namespace EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
MsgStream & msg
Definition testRead.cxx:32
TChain * tree
TFile * file