The Gaudi Framework
master (bb4415cc)
Toggle main menu visibility
Loading...
Searching...
No Matches
NTupleAlgorithm.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
// Include files
12
#include "
NTupleAlgorithm.h
"
13
14
#include <
GaudiKernel/IHistogramSvc.h
>
15
#include <
GaudiKernel/MsgStream.h
>
16
#include <
GaudiKernel/SmartDataPtr.h
>
17
18
#include <
GaudiKernel/INTupleSvc.h
>
19
20
#include <math.h>
21
22
DECLARE_COMPONENT
(
NTupleAlgorithm
)
23
24
//------------------------------------------------------------------------------
25
NTupleAlgorithm
::
NTupleAlgorithm
( const
std
::
string
&
name
,
ISvcLocator
* pSvcLocator )
26
:
Algorithm
(
name
, pSvcLocator )
27
//------------------------------------------------------------------------------
28
{
29
m_tuple1
=
nullptr
;
30
m_tuple2
=
nullptr
;
31
}
32
33
//------------------------------------------------------------------------------
34
StatusCode
NTupleAlgorithm::initialize
()
35
//------------------------------------------------------------------------------
36
{
37
// Book N-tuple 1
38
NTuplePtr
nt1(
ntupleSvc
(),
"MyTuples/1"
);
39
if
( nt1 )
40
m_tuple1
= nt1;
41
else
{
42
m_tuple1
=
ntupleSvc
()->
book
(
"MyTuples/1"
, CLID_RowWiseTuple,
"Row-wise N-Tuple example"
);
43
if
(
m_tuple1
) {
44
m_tuple1
->addItem(
"Ntrack"
,
m_ntrk
).ignore();
45
m_tuple1
->addItem(
"Energy"
,
m_energy
).ignore();
46
}
else
{
// did not manage to book the N tuple....
47
error
() <<
" Cannot book N-tuple:"
<< long(
m_tuple1
) <<
endmsg
;
48
return
StatusCode::FAILURE
;
49
}
50
}
51
52
// Book N-tuple 2
53
NTuplePtr
nt2(
ntupleSvc
(),
"MyTuples/simple/2"
);
54
if
( nt2 )
55
m_tuple2
= nt2;
56
else
{
57
m_tuple2
=
ntupleSvc
()->
book
(
"MyTuples/simple/2"
, CLID_ColumnWiseTuple,
"Col-Wise NTuple examples"
);
58
if
(
m_tuple2
) {
59
m_tuple2
->addItem(
"N"
,
m_n
, 0, 100 ).ignore();
60
m_tuple2
->addItem(
"FNumbers"
,
m_n
,
m_fNumbers
).ignore();
61
m_tuple2
->addItem(
"INumbers"
,
m_n
,
m_iNumbers
).ignore();
62
}
else
{
// did not manage to book the N tuple....
63
error
() <<
" Cannot book N-tuple:"
<< long(
m_tuple2
) <<
endmsg
;
64
return
StatusCode::FAILURE
;
65
}
66
}
67
info
() <<
"Finished booking NTuples"
<<
endmsg
;
68
return
StatusCode::SUCCESS
;
69
}
70
71
//------------------------------------------------------------------------------
72
StatusCode
NTupleAlgorithm::execute
()
73
//------------------------------------------------------------------------------
74
{
75
StatusCode
status;
76
77
static
int
n = 0;
78
79
m_ntrk
= long( sin(
double
( n ) ) * 52. + 50. );
80
m_energy
= float( sin(
double
( n ) ) * 52. + 50. );
81
82
m_n
= long( abs( ( 12345 * ( n + 1 ) ) % 100 ) );
83
84
for
(
int
i = 0; i <
m_n
; i++ ) {
85
m_fNumbers
[i] = float( cos(
double
( 2 * n ) ) * 52. + 50. );
86
m_iNumbers
[i] = long( cos(
double
( 2 * n ) ) * 52. + 50. );
87
}
88
n++;
89
90
status =
m_tuple1
->write();
91
if
( status.
isFailure
() ) {
92
error
() <<
" Cannot fill N-tuple:"
<< long(
m_tuple1
) <<
endmsg
;
93
return
StatusCode::FAILURE
;
94
}
95
status =
m_tuple2
->write();
96
if
( status.
isFailure
() ) {
97
error
() <<
" Cannot fill N-tuple:"
<< long(
m_tuple2
) <<
endmsg
;
98
return
StatusCode::FAILURE
;
99
}
100
101
return
StatusCode::SUCCESS
;
102
}
103
104
//------------------------------------------------------------------------------
105
StatusCode
NTupleAlgorithm::finalize
()
106
//------------------------------------------------------------------------------
107
{
108
info
() <<
"Finalizing..."
<<
endmsg
;
109
return
StatusCode::SUCCESS
;
110
}
IHistogramSvc.h
INTupleSvc.h
MsgStream.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
NTuplePtr
SmartDataPtr< NTuple::Tuple > NTuplePtr
Definition
NTuple.h:1020
NTupleAlgorithm.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
SmartDataPtr.h
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:115
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition
Algorithm.h:98
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition
Algorithm.cpp:518
Gaudi::Algorithm::ntupleSvc
SmartIF< INTupleSvc > & ntupleSvc() const
The standard N tuple service.
Definition
Algorithm.cpp:554
INTupleSvc::book
virtual NTuple::Tuple * book(const std::string &fullPath, const CLID &type, const std::string &title)=0
Book Ntuple and register it with the data store.
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition
ISvcLocator.h:42
NTupleAlgorithm
Definition
NTupleAlgorithm.h:19
NTupleAlgorithm::m_fNumbers
NTuple::Array< float > m_fNumbers
Definition
NTupleAlgorithm.h:38
NTupleAlgorithm::finalize
StatusCode finalize() override
Definition
NTupleAlgorithm.cpp:105
NTupleAlgorithm::m_iNumbers
NTuple::Array< long > m_iNumbers
Definition
NTupleAlgorithm.h:37
NTupleAlgorithm::NTupleAlgorithm
NTupleAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition
NTupleAlgorithm.cpp:25
NTupleAlgorithm::m_tuple2
NTuple::Tuple * m_tuple2
Definition
NTupleAlgorithm.h:32
NTupleAlgorithm::initialize
StatusCode initialize() override
Definition
NTupleAlgorithm.cpp:34
NTupleAlgorithm::execute
StatusCode execute() override
Definition
NTupleAlgorithm.cpp:72
NTupleAlgorithm::m_tuple1
NTuple::Tuple * m_tuple1
Definition
NTupleAlgorithm.h:31
NTupleAlgorithm::m_ntrk
NTuple::Item< long > m_ntrk
Definition
NTupleAlgorithm.h:34
NTupleAlgorithm::m_n
NTuple::Item< long > m_n
Definition
NTupleAlgorithm.h:39
NTupleAlgorithm::m_energy
NTuple::Item< float > m_energy
Definition
NTupleAlgorithm.h:35
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
std
STL namespace.
GaudiTestSuite
src
NTuples
NTupleAlgorithm.cpp
Generated on
for The Gaudi Framework by
1.17.0