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
20// ROOT include(s):
21#include <ROOT/RNTupleModel.hxx>
22
23// System include(s):
24#include <string>
25#include <vector>
26#include <memory>
27#include <functional>
28#include <typeinfo>
29#include <set>
30
31namespace SG {
34}
35
36namespace CP {
37
39
40#ifdef XAOD_STANDALONE
41 using StoreType = asg::SgEvent;
42#else
44#endif
46
48
49 struct FieldOps {
50 std::function<void(size_t)> resize;
51 std::function<void*()> getData;
52 };
53
54 // ----------------------------------------------------------------------
55 // Field Processors
56 // ----------------------------------------------------------------------
58 public:
60 virtual ~ElementFieldProcessor() = default;
63
64 virtual StatusCode setup( ROOT::RNTupleModel& model,
65 const BranchConfig& branchConfig,
66 OutputBranchData& outputData,
67 MsgStream& msg ) override;
68
69 StatusCode process( const SG::AuxElement& element, MsgStream& msg );
70 virtual StatusCode setup ( TTree& /* tree */,
71 const BranchConfig& /* branchConfig */,
72 OutputBranchData& /* outputData */,
73 MsgStream& msg ) override;
74
75 std::string m_fieldName;
76 std::unique_ptr< SG::TypelessConstAccessor > m_acc;
78 std::shared_ptr<void> m_field;
79 void* m_dataPtr = nullptr;
80 };
81
83 public:
85 virtual ~ContainerFieldProcessor() = default;
88
89 virtual StatusCode setup( ROOT::RNTupleModel& model,
90 const BranchConfig& branchConfig,
91 OutputBranchData& outputData,
92 MsgStream& msg ) override;
93
94 virtual StatusCode setup ( TTree& /* tree */,
95 const BranchConfig& /* branchConfig */,
96 OutputBranchData& /* outputData */,
97 MsgStream& msg ) override;
98
99 StatusCode resize( size_t size, MsgStream& msg );
100
101 StatusCode process( const SG::AuxElement& element, size_t index, MsgStream& msg );
102
103 void* getData() const { return m_ops.getData ? m_ops.getData() : nullptr; }
104
105
106 std::string m_fieldName;
107 std::unique_ptr< SG::TypelessConstAccessor > m_acc;
109 std::shared_ptr<void> m_field;
110 void* m_dataPtr = nullptr;
111 // 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.
112 // You can pre-define how to resize aux vector in compile time for ttree, aka "IAuxTypeVector"
113 // In RNTuple, "model" will give you a shared pointer of the primitive type you requested. This request is made in run-time.
114 // That is why unlike ttree, we need an operator that takes lambda function to do the resize in the run time.
116 };
117
118
119 // ----------------------------------------------------------------------
120 // Object Processors Interface
121 // ----------------------------------------------------------------------
122
124 public:
125 ElementProcessor(const std::string& sgName);
126 virtual ~ElementProcessor() = default;
129
130 virtual StatusCode retrieveProcess( StoreType& evtStore ) override;
131
132 virtual StatusCode addBranch( ROOT::RNTupleModel& model,
133 const BranchConfig& branchConfig,
134 OutputBranchData& outputData ) override;
135
136 virtual StatusCode addBranch( TTree& tree,
137 const BranchConfig& branchConfig,
138 OutputBranchData& outputData ) override;
139
140 protected:
141 std::string m_sgName;
142 std::vector< std::unique_ptr<ElementFieldProcessor> > m_fields;
143 };
144
145
147 public:
148 ContainerProcessor(const std::string& sgName);
149 virtual ~ContainerProcessor() = default;
152
153 virtual StatusCode retrieveProcess( StoreType& evtStore ) override;
154
155 virtual StatusCode addBranch( ROOT::RNTupleModel& model,
156 const BranchConfig& branchConfig,
157 OutputBranchData& outputData ) override;
158
159 virtual StatusCode addBranch( TTree& tree,
160 const BranchConfig& branchConfig,
161 OutputBranchData& outputData ) override;
162
163 private:
164 std::string m_sgName;
165 std::vector< std::unique_ptr<ContainerFieldProcessor> > m_fields;
166 TVirtualCollectionProxy* m_collProxy = nullptr;
168 };
169
171 public:
172 ElementProcessorMet(const std::string& sgName, const std::string& termName);
173 virtual ~ElementProcessorMet() = default;
176 virtual StatusCode retrieveProcess( StoreType& evtStore ) override;
177 private:
178 std::string m_termName;
179 };
180
182 public:
183 using AsgMessagingForward::AsgMessagingForward;
184 virtual ~ProcessorList() = default;
185 ProcessorList( const ProcessorList& ) = delete;
187
188 StatusCode setupTree( const std::vector<std::string>& branches,
189 std::unordered_set<std::string> nonContainers,
190 ISystematicsSvc& sysSvc,
191 ROOT::RNTupleModel& model );
192
193 StatusCode setupBranch( const BranchConfig& branchConfig,
194 OutputBranchData& outputData,
195 ROOT::RNTupleModel& model );
196
197 StatusCode process( StoreType& evtStore );
198
199 TreeBranchHelpers::IObjectProcessor& getObjectProcessor( const BranchConfig& branchConfig, const std::string& sgName );
200 std::unordered_set<std::string> m_nonContainers;
201 std::unordered_map< std::string, std::unique_ptr<TreeBranchHelpers::IObjectProcessor> > m_processors;
202 };
203
204 } // namespace RNtupleFieldHelpers
205} // namespace CP
206
207#endif // ASGANALYSISALGORITHMS_RNTUPLEFIELDHELPERS_H
Base class for elements of a container that can have aux data.
Manage index tracking and synchronization of auxiliary data.
size_t size() const
Number of registered mappings.
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
ElementProcessorMet(const std::string &sgName, const std::string &termName)
ElementProcessorMet(const ElementProcessorMet &)=delete
ElementProcessorMet & operator=(const ElementProcessorMet &)=delete
virtual StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
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 &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
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 Event to make it look like StoreGate.
Definition SgEvent.h:44
const std::string process
TreeBranchHelpers::OutputBranchData OutputBranchData
TreeBranchHelpers::BranchConfig BranchConfig
Select isolated Photons, Electrons and Muons.
Forward declaration.
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
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