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-2024 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 <string>
10#include <vector>
11#include <memory>
12#include <list>
13
14// Framework include(s):
22
23// EDM include(s):
26
27// Forward declaration(s):
28class TClass;
29class TTree;
30class TVirtualCollectionProxy;
31namespace SG {
32 class AuxVectorBase;
34}
35
36namespace CP
37{
48
50 {
52#ifdef XAOD_STANDALONE
54#else
56#endif
57
58
59
62 {
64 std::string branchDecl;
65
67 std::string sgName;
68
70 std::string auxName;
71
73 std::string branchName;
74
76 std::string typeName;
77
79 bool nominalOnly = false;
80
82 std::optional<int> basketSize;
83
85 std::string metTermName;
86
87
90
92 const std::type_info* auxType = nullptr;
93
95 const std::type_info* auxVecType = nullptr;
96
99
100
103
106
109
110
112 StatusCode parse (const std::string& branchDecl, MsgStream& msg);
113
115 StatusCode configureTypes (std::set<std::string>& decosWithoutType, MsgStream& msg);
116
118 StatusCode configureSystematics (ISystematicsSvc& sysSvc, MsgStream& msg);
119 };
120
121
122
125 {
127 const BranchConfig *branchConfig = nullptr;
128
130 std::size_t sysIndex = 0u;
131
133 bool isNominal = false;
134
136 std::string sgName;
137
139 std::string auxName;
140
142 std::string branchName;
143
144
146 StatusCode configureNames (const BranchConfig& branchConfig, const CP::SystematicSet& sys, ISystematicsSvc& sysSvc, MsgStream& msg);
147 };
148
149
150
153 {
154 public:
156 virtual ~IBranchProcessor() = default;
157 };
158
159
160
170 {
171 public:
173 virtual ~IObjectProcessor() = default;
174
181 virtual StatusCode retrieveProcess (StoreType& evtStore) = 0;
182
196 virtual StatusCode addBranch( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData ) = 0;
197 };
198
199
200
201
202
219
220 public:
235 StatusCode setup( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData, MsgStream& msg );
236
249 StatusCode process( const SG::AuxElement& element,
250 MsgStream& msg );
251
253 std::string m_branchName;
255 std::unique_ptr< SG::TypelessConstAccessor > m_acc;
259 std::unique_ptr< SG::IAuxTypeVector > m_data;
261 void* m_dataPtr = nullptr;
262
263 }; // class ElementBranchProcessor
264
265
266
289
290 public:
292 StatusCode setup( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData, MsgStream& msg );
294 StatusCode resize( size_t size, MsgStream& msg );
296 StatusCode process( const SG::AuxElement& element, size_t index,
297 MsgStream& msg );
298
300 std::string m_branchName;
302 std::unique_ptr< SG::TypelessConstAccessor > m_acc;
306 std::unique_ptr< SG::IAuxTypeVector > m_data;
308 void* m_dataPtr = nullptr;
309
310 }; // class ContainerBranchProcessor
311
312
313
314
322
323 public:
330 ElementProcessorRegular(const std::string& sgName);
331
333 StatusCode retrieveProcess (StoreType& evtStore) override;
334
351 StatusCode addBranch( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
352
353 private:
354
364 std::vector<std::unique_ptr<ElementBranchProcessor>> m_branches;
365
367 std::string m_sgName;
368
369 }; // class ElementProcessorRegular
370
371
384
385 public:
392 ContainerProcessorRegular(const std::string& sgName);
393
395 StatusCode retrieveProcess (StoreType& evtStore) override;
396
413 StatusCode addBranch( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
414
415 private:
425 std::vector<std::unique_ptr<ContainerBranchProcessor>> m_branches;
427 TVirtualCollectionProxy* m_collProxy = nullptr;
430
432 std::string m_sgName;
433
434 }; // class ContainerProcessorRegular
435
436
437
445
446 public:
453 ElementProcessorMet (const std::string& sgName, const std::string& termName);
454
456 StatusCode retrieveProcess (StoreType& evtStore) override;
457
474 StatusCode addBranch( TTree& tree, const BranchConfig& branchConfig, OutputBranchData& outputData ) override;
475
476 private:
477
487 std::vector<std::unique_ptr<ElementBranchProcessor>> m_branches;
488
490 std::string m_sgName;
491
493 std::string m_termName;
494
495 }; // class ElementProcessorMet
496
497
498
500 public:
501 using AsgMessagingForward::AsgMessagingForward;
502
505 StatusCode setupTree(const std::vector<std::string>& branches, std::unordered_set<std::string> nonContainers, ISystematicsSvc& sysSvc, TTree& tree );
506
508 StatusCode setupBranch( const BranchConfig& branchConfig, OutputBranchData& outputData, TTree& tree );
509
510 StatusCode process (StoreType& evtStore);
511
512 IObjectProcessor& getObjectProcessor (const BranchConfig& branchConfig, const std::string& sgName);
513
515 std::unordered_set<std::string> m_nonContainers;
516
518 std::optional<int> defaultBasketSize;
519
521 std::unordered_map< std::string, std::unique_ptr<IObjectProcessor>> m_processors;
522 };
523 }
524}
525
526#endif
Base class for elements of a container that can have aux data.
Abstract interface for manipulating vectors of arbitrary types.
Define macros for attributes used to control the static checker.
the interface for the central systematics service
Class to wrap a set of SystematicVariations.
Class writing one variable from an xAOD object into a branch.
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.
StatusCode setup(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg)
Function setting up the object, and the branch.
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.
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.
StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
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 std::string &sgName)
Default constructor.
Class writing one variable from an xAOD object into a branch.
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
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.
StatusCode setup(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg)
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.
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.
StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
std::string m_sgName
Name of the object in the event store.
StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData) override
Add one branch to the output tree.
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 ~IBranchProcessor()=default
virtual destructor
the interface class for classes reading an object from the event store and processing it
virtual StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData)=0
Add one branch to the output tree.
virtual StatusCode retrieveProcess(StoreType &evtStore)=0
retrieve and process the object
virtual ~IObjectProcessor()=default
virtual destructor
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
Base class for elements of a container that can have aux data.
Definition AuxElement.h:484
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 TEvent to make it look like StoreGate.
Definition SgTEvent.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
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