ATLAS Offline Software
Loading...
Searching...
No Matches
MuonTesterTree.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 MUONTESTERTREE_MUONTESTERTREE_H
5#define MUONTESTERTREE_MUONTESTERTREE_H
6
7#include <GaudiKernel/ITHistSvc.h> //service handle template argument
8#include <GaudiKernel/ServiceHandle.h>
9#include <MuonTesterTree/IMuonTesterBranch.h> //for IMuonTesterBranch::DataDependency
10#include <AthenaBaseComps/AthMessaging.h> //parent class
12//
13#include <set>
14#include <string>
15#include <vector>
16#include <memory>
17#include <concepts>
18#include <format>
19//
20//need the full class declarations, function templates cannot return incomplete types
25//
26class TTree;
27
28namespace MuonVal {
29 namespace detail {
31 template <typename HistSvcHolder_t> concept hasHistSvc = requires(const HistSvcHolder_t& holder) {
32 { holder.histSvc() }-> std::same_as<const ServiceHandle<ITHistSvc>&>;
33 };
34 }
35
36class EventHashBranch;
37
39public:
40 MuonTesterTree(const std::string& tree_name, const std::string& stream);
42
44 TTree* tree();
45 const TTree* tree() const;
46
48 TTree* operator->();
49 const TTree* operator->() const;
50
52 bool initialized() const;
53
55 bool fill(const EventContext& ctx);
56
58 std::string name() const;
60 const std::string& fileStream() const;
62 const std::string& path() const;
63
65 void setPath(const std::string& new_path);
67 void setFileStream(const std::string& new_stream);
68
69
71 template <detail::hasHistSvc OWNER>
72 StatusCode init(OWNER* instance);
73
75 StatusCode write();
81 bool registerBranch(std::shared_ptr<IMuonTesterBranch> branch);
82
84 bool addBranch(std::shared_ptr<IMuonTesterBranch> branch);
85 bool addBranch(IMuonTesterBranch& branch);
86 bool addBranch(IMuonTesterBranch* branch);
88 void removeBranch(IMuonTesterBranch* branch);
89 void removeBranch(IMuonTesterBranch& branch);
90
92 void disableBranch(const std::string& br_name);
93 void disableBranch(const std::vector<std::string>& br_names);
94
96 template <class T> std::shared_ptr<T> getBranch(const std::string& str) const;
97
99 template <typename T> VectorBranch<T>& newVector(const std::string& name);
100 template <typename T> ScalarBranch<T>& newScalar(const std::string& name);
101 template <typename T> MatrixBranch<T>& newMatrix(const std::string& name);
102 template <typename T> SetBranch<T>& newSet(const std::string& name);
103
105 template <typename T> VectorBranch<T>& newVector(const std::string& name, const T def_val);
106 template <typename T> ScalarBranch<T>& newScalar(const std::string& name, const T def_val);
107 template <typename T> MatrixBranch<T>& newMatrix(const std::string& name, const T def_val);
108
109
111 template <typename T> T& newBranch(std::shared_ptr<T> br);
112
114 bool isActive(const IMuonTesterBranch* branch) const;
115
117 bool isCommonTree() const;
119 using FriendTreePtr = std::shared_ptr<MuonTesterTree>;
120
121 bool addCommonTree(FriendTreePtr common_tree);
123 const std::vector<FriendTreePtr>& getFriends() const;
124private:
127 bool addClient(MuonTesterTree* client);
128
131 StatusCode init(const ServiceHandle<ITHistSvc> & hist_svc);
132
134 std::vector<DataDependency> m_dependencies{};
135 unsigned int m_depCounter{0};
136
137 std::unique_ptr<TTree> m_tree{nullptr};
138 std::string m_stream{};
139 std::string m_path{};
141 bool m_init{false};
143 bool m_written{false};
144
145 // Careful: m_branches_to_init must come before m_branches.
146 // When m_branches is destroyed, the branches being deleted will
147 // try to remove themselves from m_branches_to_init. If these are
148 // in the opposite order, then m_branches_to_init will already
149 // have been destroyed, and we'll be accessing freed memory.
150
151 // List of branches which shall be initialized. The list will be sorted before initialization and then cleared
152 // None of the branches is explicitly owned by the object
153 std::vector<IMuonTesterBranch*> m_branches_to_init{};
154 // List of branches which are owned by the tree. They will be deleted if the object is destroyed
155 std::vector<std::shared_ptr<IMuonTesterBranch>> m_branches{};
157 std::set<IMuonTesterBranch*> m_initialized_br{};
158
159 std::set<std::string> m_excludedBranches{};
160
161 TDirectory* m_directory{nullptr};
162 bool m_filled{false};
164
166 std::vector<FriendTreePtr> m_friendLinks{};
170 std::set<MuonTesterTree*> m_commonClients{};
171
172 std::shared_ptr<EventHashBranch> m_hash_br;
173
174};
175}
177#endif
std::map< std::string, double > instance
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Most basic interface class used by the MuonTester tree.
SG::VarHandleKey * DataDependency
std::set< std::string > m_excludedBranches
bool m_init
Flag to avoid double initialization with the StoreGate.
MatrixBranch< T > & newMatrix(const std::string &name)
T & newBranch(std::shared_ptr< T > br)
returns the reference of the branch
IMuonTesterBranch::DataDependency DataDependency
const std::vector< FriendTreePtr > & getFriends() const
std::vector< std::shared_ptr< IMuonTesterBranch > > m_branches
std::set< MuonTesterTree * > m_commonClients
List of all other MuonTesterTree instances using this instance as a common Tree If the Tree has one c...
std::vector< IMuonTesterBranch * > m_branches_to_init
bool registerBranch(std::shared_ptr< IMuonTesterBranch > branch)
This method adds the branch to the tree and hands over the ownership to the MuonAnalysisTree instance...
MuonTesterTree(const std::string &tree_name, const std::string &stream)
bool fill(const EventContext &ctx)
Fills the tree per call.
bool addBranch(std::shared_ptr< IMuonTesterBranch > branch)
Branch is added to the tree without transferring the ownership.
MatrixBranch< T > & newMatrix(const std::string &name, const T def_val)
TTree * operator->()
Operator to the TTree object.
ServiceHandle< ITHistSvc > m_hist_svc
VectorBranch< T > & newVector(const std::string &name, const T def_val)
Creates and returns branches with a default value.
void removeBranch(IMuonTesterBranch *branch)
In case instances of a certain branch type are destroyed before hand.
void disableBranch(const std::string &br_name)
Skips the branch from being added to the tree.
VectorBranch< T > & newVector(const std::string &name)
Creates new branches and returns their reference.
bool addClient(MuonTesterTree *client)
Adds the other TTree as a Client and declares this instance as a Common Tree.
bool initialized() const
Has the init method been called and the tree is connected with the output file.
bool m_written
Flag to indicate whether the TTree is written to the file or not.
std::shared_ptr< MuonTesterTree > FriendTreePtr
Appends the other tester Tree as friend to this instance.
ScalarBranch< T > & newScalar(const std::string &name, const T def_val)
std::shared_ptr< T > getBranch(const std::string &str) const
Retrieves the branches owned by the muon_tree.
void setPath(const std::string &new_path)
Save the TTree in a subfolder of the TFile.
SetBranch< T > & newSet(const std::string &name)
std::vector< FriendTreePtr > m_friendLinks
List of all other common instances that are acting as friends.
const std::string & path() const
sub directory in the TFile
bool addCommonTree(FriendTreePtr common_tree)
std::unique_ptr< TTree > m_tree
bool isActive(const IMuonTesterBranch *branch) const
Returns a boolean whether the branch is already part of the tree or one of the deligated friends.
std::vector< DataDependency > m_dependencies
std::string name() const
Name of the tree.
const std::string & fileStream() const
file_stream of the analysis to which the tree belongs
StatusCode write()
Finally write the TTree objects.
void setFileStream(const std::string &new_stream)
Set the file stream post creation.
std::shared_ptr< EventHashBranch > m_hash_br
ScalarBranch< T > & newScalar(const std::string &name)
TTree * tree()
TTree object.
bool isCommonTree() const
Returns Whether the Tree is a common tree or not.
std::set< IMuonTesterBranch * > m_initialized_br
Set of branches that were already initialized.
StatusCode init(OWNER *instance)
Initialize method.
Concept to specify whether the class returns a ServiceHandle to the THistSvc.
Class to store array like branches into the n-tuples.
Definition HitValAlg.cxx:19