ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
AsgAnalysisAlgorithms
Root
RNtupleTreeMakerAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Local include(s):
6
#include "
AsgAnalysisAlgorithms/RNtupleTreeMakerAlg.h
"
7
8
// ROOT include(s):
9
#include <TFile.h>
10
11
// Gaudi/EventLoop include(s):
12
#ifdef XAOD_STANDALONE
13
#include "
EventLoop/Worker.h
"
14
#endif
15
16
namespace
CP
{
17
18
StatusCode
RNtupleTreeMakerAlg::initialize
() {
19
if
(
m_branches
.empty() ) {
20
ATH_MSG_ERROR
(
"No branches set up for writing"
);
21
return
StatusCode::FAILURE;
22
}
23
ATH_CHECK
(
m_systematicsService
.retrieve() );
24
m_isInitialized
=
false
;
25
return
StatusCode::SUCCESS;
26
}
27
28
StatusCode
RNtupleTreeMakerAlg::execute
(
const
EventContext&
/*ctx*/
) {
29
if
( !
m_isInitialized
) {
30
m_model
= ROOT::RNTupleModel::Create();
31
if
( !
m_model
) {
32
ATH_MSG_ERROR
(
"Failed to create RNTupleModel"
);
33
return
StatusCode::FAILURE;
34
}
35
36
ATH_CHECK
(
setupTree
() );
37
38
TFile* outputFile =
nullptr
;
39
#ifdef XAOD_STANDALONE
40
if
( wk() ) {
41
outputFile = wk()->getOutputFile(
m_outputStreamName
.value() );
42
}
else
{
43
ATH_MSG_ERROR
(
"Worker not available in standalone mode"
);
44
return
StatusCode::FAILURE;
45
}
46
#else
47
// naive implementation for AthAnalysis, I don't see any Ath Svc offer getting the output stream easily
48
m_outputFile
.reset( TFile::Open(
m_outputStreamName
.value().c_str(),
"UPDATE"
) );
49
if
(
m_outputFile
&&
m_outputFile
->IsZombie())
m_outputFile
.reset();
50
outputFile =
m_outputFile
.get();
51
#endif
52
53
if
( !outputFile ) {
54
ATH_MSG_ERROR
(
"Could not retrieve file for stream: "
<<
m_outputStreamName
.value() );
55
return
StatusCode::FAILURE;
56
}
57
58
try
{
59
m_writer
= ROOT::RNTupleWriter::Append( std::move(
m_model
),
m_modelName
.value(), *outputFile );
60
}
catch
(
const
std::exception&
e
) {
61
ATH_MSG_ERROR
(
"Failed to create RNTupleWriter: "
<<
e
.what() );
62
return
StatusCode::FAILURE;
63
}
64
65
m_isInitialized
=
true
;
66
}
67
68
ATH_CHECK
(
m_processorList
.process( *(
evtStore
()) ) );
69
70
if
(
m_writer
) {
71
m_writer
->Fill();
72
}
73
74
return
StatusCode::SUCCESS;
75
}
76
77
StatusCode
RNtupleTreeMakerAlg::finalize
() {
78
m_writer
.reset();
79
#ifndef XAOD_STANDALONE
80
if
(
m_outputFile
) {
81
m_outputFile
->Close();
82
m_outputFile
.reset();
83
}
84
#endif
85
return
StatusCode::SUCCESS;
86
}
87
88
StatusCode
RNtupleTreeMakerAlg::setupTree
() {
89
std::unordered_set<std::string> nonContainerSet(
m_nonContainers
.begin(),
m_nonContainers
.end() );
90
ATH_CHECK
(
m_processorList
.setupTree(
m_branches
, std::move(nonContainerSet), *
m_systematicsService
, *
m_model
) );
91
return
StatusCode::SUCCESS;
92
}
93
94
95
96
// Removed old ContainerProcessor/ElementProcessor implementations as they are now in FieldHelpers
97
}
// namespace CP
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:47
RNtupleTreeMakerAlg.h
Worker.h
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
CP::RNtupleTreeMakerAlg::m_nonContainers
Gaudi::Property< std::vector< std::string > > m_nonContainers
Definition
RNtupleTreeMakerAlg.h:59
CP::RNtupleTreeMakerAlg::m_branches
Gaudi::Property< std::vector< std::string > > m_branches
Definition
RNtupleTreeMakerAlg.h:56
CP::RNtupleTreeMakerAlg::m_outputStreamName
Gaudi::Property< std::string > m_outputStreamName
Definition
RNtupleTreeMakerAlg.h:53
CP::RNtupleTreeMakerAlg::setupTree
StatusCode setupTree()
Function setting up the internal data structures on the first event.
Definition
RNtupleTreeMakerAlg.cxx:88
CP::RNtupleTreeMakerAlg::m_isInitialized
bool m_isInitialized
Definition
RNtupleTreeMakerAlg.h:76
CP::RNtupleTreeMakerAlg::m_modelName
Gaudi::Property< std::string > m_modelName
Definition
RNtupleTreeMakerAlg.h:50
CP::RNtupleTreeMakerAlg::m_processorList
CP::RNtupleFieldHelpers::ProcessorList m_processorList
Definition
RNtupleTreeMakerAlg.h:74
CP::RNtupleTreeMakerAlg::m_writer
std::unique_ptr< ROOT::RNTupleWriter > m_writer
Definition
RNtupleTreeMakerAlg.h:72
CP::RNtupleTreeMakerAlg::initialize
virtual StatusCode initialize() override
Function executed during algorithm initialization.
Definition
RNtupleTreeMakerAlg.cxx:18
CP::RNtupleTreeMakerAlg::m_systematicsService
ServiceHandle< ISystematicsSvc > m_systematicsService
Service handle for systematics.
Definition
RNtupleTreeMakerAlg.h:65
CP::RNtupleTreeMakerAlg::finalize
virtual StatusCode finalize() override
Function executed during algo finalization.
Definition
RNtupleTreeMakerAlg.cxx:77
CP::RNtupleTreeMakerAlg::m_model
std::unique_ptr< ROOT::RNTupleModel > m_model
Definition
RNtupleTreeMakerAlg.h:71
CP::RNtupleTreeMakerAlg::m_outputFile
std::unique_ptr< TFile > m_outputFile
Definition
RNtupleTreeMakerAlg.h:79
EL::AnaAlgorithm::execute
virtual::StatusCode execute()
execute this algorithm
Definition
AnaAlgorithm.cxx:315
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
xAOD::e
setPy e
Definition
CompositeParticle_v1.cxx:166
Generated on
for ATLAS Offline Software by
1.17.0