ATLAS Offline Software
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 //
24 class TTree;
25 
26 namespace MuonVal {
27 
28 class EventHashBranch;
29 
31 public:
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,
63 
65  StatusCode write();
71  bool registerBranch(std::shared_ptr<IMuonTesterBranch> branch);
72 
74  bool addBranch(std::shared_ptr<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;
114 private:
118 
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
MuonVal::MuonTesterTree::m_branches
std::vector< std::shared_ptr< IMuonTesterBranch > > m_branches
Definition: MuonTesterTree.h:145
MuonVal::MuonTesterTree::newBranch
T & newBranch(std::shared_ptr< T > br)
returns the reference of the branch
MuonVal::MuonTesterTree::initialized
bool initialized() const
Has the init method been called and the tree is connected with the output file.
Definition: MuonTesterTree.cxx:88
MuonVal::MuonTesterTree::m_filled
bool m_filled
Definition: MuonTesterTree.h:152
MuonVal::MuonTesterTree::newScalar
ScalarBranch< T > & newScalar(const std::string &name, const T def_val)
MuonVal::MuonTesterTree::m_init
bool m_init
Flag to avoid double initialization with the StoreGate.
Definition: MuonTesterTree.h:131
MuonVal::MuonTesterTree::m_written
bool m_written
Flag to indicate whether the TTree is written to the file or not.
Definition: MuonTesterTree.h:133
MuonVal::MuonTesterTree::FriendTreePtr
std::shared_ptr< MuonTesterTree > FriendTreePtr
Appends the other tester Tree as friend to this instance.
Definition: MuonTesterTree.h:109
MuonVal::MuonTesterTree::getBranch
std::shared_ptr< T > getBranch(const std::string &str) const
Retrieves the branches owned by the muon_tree.
MuonVal::MuonTesterTree::init
StatusCode init(OWNER *instance)
Initialize method.
MuonVal::MuonTesterTree::MuonTesterTree
MuonTesterTree(const std::string &tree_name, const std::string &stream)
Definition: MuonTesterTree.cxx:267
MuonVal::MuonTesterTree::newSet
SetBranch< T > & newSet(const std::string &name)
MuonVal::MuonTesterTree::~MuonTesterTree
~MuonTesterTree()
Definition: MuonTesterTree.cxx:271
MuonVal::MuonTesterTree::isActive
bool isActive(const IMuonTesterBranch *branch) const
Returns a boolean whether the branch is already part of the tree or one of the deligated friends.
Definition: MuonTesterTree.cxx:206
athena.value
value
Definition: athena.py:124
MuonVal::MuonTesterTree::registerBranch
bool registerBranch(std::shared_ptr< IMuonTesterBranch > branch)
This method adds the branch to the tree and hands over the ownership to the MuonAnalysisTree instance...
Definition: MuonTesterTree.cxx:28
MuonVal::MuonTesterTree::operator->
TTree * operator->()
Operator to the TTree object.
Definition: MuonTesterTree.cxx:23
MuonVal::VectorBranch
Definition: VectorBranch.h:14
MuonVal::MuonTesterTree::addClient
bool addClient(MuonTesterTree *client)
Adds the other TTree as a Client and declares this instance as a Common Tree.
Definition: MuonTesterTree.cxx:225
MuonVal::MuonTesterTree::m_tree
std::unique_ptr< TTree > m_tree
Definition: MuonTesterTree.h:127
MuonTesterTree.icc
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
MuonVal::MuonTesterTree::m_directory
TDirectory * m_directory
Definition: MuonTesterTree.h:151
MuonVal::MuonTesterTree::newMatrix
MatrixBranch< T > & newMatrix(const std::string &name, const T def_val)
MuonVal::MuonTesterTree::fileStream
const std::string & fileStream() const
file_stream of the analysis to which the tree belongs
Definition: MuonTesterTree.cxx:205
VectorBranch.h
rerun_display.client
client
Definition: rerun_display.py:31
SetBranch.h
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
IMuonTesterBranch.h
MuonVal::MuonTesterTree::m_branches_to_init
std::vector< IMuonTesterBranch * > m_branches_to_init
Definition: MuonTesterTree.h:143
MuonVal::MuonTesterTree::isCommonTree
bool isCommonTree() const
Returns Whether the Tree is a common tree or not.
Definition: MuonTesterTree.cxx:265
MuonVal::MuonTesterTree
Definition: MuonTesterTree.h:30
MuonVal::SetBranch
Definition: SetBranch.h:12
MuonVal::MuonTesterTree::disableBranch
void disableBranch(const std::string &br_name)
Skips the branch from being added to the tree.
Definition: MuonTesterTree.cxx:199
MuonVal::IMuonTesterBranch::DataDependency
SG::VarHandleKey * DataDependency
Definition: IMuonTesterBranch.h:39
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonVal::MuonTesterTree::m_commonClients
std::set< MuonTesterTree * > m_commonClients
List of all other MuonTesterTree instances using this instance as a common Tree If the Tree has one c...
Definition: MuonTesterTree.h:160
MuonVal::MuonTesterTree::newVector
VectorBranch< T > & newVector(const std::string &name, const T def_val)
Creates and returns branches with a default value.
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
MuonVal::MuonTesterTree::newVector
VectorBranch< T > & newVector(const std::string &name)
Creates new branches and returns their reference.
ScalarBranch.h
MuonVal
Class to store array like branches into the n-tuples.
Definition: MuonTPMetaDataAlg.cxx:25
MuonVal::MuonTesterTree::name
std::string name() const
Name of the tree.
Definition: MuonTesterTree.cxx:20
MuonVal::ScalarBranch
Definition: ScalarBranch.h:12
MuonVal::MuonTesterTree::m_dependencies
std::vector< DataDependency > m_dependencies
Definition: MuonTesterTree.h:124
MuonVal::MuonTesterTree::setPath
void setPath(const std::string &new_path)
Save the TTree in a subfolder of the TFile.
Definition: MuonTesterTree.cxx:222
MuonVal::MuonTesterTree::newScalar
ScalarBranch< T > & newScalar(const std::string &name)
SG::VarHandleKey
A property holding a SG store/key/clid from which a VarHandle is made.
Definition: StoreGate/StoreGate/VarHandleKey.h:62
MuonVal::MuonTesterTree::m_hash_br
std::shared_ptr< EventHashBranch > m_hash_br
Definition: MuonTesterTree.h:162
MuonVal::MuonTesterTree::addCommonTree
bool addCommonTree(FriendTreePtr common_tree)
Definition: MuonTesterTree.cxx:237
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
MuonVal::MuonTesterTree::m_friendLinks
std::vector< FriendTreePtr > m_friendLinks
List of all other common instances that are acting as friends.
Definition: MuonTesterTree.h:156
MuonVal::MuonTesterTree::m_initialized_br
std::set< IMuonTesterBranch * > m_initialized_br
Set of branches that were already initialized.
Definition: MuonTesterTree.h:147
MuonVal::MuonTesterTree::m_hist_svc
ServiceHandle< ITHistSvc > m_hist_svc
Definition: MuonTesterTree.h:153
MuonVal::MatrixBranch
Definition: MatrixBranch.h:12
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthMessaging.h
MuonVal::MuonTesterTree::fill
bool fill(const EventContext &ctx)
Fills the tree per call.
Definition: MuonTesterTree.cxx:89
MuonVal::MuonTesterTree::path
const std::string & path() const
sub directory in the TFile
Definition: MuonTesterTree.cxx:223
MuonVal::MuonTesterTree::write
StatusCode write()
Finally write the TTree objects.
Definition: MuonTesterTree.cxx:178
MuonVal::MuonTesterTree::newMatrix
MatrixBranch< T > & newMatrix(const std::string &name)
MuonVal::MuonTesterTree::getFriends
const std::vector< FriendTreePtr > & getFriends() const
Definition: MuonTesterTree.cxx:262
MuonVal::MuonTesterTree::m_depCounter
unsigned int m_depCounter
Definition: MuonTesterTree.h:125
str
Definition: BTagTrackIpAccessor.cxx:11
MuonVal::IMuonTesterBranch
Most basic interface class used by the MuonTester tree.
Definition: IMuonTesterBranch.h:20
MuonVal::MuonTesterTree::tree
TTree * tree()
TTree object.
Definition: MuonTesterTree.cxx:22
MatrixBranch.h
MuonVal::MuonTesterTree::m_stream
std::string m_stream
Definition: MuonTesterTree.h:128
MuonVal::MuonTesterTree::removeBranch
void removeBranch(IMuonTesterBranch *branch)
In case instances of a certain branch type are destroyed before hand.
Definition: MuonTesterTree.cxx:83
MuonVal::MuonTesterTree::m_excludedBranches
std::set< std::string > m_excludedBranches
Definition: MuonTesterTree.h:149
MuonVal::MuonTesterTree::m_path
std::string m_path
Definition: MuonTesterTree.h:129
MuonVal::MuonTesterTree::addBranch
bool addBranch(std::shared_ptr< IMuonTesterBranch > branch)
Branch is added to the tree without transferring the ownership.
Definition: MuonTesterTree.cxx:61
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355
ServiceHandle< ITHistSvc >