ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaExamples
AthExHistNtup
src
Ntup.cxx
Go to the documentation of this file.
1
2
3
/*
4
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5
*/
6
7
// Ntup.cxx
8
// Implementation file for class Ntup
9
// Author: S.Binet<binet@cern.ch>
11
12
// AthExHistNtup includes
13
#include "
Ntup.h
"
14
15
// ROOT includes
16
#include "TTree.h"
17
18
using namespace
AthEx
;
19
21
// Public methods:
23
24
// Constructors
26
Ntup::Ntup
(
const
std::string& name,
27
ISvcLocator* pSvcLocator ) :
28
::
AthAlgorithm
( name, pSvcLocator ),
29
m_size
(0),
30
m_run
(0),
31
m_event
(0),
32
m_ntuple
(0)
33
{ }
34
35
// Destructor
37
Ntup::~Ntup
()
38
{}
39
40
// Athena Algorithm's Hooks
42
StatusCode
Ntup::initialize
()
43
{
44
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
);
45
ATH_CHECK
(
m_ntSvc
.retrieve() );
46
ATH_CHECK
(
m_evt
.initialize() );
47
48
// register our n-tuple with the svc
49
m_ntuple
=
new
TTree(
"tree1"
,
"tree title"
);
50
if
(!
m_ntSvc
->regTree(
"/rec/trees/tree1"
,
m_ntuple
).isSuccess()) {
51
ATH_MSG_ERROR
(
"could not register tree [tree1]"
);
52
delete
m_ntuple
;
m_ntuple
= 0;
53
return
StatusCode::FAILURE;
54
}
55
56
// book branches
57
m_ntuple
->Branch(
"size"
, &
m_size
,
"size/i"
);
58
m_ntuple
->Branch(
"run"
, &
m_run
,
"run/i"
);
59
m_ntuple
->Branch(
"rundata"
, &
m_rundata
);
60
61
return
StatusCode::SUCCESS;
62
}
63
64
StatusCode
Ntup::finalize
()
65
{
66
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
67
68
return
StatusCode::SUCCESS;
69
}
70
71
StatusCode
Ntup::execute
(
const
EventContext& ctx)
72
{
73
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
74
75
// clear data...
76
m_rundata
.clear();
77
m_size
= 0;
78
m_event
= 0;
79
m_run
= 0;
80
81
// get event data...
82
SG::ReadHandle<xAOD::EventInfo>
evt(
m_evt
, ctx);
83
if
(!evt.isValid()) {
84
ATH_MSG_ERROR
(
"Could not retrieve EventInfo obj"
);
85
return
StatusCode::FAILURE;
86
}
87
88
m_event
= evt->eventNumber();
89
m_size
= 2 + (
m_event
% 3);
90
m_run
= evt->runNumber();
91
92
m_rundata
.resize(
m_size
);
93
m_rundata
[0] =
m_run
;
94
m_rundata
[1] =
m_event
;
95
for
(
unsigned
int
i=2; i <
m_size
; ++i) {
96
m_rundata
[i] = i;
97
}
98
99
// fill n-tuple
100
if
(
m_ntuple
->Fill() == -1) {
101
ATH_MSG_WARNING
(
"problems writing n-tuple"
);
102
}
103
104
ATH_MSG_INFO
(
"run: ["
<<
m_run
<<
"]"
<<
endmsg
<<
105
"size: ["
<<
m_size
<<
"]"
<<
endmsg
<<
106
"rundata-sz: ["
<<
m_rundata
.size() <<
"]"
);
107
108
return
StatusCode::SUCCESS;
109
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:61
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
Ntup.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthEx::Ntup::Ntup
Ntup()
Default constructor:
AthEx::Ntup::finalize
virtual StatusCode finalize()
Definition
Ntup.cxx:64
AthEx::Ntup::m_evt
SG::ReadHandleKey< xAOD::EventInfo > m_evt
key to the event-info
Definition
Ntup.h:76
AthEx::Ntup::execute
virtual StatusCode execute(const EventContext &ctx)
Execute method.
Definition
Ntup.cxx:71
AthEx::Ntup::m_run
unsigned int m_run
Definition
Ntup.h:68
AthEx::Ntup::m_ntuple
TTree * m_ntuple
pointer to the n-tuple
Definition
Ntup.h:73
AthEx::Ntup::m_rundata
std::vector< long > m_rundata
Definition
Ntup.h:70
AthEx::Ntup::initialize
virtual StatusCode initialize()
Definition
Ntup.cxx:42
AthEx::Ntup::m_event
unsigned int m_event
Definition
Ntup.h:69
AthEx::Ntup::m_size
unsigned int m_size
Definition
Ntup.h:67
AthEx::Ntup::~Ntup
virtual ~Ntup()
Destructor:
Definition
Ntup.cxx:37
AthEx::Ntup::m_ntSvc
ServiceHandle< ITHistSvc > m_ntSvc
handle to the histogram service
Definition
Ntup.h:64
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
AthEx
Definition
Hist.h:27
Generated on
for ATLAS Offline Software by
1.17.0