The Gaudi Framework
master (123e188a)
Toggle main menu visibility
Loading...
Searching...
No Matches
NTupleWriterAlg.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 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 "COPYING". *
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 <
Gaudi/Algorithm.h
>
12
#include <
Gaudi/Interfaces/IFileSvc.h
>
13
#include <TTree.h>
14
15
namespace
Gaudi::TestSuite::FileSvc
{
16
class
NTupleWriterAlg
:
public
Gaudi::Algorithm
{
17
public
:
18
NTupleWriterAlg
(
const
std::string& n,
ISvcLocator
* l ) :
Algorithm
( n, l ) {}
19
20
StatusCode
initialize
()
override
{
21
return
Gaudi::Algorithm::initialize
().
andThen
( [
this
]() {
22
m_fileSvc
=
service<Gaudi::Interfaces::IFileSvc>
(
"FileSvc"
);
23
if
( !
m_fileSvc
) {
24
error
() <<
"Failed to retrieve FileSvc"
<<
endmsg
;
25
return
StatusCode::FAILURE
;
26
}
27
28
m_file
=
m_fileSvc
->getFile(
"Ntuple"
);
29
if
( !
m_file
) {
30
error
() <<
"Failed to retrieve TFile"
<<
endmsg
;
31
return
StatusCode::FAILURE
;
32
}
33
34
m_tree
= std::make_unique<TTree>(
"FileSvcNTuple"
,
"An example NTuple"
).release();
35
m_tree
->Branch(
"value"
, &
m_value
);
36
37
return
StatusCode::SUCCESS
;
38
} );
39
}
40
41
StatusCode
execute
(
const
EventContext
& )
const override
{
42
m_tree
->Fill();
43
return
StatusCode::SUCCESS
;
44
}
45
46
StatusCode
finalize
()
override
{
47
m_tree
->Write();
48
return
Gaudi::Algorithm::finalize
();
49
}
50
51
private
:
52
Gaudi::Interfaces::IFileSvc
*
m_fileSvc
{
nullptr
};
53
std::shared_ptr<TFile>
m_file
;
54
TTree*
m_tree
{
nullptr
};
55
int
m_value
{ 9 };
56
};
57
58
DECLARE_COMPONENT
( NTupleWriterAlg )
59
}
// namespace Gaudi::TestSuite::FileSvc
Algorithm.h
IFileSvc.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
EventContext
This class represents an entry point to all the event specific data.
Definition
EventContext.h:35
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition
Algorithm.h:87
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition
Algorithm.h:98
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition
Algorithm.h:175
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition
Algorithm.h:181
Gaudi::Algorithm::service
SmartIF< IService > service(std::string_view name, const bool createIf=true, const bool quiet=false) const
Return a pointer to the service identified by name (or "type/name").
Definition
Algorithm.cpp:621
Gaudi::TestSuite::FileSvc::NTupleWriterAlg::execute
StatusCode execute(const EventContext &) const override
Definition
NTupleWriterAlg.cpp:41
Gaudi::TestSuite::FileSvc::NTupleWriterAlg::m_tree
TTree * m_tree
Definition
NTupleWriterAlg.cpp:54
Gaudi::TestSuite::FileSvc::NTupleWriterAlg::m_file
std::shared_ptr< TFile > m_file
Definition
NTupleWriterAlg.cpp:53
Gaudi::TestSuite::FileSvc::NTupleWriterAlg::initialize
StatusCode initialize() override
Definition
NTupleWriterAlg.cpp:20
Gaudi::TestSuite::FileSvc::NTupleWriterAlg::finalize
StatusCode finalize() override
Definition
NTupleWriterAlg.cpp:46
Gaudi::TestSuite::FileSvc::NTupleWriterAlg::NTupleWriterAlg
NTupleWriterAlg(const std::string &n, ISvcLocator *l)
Definition
NTupleWriterAlg.cpp:18
Gaudi::TestSuite::FileSvc::NTupleWriterAlg::m_value
int m_value
Definition
NTupleWriterAlg.cpp:55
Gaudi::TestSuite::FileSvc::NTupleWriterAlg::m_fileSvc
Gaudi::Interfaces::IFileSvc * m_fileSvc
Definition
NTupleWriterAlg.cpp:52
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition
ISvcLocator.h:42
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::andThen
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition
StatusCode.h:151
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi::TestSuite::FileSvc
Definition
HistogramWriterAlg.cpp:15
Gaudi::Interfaces::IFileSvc
Interface for a component that manages file access within Gaudi applications.
Definition
IFileSvc.h:27
GaudiTestSuite
src
FileSvc
NTupleWriterAlg.cpp
Generated on
for The Gaudi Framework by
1.17.0