ATLAS Offline Software
Loading...
Searching...
No Matches
MuonTesterTree.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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
11//
12#include <set>
13#include <string>
14#include <vector>
15#include <memory>
16#include <type_traits> //for std::enable_if
17//
18//need the full class declarations, function templates cannot return incomplete types
23//
24class TTree;
25
26namespace MuonVal {
27
28class EventHashBranch;
29
31public:
32 MuonTesterTree(const std::string& tree_name, const std::string& stream);
34
36 TTree* tree();
37 const TTree* tree() const;
38
40 TTree* operator->();
41 const TTree* operator->() const;
42
44 bool initialized() const;
45
47 bool fill(const EventContext& ctx);
48
50 std::string name() const;
52 const std::string& fileStream() const;
54 const std::string& path() const;
55
57 void setPath(const std::string& new_path);
58
60 template <class OWNER,
61 typename = typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type>
62 StatusCode init(OWNER* instance);
63
65 StatusCode write();
71 bool registerBranch(std::shared_ptr<IMuonTesterBranch> branch);
72
74 bool addBranch(std::shared_ptr<IMuonTesterBranch> branch);
75 bool addBranch(IMuonTesterBranch& branch);
76 bool addBranch(IMuonTesterBranch* branch);
78 void removeBranch(IMuonTesterBranch* branch);
79 void removeBranch(IMuonTesterBranch& branch);
80
82 void disableBranch(const std::string& br_name);
83 void disableBranch(const std::vector<std::string>& br_names);
84
86 template <class T> std::shared_ptr<T> getBranch(const std::string& str) const;
87
89 template <typename T> VectorBranch<T>& newVector(const std::string& name);
90 template <typename T> ScalarBranch<T>& newScalar(const std::string& name);
91 template <typename T> MatrixBranch<T>& newMatrix(const std::string& name);
92 template <typename T> SetBranch<T>& newSet(const std::string& name);
93
95 template <typename T> VectorBranch<T>& newVector(const std::string& name, const T def_val);
96 template <typename T> ScalarBranch<T>& newScalar(const std::string& name, const T def_val);
97 template <typename T> MatrixBranch<T>& newMatrix(const std::string& name, const T def_val);
98
99
101 template <typename T> T& newBranch(std::shared_ptr<T> br);
102
104 bool isActive(const IMuonTesterBranch* branch) const;
105
107 bool isCommonTree() const;
109 using FriendTreePtr = std::shared_ptr<MuonTesterTree>;
110
111 bool addCommonTree(FriendTreePtr common_tree);
113 const std::vector<FriendTreePtr>& getFriends() const;
114private:
117 bool addClient(MuonTesterTree* client);
118
121 StatusCode init(ServiceHandle<ITHistSvc> hist_svc);
122
124 std::vector<DataDependency> m_dependencies{};
125 unsigned int m_depCounter{0};
126
127 std::unique_ptr<TTree> m_tree{nullptr};
128 std::string m_stream{};
129 std::string m_path{};
131 bool m_init{false};
133 bool m_written{false};
134
135 // Careful: m_branches_to_init must come before m_branches.
136 // When m_branches is destroyed, the branches being deleted will
137 // try to remove themselves from m_branches_to_init. If these are
138 // in the opposite order, then m_branches_to_init will already
139 // have been destroyed, and we'll be accessing freed memory.
140
141 // List of branches which shall be initialized. The list will be sorted before initialization and then cleared
142 // None of the branches is explicitly owned by the object
143 std::vector<IMuonTesterBranch*> m_branches_to_init{};
144 // List of branches which are owned by the tree. They will be deleted if the object is destroyed
145 std::vector<std::shared_ptr<IMuonTesterBranch>> m_branches{};
147 std::set<IMuonTesterBranch*> m_initialized_br{};
148
149 std::set<std::string> m_excludedBranches{};
150
151 TDirectory* m_directory{nullptr};
152 bool m_filled{false};
154
156 std::vector<FriendTreePtr> m_friendLinks{};
160 std::set<MuonTesterTree*> m_commonClients{};
161
162 std::shared_ptr<EventHashBranch> m_hash_br;
163
164};
165}
167#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.
StatusCode init(OWNER *instance)
Initialize method.
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.
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.
Class to store array like branches into the n-tuples.
Definition HitValAlg.cxx:19