ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoopTest
Root
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
11
#include <
EventLoopTest/UnitTestAlg2.h
>
12
13
#include <
EventLoop/Job.h
>
14
#include <
EventLoop/OutputStream.h
>
15
#include <
EventLoop/Worker.h
>
16
#include <
RootCoreUtils/Assert.h
>
17
#include <TEfficiency.h>
18
#include <TFile.h>
19
#include <TH1.h>
20
#include <TTree.h>
21
#include <TObjString.h>
22
23
#include <
AsgMessaging/MsgStream.h
>
24
#include <
AsgMessaging/MsgStreamMacros.h
>
25
26
//
27
// method implementations
28
//
29
30
ClassImp
(
EL::UnitTestAlg2
)
31
32
namespace
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
{
62
RCU_CHANGE_INVARIANT
(
this
);
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
{
98
RCU_CHANGE_INVARIANT
(
this
);
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
{
135
RCU_CHANGE_INVARIANT
(
this
);
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
}
Assert.h
RCU_ASSERT
#define RCU_ASSERT(x)
Definition
Assert.h:210
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition
Assert.h:219
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_ASSERT_SOFT
#define RCU_ASSERT_SOFT(x)
Definition
Assert.h:155
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:325
MsgStreamMacros.h
MsgStream.h
Job.h
OutputStream.h
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition
TRTCalib_makeplots.cxx:4025
ClassImp
ClassImp(EL::UnitTestAlg2) namespace EL
Definition
UnitTestAlg2.cxx:30
UnitTestAlg2.h
Worker.h
EL::UnitTestAlg2
Definition
UnitTestAlg2.h:27
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
msg
MsgStream & msg
Definition
testRead.cxx:32
tree
TChain * tree
Definition
tile_monitor.h:30
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0