7#include <GaudiKernel/ConcurrencyFlags.h>
15 auto [
begin,
end] = std::ranges::remove_if(
vec, std::move(remove_func));
16 vec.erase(begin, end);
36 if (branch->tree() !=
tree()) {
38 if (friend_tree->registerBranch(branch)) {
45 std::vector<std::shared_ptr<IMuonTesterBranch>>
::const_iterator itr = std::find_if(
47 [&branch](
const std::shared_ptr<IMuonTesterBranch>& known) {
48 return known == branch || known->name() == branch->name();
51 if (
typeid((*itr).get()) !=
typeid(branch.get())) {
52 ATH_MSG_FATAL(
"Different branches have been added here under " << branch->name());
72 ATH_MSG_ERROR(
"Tree structure is already finalized. Cannot add " << branch->
name());
77 if (friend_tree->addBranch(branch))
return true;
108 if (!friend_tree->fill(ctx))
return false;
113 if (!branch->fill(ctx)) {
114 ATH_MSG_ERROR(
"fill() --- Failed to fill branch " << branch->name() <<
" in tree " <<
name() );
125 return StatusCode::FAILURE;
130 return StatusCode::FAILURE;
133 std::stringstream full_path{};
135 if (!hist_svc->regTree(full_path.str(),
tree()).isSuccess()) {
return StatusCode::FAILURE; }
139 return StatusCode::FAILURE;
145 if (!friend_tree->init(hist_svc).isSuccess())
return StatusCode::FAILURE;
156 ATH_MSG_VERBOSE(
"Do not count the initialize function on "<<branch->name()<<
" twice.");
159 if (!branch->init()) {
160 ATH_MSG_ERROR(
"Failed to initialize branch " << branch->name());
161 return StatusCode::FAILURE;
163 ATH_MSG_DEBUG(
" Branch " << branch->name() <<
" has been initialized");
164 std::vector<DataDependency> data_dep = branch->data_dependencies();
173 [br](
const std::shared_ptr<IMuonTesterBranch>& owned) {
174 return owned.get() == br; }) ==
m_branches.end();
177 return StatusCode::SUCCESS;
192 ATH_MSG_ERROR(__func__<<
"() --- Failed to put the tree "<<
name()<<
" out of the HistService");
193 return StatusCode::FAILURE;
196 if (!friend_tree->write().isSuccess())
return StatusCode::FAILURE;
197 if (!
tree()->AddFriend(friend_tree->tree())) {
198 ATH_MSG_ERROR(
"Failed to establish the Friendship between "<<
name()<<
" & "<<friend_tree->tree());
199 return StatusCode::FAILURE;
208 return StatusCode::SUCCESS;
224 if (friend_tree->isActive(branch))
return true;
230 return known == branch || known->name() == branch->name();
237 if (Gaudi::Concurrency::ConcurrencyFlags::numThreads() > 1) {
238 ATH_MSG_WARNING(
"Common TTree mechanism only supported in single thread environment");
249 if (Gaudi::Concurrency::ConcurrencyFlags::numThreads() > 1) {
250 ATH_MSG_WARNING(
"Common TTree mechanism only supported in single thread environment");
257 if (common_tree->fileStream() !=
fileStream()) {
258 ATH_MSG_ERROR(
"The common tree "<<common_tree->name()<<
" and "<<
name()<<
" have to be written into the same file");
271 return common_tree->addClient(
this);
280 m_tree{
std::make_unique<TTree>(tree_name.c_str(),
"MuonTesterTree")},
m_stream(stream) {}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
static const Attributes_t empty
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Most basic interface class used by the MuonTester tree.
virtual std::string name() const =0
Returns the name of the branch.
virtual TTree * tree()=0
Returns the pointer to the underlying TTree object.
std::set< std::string > m_excludedBranches
bool m_init
Flag to avoid double initialization with the StoreGate.
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.
TTree * operator->()
Operator to the TTree object.
ServiceHandle< ITHistSvc > m_hist_svc
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.
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.
void setPath(const std::string &new_path)
Save the TTree in a subfolder of the TFile.
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
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.
Class to store array like branches into the n-tuples.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.