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
// EDM include(s):
9
#include "
AthContainers/AuxElement.h
"
10
#include "
AthContainers/AuxVectorBase.h
"
11
12
// ROOT include(s):
13
#include <TClass.h>
14
#include <TFile.h>
15
16
// Gaudi/EventLoop include(s):
17
#ifdef XAOD_STANDALONE
18
#include "
EventLoop/Worker.h
"
19
#endif
20
21
namespace
CP
{
22
23
StatusCode
RNtupleTreeMakerAlg::initialize
() {
24
if
(
m_branches
.empty() ) {
25
ATH_MSG_ERROR
(
"No branches set up for writing"
);
26
return
StatusCode::FAILURE;
27
}
28
ATH_CHECK
(
m_systematicsService
.retrieve() );
29
m_isInitialized
=
false
;
30
return
StatusCode::SUCCESS;
31
}
32
33
StatusCode
RNtupleTreeMakerAlg::execute
(
const
EventContext&
/*ctx*/
) {
34
if
( !
m_isInitialized
) {
35
m_model
= ROOT::RNTupleModel::Create();
36
if
( !
m_model
) {
37
ATH_MSG_ERROR
(
"Failed to create RNTupleModel"
);
38
return
StatusCode::FAILURE;
39
}
40
41
ATH_CHECK
(
setupTree
() );
42
43
TFile* outputFile =
nullptr
;
44
#ifdef XAOD_STANDALONE
45
if
( wk() ) {
46
outputFile = wk()->getOutputFile(
m_outputStreamName
.value() );
47
}
else
{
48
ATH_MSG_ERROR
(
"Worker not available in standalone mode"
);
49
return
StatusCode::FAILURE;
50
}
51
#else
52
// naive implementation for AthAnalysis, I don't see any Ath Svc offer getting the output stream easily
53
outputFile = TFile::Open(
m_outputStreamName
.value().c_str(),
"UPDATE"
);
54
#endif
55
56
if
( !outputFile ) {
57
ATH_MSG_ERROR
(
"Could not retrieve file for stream: "
<<
m_outputStreamName
.value() );
58
return
StatusCode::FAILURE;
59
}
60
61
try
{
62
m_writer
= ROOT::RNTupleWriter::Append( std::move(
m_model
),
m_modelName
.value(), *outputFile );
63
}
catch
(
const
std::exception&
e
) {
64
ATH_MSG_ERROR
(
"Failed to create RNTupleWriter: "
<<
e
.what() );
65
return
StatusCode::FAILURE;
66
}
67
68
m_isInitialized
=
true
;
69
}
70
71
ATH_CHECK
(
m_processorList
.process( *(
evtStore
()) ) );
72
73
if
(
m_writer
) {
74
m_writer
->Fill();
75
}
76
77
return
StatusCode::SUCCESS;
78
}
79
80
StatusCode
RNtupleTreeMakerAlg::finalize
() {
81
m_writer
.reset();
82
return
StatusCode::SUCCESS;
83
}
84
85
StatusCode
RNtupleTreeMakerAlg::setupTree
() {
86
std::unordered_set<std::string> nonContainerSet(
m_nonContainers
.begin(),
m_nonContainers
.end() );
87
ATH_CHECK
(
m_processorList
.setupTree(
m_branches
, std::move(nonContainerSet), *
m_systematicsService
, *
m_model
) );
88
return
StatusCode::SUCCESS;
89
}
90
91
92
93
// Removed old ContainerProcessor/ElementProcessor implementations as they are now in FieldHelpers
94
}
// 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:33
AuxElement.h
Base class for elements of a container that can have aux data.
AuxVectorBase.h
Manage index tracking and synchronization of auxiliary data.
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:58
CP::RNtupleTreeMakerAlg::m_branches
Gaudi::Property< std::vector< std::string > > m_branches
Definition
RNtupleTreeMakerAlg.h:55
CP::RNtupleTreeMakerAlg::m_outputStreamName
Gaudi::Property< std::string > m_outputStreamName
Definition
RNtupleTreeMakerAlg.h:52
CP::RNtupleTreeMakerAlg::setupTree
StatusCode setupTree()
Function setting up the internal data structures on the first event.
Definition
RNtupleTreeMakerAlg.cxx:85
CP::RNtupleTreeMakerAlg::m_isInitialized
bool m_isInitialized
Definition
RNtupleTreeMakerAlg.h:75
CP::RNtupleTreeMakerAlg::m_modelName
Gaudi::Property< std::string > m_modelName
Definition
RNtupleTreeMakerAlg.h:49
CP::RNtupleTreeMakerAlg::m_processorList
CP::RNtupleFieldHelpers::ProcessorList m_processorList
Definition
RNtupleTreeMakerAlg.h:73
CP::RNtupleTreeMakerAlg::m_writer
std::unique_ptr< ROOT::RNTupleWriter > m_writer
Definition
RNtupleTreeMakerAlg.h:71
CP::RNtupleTreeMakerAlg::initialize
virtual StatusCode initialize() override
Function executed during algorithm initialization.
Definition
RNtupleTreeMakerAlg.cxx:23
CP::RNtupleTreeMakerAlg::m_systematicsService
ServiceHandle< ISystematicsSvc > m_systematicsService
Service handle for systematics.
Definition
RNtupleTreeMakerAlg.h:64
CP::RNtupleTreeMakerAlg::finalize
virtual StatusCode finalize() override
Function executed during algo finalization.
Definition
RNtupleTreeMakerAlg.cxx:80
CP::RNtupleTreeMakerAlg::m_model
std::unique_ptr< ROOT::RNTupleModel > m_model
Definition
RNtupleTreeMakerAlg.h:70
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