ATLAS Offline Software
Loading...
Searching...
No Matches
RNtupleFieldHelpers.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef ASGANALYSISALGORITHMS_RNTUPLEFIELDHELPERS_H
5#define ASGANALYSISALGORITHMS_RNTUPLEFIELDHELPERS_H
6
7// Framework include(s):
15
16// EDM include(s):
19#include "TreeBranchHelpers.h"
20
21// ROOT include(s):
22#include <ROOT/RNTupleModel.hxx>
23
24// System include(s):
25#include <string>
26#include <vector>
27#include <memory>
28#include <functional>
29#include <typeinfo>
30#include <set>
31
32namespace SG {
35}
36
37namespace CP {
38
40
41#ifdef XAOD_STANDALONE
43#else
45#endif
47
49
50 struct FieldOps {
51 std::function<void(size_t)> resize;
52 std::function<void*()> getData;
53 };
54
55 // ----------------------------------------------------------------------
56 // Field Processors
57 // ----------------------------------------------------------------------
59 public:
61 virtual ~ElementFieldProcessor() = default;
64
65 virtual StatusCode setup( ROOT::RNTupleModel& model,
66 const BranchConfig& branchConfig,
67 OutputBranchData& outputData,
68 MsgStream& msg ) override;
69
70 StatusCode process( const SG::AuxElement& element, MsgStream& msg );
71 virtual StatusCode setup ( TTree& /* tree */,
72 const BranchConfig& /* branchConfig */,
73 OutputBranchData& /* outputData */,
74 MsgStream& msg ) override;
75
76 std::string m_fieldName;
77 std::unique_ptr< SG::TypelessConstAccessor > m_acc;
79 std::shared_ptr<void> m_field;
80 void* m_dataPtr = nullptr;
81 };
82
84 public:
86 virtual ~ContainerFieldProcessor() = default;
89
90 virtual StatusCode setup( ROOT::RNTupleModel& model,
91 const BranchConfig& branchConfig,
92 OutputBranchData& outputData,
93 MsgStream& msg ) override;
94
95 virtual StatusCode setup ( TTree& /* tree */,
96 const BranchConfig& /* branchConfig */,
97 OutputBranchData& /* outputData */,
98 MsgStream& msg ) override;
99
100 StatusCode resize( size_t size, MsgStream& msg );
101
102 StatusCode process( const SG::AuxElement& element, size_t index, MsgStream& msg );
103
104 void* getData() const { return m_ops.getData ? m_ops.getData() : nullptr; }
105
106
107 std::string m_fieldName;
108 std::unique_ptr< SG::TypelessConstAccessor > m_acc;
110 std::shared_ptr<void> m_field;
111 void* m_dataPtr = nullptr;
112 // Field operation is needed here but not in ttree because ttree works by creating a branch and feed a pointer to the data to manage.
113 // You can pre-define how to resize aux vector in compile time for ttree, aka "IAuxTypeVector"
114 // In RNTuple, "model" will give you a shared pointer of the primitive type you requested. This request is made in run-time.
115 // That is why unlike ttree, we need an operator that takes lambda function to do the resize in the run time.
117 };
118
119
120 // ----------------------------------------------------------------------
121 // Object Processors Interface
122 // ----------------------------------------------------------------------
123
125 public:
126 ElementProcessor(const std::string& sgName);
127 virtual ~ElementProcessor() = default;
130
131 virtual StatusCode retrieveProcess( StoreType& evtStore ) override;
132
133 virtual StatusCode addBranch( ROOT::RNTupleModel& model,
134 const BranchConfig& branchConfig,
135 OutputBranchData& outputData ) override;
136
137 virtual StatusCode addBranch( TTree& tree,
138 const BranchConfig& branchConfig,
139 OutputBranchData& outputData ) override;
140
141 private:
142 std::string m_sgName;
143 std::vector< std::unique_ptr<ElementFieldProcessor> > m_fields;
144 };
145
146
148 public:
149 ContainerProcessor(const std::string& sgName);
150 virtual ~ContainerProcessor() = default;
153
154 virtual StatusCode retrieveProcess( StoreType& evtStore ) override;
155
156 virtual StatusCode addBranch( ROOT::RNTupleModel& model,
157 const BranchConfig& branchConfig,
158 OutputBranchData& outputData ) override;
159
160 virtual StatusCode addBranch( TTree& tree,
161 const BranchConfig& branchConfig,
162 OutputBranchData& outputData ) override;
163
164 private:
165 std::string m_sgName;
166 std::vector< std::unique_ptr<ContainerFieldProcessor> > m_fields;
167 TVirtualCollectionProxy* m_collProxy = nullptr;
169 };
170
172 public:
173 using AsgMessagingForward::AsgMessagingForward;
174 virtual ~ProcessorList() = default;
175 ProcessorList( const ProcessorList& ) = delete;
177
178 StatusCode setupTree( const std::vector<std::string>& branches,
179 std::unordered_set<std::string> nonContainers,
180 ISystematicsSvc& sysSvc,
181 ROOT::RNTupleModel& model );
182
183 StatusCode setupBranch( const BranchConfig& branchConfig,
184 OutputBranchData& outputData,
185 ROOT::RNTupleModel& model );
186
187 StatusCode process( StoreType& evtStore );
188
189 TreeBranchHelpers::IObjectProcessor& getObjectProcessor( const BranchConfig& /*branchConfig*/, const std::string& sgName );
190 std::optional<int> defaultBasketSize;
191 std::unordered_set<std::string> m_nonContainers;
192 std::unordered_map< std::string, std::unique_ptr<TreeBranchHelpers::IObjectProcessor> > m_processors;
193 };
194
195 } // namespace RNtupleFieldHelpers
196} // namespace CP
197
198#endif // ASGANALYSISALGORITHMS_RNTUPLEFIELDHELPERS_H
Base class for elements of a container that can have aux data.
Manage index tracking and synchronization of auxiliary data.
the interface for the central systematics service
ContainerFieldProcessor & operator=(const ContainerFieldProcessor &)=delete
std::unique_ptr< SG::TypelessConstAccessor > m_acc
ContainerFieldProcessor(const ContainerFieldProcessor &)=delete
virtual StatusCode setup(ROOT::RNTupleModel &model, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg) override
StatusCode resize(size_t size, MsgStream &msg)
virtual StatusCode addBranch(ROOT::RNTupleModel &model, const BranchConfig &branchConfig, OutputBranchData &outputData) override
ContainerProcessor & operator=(const ContainerProcessor &)=delete
std::vector< std::unique_ptr< ContainerFieldProcessor > > m_fields
ContainerProcessor(const ContainerProcessor &)=delete
virtual StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
ElementFieldProcessor(const ElementFieldProcessor &)=delete
std::unique_ptr< SG::TypelessConstAccessor > m_acc
ElementFieldProcessor & operator=(const ElementFieldProcessor &)=delete
virtual StatusCode setup(ROOT::RNTupleModel &model, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg) override
const SG::IAuxTypeVectorFactory * m_factory
ElementProcessor & operator=(const ElementProcessor &)=delete
virtual StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
ElementProcessor(const ElementProcessor &)=delete
std::vector< std::unique_ptr< ElementFieldProcessor > > m_fields
virtual StatusCode addBranch(ROOT::RNTupleModel &model, const BranchConfig &branchConfig, OutputBranchData &outputData) override
ProcessorList & operator=(const ProcessorList &)=delete
StatusCode setupTree(const std::vector< std::string > &branches, std::unordered_set< std::string > nonContainers, ISystematicsSvc &sysSvc, ROOT::RNTupleModel &model)
std::unordered_set< std::string > m_nonContainers
std::unordered_map< std::string, std::unique_ptr< TreeBranchHelpers::IObjectProcessor > > m_processors
TreeBranchHelpers::IObjectProcessor & getObjectProcessor(const BranchConfig &, const std::string &sgName)
StatusCode setupBranch(const BranchConfig &branchConfig, OutputBranchData &outputData, ROOT::RNTupleModel &model)
ProcessorList(const ProcessorList &)=delete
the interface class for branch processors
the interface class for classes reading an object from the event store and processing it
Base class for elements of a container that can have aux data.
Definition AuxElement.h:484
Interface for factory objects that create vectors.
Helper class to provide const generic access to aux data.
The Athena Transient Store API.
base class to forward messages to another class
Class mimicking the AthMessaging class from the offline software.
Wrapper for TEvent to make it look like StoreGate.
Definition SgTEvent.h:44
const std::string process
TreeBranchHelpers::OutputBranchData OutputBranchData
TreeBranchHelpers::BranchConfig BranchConfig
Select isolated Photons, Electrons and Muons.
Forward declaration.
Definition index.py:1
void ErrorHandler ATLAS_NOT_THREAD_SAFE(Int_t level, Bool_t abort, const char *location, const char *message)
Function filtering the warnings coming from ROOT.
Definition Init.cxx:105
std::function< void(size_t)> resize
the user configuration of an output branch
the data for a single output branch
MsgStream & msg
Definition testRead.cxx:32
TChain * tree