ATLAS Offline Software
Loading...
Searching...
No Matches
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):
7
8// EDM include(s):
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
21namespace CP {
22
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
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
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
81 m_writer.reset();
82 return StatusCode::SUCCESS;
83 }
84
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Base class for elements of a container that can have aux data.
Manage index tracking and synchronization of auxiliary data.
virtual StatusCode execute() override
Function executed once per event.
Gaudi::Property< std::vector< std::string > > m_nonContainers
Gaudi::Property< std::vector< std::string > > m_branches
Gaudi::Property< std::string > m_outputStreamName
StatusCode setupTree()
Function setting up the internal data structures on the first event.
Gaudi::Property< std::string > m_modelName
CP::RNtupleFieldHelpers::ProcessorList m_processorList
std::unique_ptr< ROOT::RNTupleWriter > m_writer
virtual StatusCode initialize() override
Function executed during algorithm initialization.
ServiceHandle< ISystematicsSvc > m_systematicsService
Service handle for systematics.
virtual StatusCode finalize() override
Function executed during algo finalization.
std::unique_ptr< ROOT::RNTupleModel > m_model
Select isolated Photons, Electrons and Muons.