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