ATLAS Offline Software
Loading...
Searching...
No Matches
TreeBranchHelpers.h
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2//
3// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4//
5#ifndef ASGANALYSISALGORITHMS_TREEBRANCHHELPERS_H
6#define ASGANALYSISALGORITHMS_TREEBRANCHHELPERS_H
7// System include(s):
8#include <unordered_map>
9#include <unordered_set>
10#include <set>
11#include <optional>
12#include <string>
13#include <vector>
14#include <memory>
15
16// Framework include(s):
24
25// ROOT include(s):
26#include <ROOT/RNTupleModel.hxx>
27
28// EDM include(s):
31
32// Forward declaration(s):
33class TClass;
34class TTree;
35class TVirtualCollectionProxy;
36namespace SG {
37 class AuxVectorBase;
39}
40
41namespace CP
42{
53
55 {
57#ifdef XAOD_STANDALONE
58 using StoreType = asg::SgEvent;
59#else
61#endif
62
63
64
67 {
69 std::string branchDecl;
70
72 std::string sgName;
73
75 std::string auxName;
76
78 std::string branchName;
79
81 std::string typeName;
82
84 bool nominalOnly = false;
85
87 std::optional<int> basketSize;
88
90 std::string metTermName;
91
92
95
97 const std::type_info* auxType = nullptr;
98
100 const std::type_info* auxVecType = nullptr;
101
104
105
108
111
114
115
117 StatusCode parse (const std::string& branchDecl, MsgStream& msg);
118
120 StatusCode configureTypes (std::set<std::string>& decosWithoutType, MsgStream& msg);
121
123 StatusCode configureSystematics (ISystematicsSvc& sysSvc, MsgStream& msg);
124 };
125
126
127
130 {
132 const BranchConfig *branchConfig = nullptr;
133
135 std::size_t sysIndex = 0u;
136
138 bool isNominal = false;
139
141 std::string sgName;
142
144 std::string auxName;
145
147 std::string branchName;
148
149
151 StatusCode configureNames (const BranchConfig& branchConfig, const CP::SystematicSet& sys, ISystematicsSvc& sysSvc, MsgStream& msg);
152 };
153
154
155
158 {
159 public:
161 virtual ~IComponentProcessor() = default;
162
163 virtual StatusCode setup ( ROOT::RNTupleModel& /* model */, const BranchConfig& /* branchConfig */, OutputBranchData& /* outputData */, MsgStream& msg ) = 0;
164
165 virtual StatusCode setup ( TTree& /* tree */, const BranchConfig& /* branchConfig */, OutputBranchData& /* outputData */, MsgStream& msg ) = 0;
166 };
167
168
169
179 {
180 public:
182 virtual ~IObjectProcessor() = default;
183
190 virtual StatusCode retrieveProcess (StoreType& evtStore) = 0;
191
205
206 virtual StatusCode addBranch(TTree&, const BranchConfig&, OutputBranchData&) = 0;
207
208 virtual StatusCode addBranch(ROOT::RNTupleModel&, const BranchConfig&, OutputBranchData&) = 0;
209 };
210
227
228 public:
230 virtual ~ElementBranchProcessor() = default;
247
248
249 virtual StatusCode setup( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData, MsgStream& msg ) override;
250
251 virtual StatusCode setup( ROOT::RNTupleModel& /* model */, const BranchConfig& /* branchConfig */, OutputBranchData& /* outputData */, MsgStream& msg ) override;
264 StatusCode process( const SG::AuxElement& element,
265 MsgStream& msg );
266
267
269 std::string m_branchName;
271 std::unique_ptr< SG::TypelessConstAccessor > m_acc;
275 std::unique_ptr< SG::IAuxTypeVector > m_data;
277 void* m_dataPtr = nullptr;
278
279 }; // class ElementBranchProcessor
280
281
282
305
306 public:
308 virtual ~ContainerBranchProcessor() = default;
312 virtual StatusCode setup( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData, MsgStream& msg ) override;
314 StatusCode resize( size_t size, MsgStream& msg );
316 StatusCode process( const SG::AuxElement& element, size_t index,
317 MsgStream& msg );
318 virtual StatusCode setup( ROOT::RNTupleModel& /* model */, const BranchConfig& /* branchConfig */, OutputBranchData& /* outputData */, MsgStream& msg ) override;
319
321 std::string m_branchName;
323 std::unique_ptr< SG::TypelessConstAccessor > m_acc;
327 std::unique_ptr< SG::IAuxTypeVector > m_data;
329 void* m_dataPtr = nullptr;
330
331 }; // class ContainerBranchProcessor
332
333
334
335
343
344 public:
351 ElementProcessorRegular(const std::string& sgName);
352 virtual ~ElementProcessorRegular() = default;
355
357 virtual StatusCode retrieveProcess (StoreType& evtStore) override;
358
375 virtual StatusCode addBranch( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
376
377 virtual StatusCode addBranch( ROOT::RNTupleModel& model, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
378
379 private:
380
389 std::vector<std::unique_ptr<ElementBranchProcessor>> m_branches;
390
392 std::string m_sgName;
393
394 }; // class ElementProcessorRegular
395
396
409
410 public:
417 ContainerProcessorRegular(const std::string& sgName);
418 virtual ~ContainerProcessorRegular() = default;
421
423 virtual StatusCode retrieveProcess (StoreType& evtStore) override;
424
441 virtual StatusCode addBranch( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
442
443 virtual StatusCode addBranch( ROOT::RNTupleModel& model, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
444
445 private:
454 std::vector<std::unique_ptr<ContainerBranchProcessor>> m_branches;
456 TVirtualCollectionProxy* m_collProxy = nullptr;
459
461 std::string m_sgName;
462
463 }; // class ContainerProcessorRegular
464
465
466
474
475 public:
482 ElementProcessorMet (const std::string& sgName, const std::string& termName);
483 virtual ~ElementProcessorMet() = default;
486
488 virtual StatusCode retrieveProcess (StoreType& evtStore) override;
489
506 virtual StatusCode addBranch( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
507
508 virtual StatusCode addBranch( ROOT::RNTupleModel& model, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
509
510 private:
511
520 std::vector<std::unique_ptr<ElementBranchProcessor>> m_branches;
521
523 std::string m_sgName;
524
526 std::string m_termName;
527
528 }; // class ElementProcessorMet
529
530
532 public:
533 using AsgMessagingForward::AsgMessagingForward;
534 virtual ~ProcessorList() = default;
535 ProcessorList( const ProcessorList& ) = delete;
537
540 StatusCode setupTree(const std::vector<std::string>& branches, std::unordered_set<std::string> nonContainers, ISystematicsSvc& sysSvc, TTree& tree );
541
543 StatusCode setupBranch( const BranchConfig& branchConfig, OutputBranchData& outputData, TTree& tree );
544
545 StatusCode process (StoreType& evtStore);
546
547 IObjectProcessor& getObjectProcessor (const BranchConfig& branchConfig, const std::string& sgName);
548
550 std::unordered_set<std::string> m_nonContainers;
551
553 std::optional<int> defaultBasketSize;
554
556 std::unordered_map< std::string, std::unique_ptr<IObjectProcessor>> m_processors;
557 };
558 }
559}
560
561#endif
Base class for elements of a container that can have aux data.
Abstract interface for manipulating vectors of arbitrary types.
size_t size() const
Number of registered mappings.
Define macros for attributes used to control the static checker.
the interface for the central systematics service
Class to wrap a set of SystematicVariations.
std::string m_branchName
Name of the branch being written.
StatusCode resize(size_t size, MsgStream &msg)
Function (re)sizing the variable for a new event.
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
std::unique_ptr< SG::TypelessConstAccessor > m_acc
Object accessing the variable in question.
virtual StatusCode setup(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg) override
Function setting up the object, and the branch.
ContainerBranchProcessor(const ContainerBranchProcessor &)=delete
ContainerBranchProcessor & operator=(const ContainerBranchProcessor &)=delete
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
void * m_dataPtr
Helper variable, pointing at the object to be written.
ContainerProcessorRegular & operator=(const ContainerProcessorRegular &)=delete
TVirtualCollectionProxy * m_collProxy
Collection proxy used for iterating over the container.
std::string m_sgName
Name of the object in the event store.
int m_auxElementOffset
Offset of the element type to SG::AuxElement.
virtual StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
virtual StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData) override
Add one branch to the output tree.
std::vector< std::unique_ptr< ContainerBranchProcessor > > m_branches
List of branch processors set up for this xAOD object.
ContainerProcessorRegular(const ContainerProcessorRegular &)=delete
ContainerProcessorRegular(const std::string &sgName)
Default constructor.
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
ElementBranchProcessor & operator=(const ElementBranchProcessor &)=delete
void * m_dataPtr
Helper variable, pointing at the object to be written.
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
std::string m_branchName
Name of the branch being written.
ElementBranchProcessor(const ElementBranchProcessor &)=delete
virtual StatusCode setup(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg) override
Function setting up the object, and the branch.
std::unique_ptr< SG::TypelessConstAccessor > m_acc
Object accessing the variable in question.
std::vector< std::unique_ptr< ElementBranchProcessor > > m_branches
List of branch processors set up for this xAOD object.
std::string m_termName
Name of the MET term to retrieve.
virtual StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData) override
Add one branch to the output tree.
ElementProcessorMet(const std::string &sgName, const std::string &termName)
Default constructor.
ElementProcessorMet(const ElementProcessorMet &)=delete
virtual StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
ElementProcessorMet & operator=(const ElementProcessorMet &)=delete
std::string m_sgName
Name of the object in the event store.
ElementProcessorRegular(const ElementProcessorRegular &)=delete
virtual StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
virtual StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData) override
Add one branch to the output tree.
ElementProcessorRegular & operator=(const ElementProcessorRegular &)=delete
std::string m_sgName
Name of the object in the event store.
ElementProcessorRegular(const std::string &sgName)
Default constructor.
std::vector< std::unique_ptr< ElementBranchProcessor > > m_branches
List of branch processors set up for this xAOD object.
the interface class for branch processors
virtual StatusCode setup(ROOT::RNTupleModel &, const BranchConfig &, OutputBranchData &, MsgStream &msg)=0
virtual ~IComponentProcessor()=default
virtual destructor
virtual StatusCode setup(TTree &, const BranchConfig &, OutputBranchData &, MsgStream &msg)=0
the interface class for classes reading an object from the event store and processing it
virtual StatusCode addBranch(ROOT::RNTupleModel &, const BranchConfig &, OutputBranchData &)=0
virtual StatusCode retrieveProcess(StoreType &evtStore)=0
retrieve and process the object
virtual StatusCode addBranch(TTree &, const BranchConfig &, OutputBranchData &)=0
Add one branch to the output tree.
virtual ~IObjectProcessor()=default
virtual destructor
ProcessorList(const ProcessorList &)=delete
StatusCode setupBranch(const BranchConfig &branchConfig, OutputBranchData &outputData, TTree &tree)
Function setting up an individual branch on the first event.
std::unordered_set< std::string > m_nonContainers
the non-containers
IObjectProcessor & getObjectProcessor(const BranchConfig &branchConfig, const std::string &sgName)
StatusCode setupTree(const std::vector< std::string > &branches, std::unordered_set< std::string > nonContainers, ISystematicsSvc &sysSvc, TTree &tree)
Function setting up the internal data structures on the first event for regular branches.
std::optional< int > defaultBasketSize
the default basket size
std::unordered_map< std::string, std::unique_ptr< IObjectProcessor > > m_processors
object processors
ProcessorList & operator=(const ProcessorList &)=delete
Manage index tracking and synchronization of auxiliary data.
Interface for factory objects that create vectors.
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
a namespace for helper functions and objects for filling tree branches
StoreGateSvc StoreType
the type of the event store in the current environment
Select isolated Photons, Electrons and Muons.
Forward declaration.
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
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
the user configuration of an output branch
std::string branchDecl
the original user configuration string
std::string sgName
the SG name of the object to read from
const SG::IAuxTypeVectorFactory * auxFactory
pointer to the aux vector factory
std::string auxName
the aux data variable name to read from
const std::type_info * auxVecType
the vector type of the decoration we read
std::optional< int > basketSize
the basket size for this branch
CP::SystematicSet auxNameFilterSys
the affecting systematics for the auxName
CP::SystematicSet sgNameFilterSys
the affecting systematics for the sgName
CP::SystematicSet branchNameFilterSys
the affecting systematics for the branchName
const std::type_info * auxType
the type of the decoration we read
StatusCode configureSystematics(ISystematicsSvc &sysSvc, MsgStream &msg)
configure the systematics
SG::auxid_t nominalAuxId
the aux-id for the nominal decoration
std::string branchName
the name of the output branch
std::string metTermName
MET ONLY: the name of the MET term to write out.
bool nominalOnly
whether we only want to write out the nominal
StatusCode configureTypes(std::set< std::string > &decosWithoutType, MsgStream &msg)
configure the associated decoration types
StatusCode parse(const std::string &branchDecl, MsgStream &msg)
parse the user configuration string
std::string typeName
the name of the type (or empty to read from aux-registry)
the data for a single output branch
bool isNominal
whether this is unaffected by systematics (i.e. nominal)
const BranchConfig * branchConfig
the BranchConfig we are based on
std::size_t sysIndex
the index in the systematics list
StatusCode configureNames(const BranchConfig &branchConfig, const CP::SystematicSet &sys, ISystematicsSvc &sysSvc, MsgStream &msg)
configure names for systematics
std::string auxName
the name of the decoration in the aux-store
std::string sgName
the SG name of the object to read from
std::string branchName
the name of the output branch
MsgStream & msg
Definition testRead.cxx:32
TChain * tree