8#include <unordered_map>
12#include "TBranchElement.h"
42 template <
typename BaggageType>
43 const BaggageType&
get(
const std::string& name) {
64 template <
typename BaggageType>
65 void board(
const std::string& name) {
66 passengers_[name] = std::make_unique<Passenger<BaggageType>>();
82 template <
typename BaggageType>
83 void update(
const std::string& name,
const BaggageType& obj) {
107 TBranch*
attach(TTree* tree,
const std::string& name,
bool can_create) {
108 return passengers_[name]->attach(tree, name, can_create);
127 for (
auto& [n, handle] :
passengers_) handle->clear();
143 void clear(
const std::string& name) {
170 s << n <<
" : " << handle << std::endl;
223 virtual TBranch*
attach(TTree* tree,
const std::string& branch_name,
224 bool can_create) = 0;
241 virtual void stream(std::ostream& s)
const = 0;
257 std::ostream& s,
const std::unique_ptr<framework::Bus::Seat>& seat) {
304 template <
typename BaggageType>
361 virtual TBranch*
attach(TTree* tree,
const std::string& branch_name,
383 void update(
const BaggageType& updated_obj) {
404 virtual void stream(std::ostream& s)
const {
448 static int bit() {
return TBranchElement::EStatusBits::kDeleteObject; }
475 template <
typename T>
478 TBranch* branch = tree->GetBranch(branch_name.c_str());
493 if (
dynamic_cast<TBranchElement*
>(branch)) {
497 }
else if (can_create) {
506 branch = tree->Branch((branch_name +
".").c_str(),
baggage_, 100000, 3);
537 TBranch* branch = tree->GetBranch(branch_name.c_str());
542 }
else if (can_create) {
543 static const std::map<std::string, std::string> cpp_to_root_type_name =
544 {{
"b",
"O"}, {
"s",
"S"}, {
"i",
"I"},
545 {
"l",
"L"}, {
"f",
"F"}, {
"d",
"D"}};
547 std::string cpp_type =
typeid(*baggage_).name();
548 branch = tree->Branch(
550 (branch_name +
"/" + cpp_to_root_type_name.at(cpp_type)).c_str());
567 const std::string& branch_name,
bool can_create) {
583 const std::string& branch_name,
bool can_create) {
599 const std::string& branch_name,
bool can_create) {
615 const std::string& branch_name,
bool can_create) {
631 const std::string& branch_name,
bool can_create) {
647 const std::string& branch_name,
bool can_create) {
663 *
baggage_ = std::numeric_limits<BaggageType>::min();
671 *
baggage_ = std::numeric_limits<BaggageType>::min();
679 *
baggage_ = std::numeric_limits<BaggageType>::min();
687 *
baggage_ = std::numeric_limits<BaggageType>::min();
695 *
baggage_ = std::numeric_limits<BaggageType>::min();
708 template <
typename T>
717 template <
typename Content>
726 template <
typename Key,
typename Val>
736 template <
typename T>
764 template <
typename T>
778 template <
typename Content>
798 template <
typename Key,
typename Val>
831 template <
typename BaggageType>
843 std::unordered_map<std::string, std::unique_ptr<Seat>>
passengers_;
DeleteObjectStatus()=delete
DeleteObjectStatus(const DeleteObjectStatus &)=delete
void clear(the_type< short > t)
virtual void stream(std::ostream &s) const
void clear(the_type< float > t)
void clear(the_type< int > t)
void clear(the_type< std::vector< Content > > t)
TBranch * attach(the_type< int > t, TTree *tree, const std::string &branch_name, bool can_create)
void clear(the_type< bool > t)
void clear(the_type< std::map< Key, Val > > t)
void clear(the_type< long > t)
TBranch * attach(the_type< T > t, TTree *tree, const std::string &branch_name, bool can_create)
virtual TBranch * attach(TTree *tree, const std::string &branch_name, bool can_create)
void stream(the_type< std::vector< Content > > t, std::ostream &s) const
void stream(the_type< T > t, std::ostream &s) const
TBranch * attach(the_type< float > t, TTree *tree, const std::string &branch_name, bool can_create)
TBranch * attach(the_type< short > t, TTree *tree, const std::string &branch_name, bool can_create)
const BaggageType & get() const
TBranch * attachBasic(TTree *tree, const std::string &branch_name, bool can_create)
void stream(the_type< std::map< Key, Val > > t, std::ostream &s) const
friend std::ostream & operator<<(std::ostream &s, const framework::Bus::Passenger< BaggageType > &p)
void post_update(the_type< T > t)
TBranch * attach(the_type< bool > t, TTree *tree, const std::string &branch_name, bool can_create)
void clear(the_type< double > t)
void clear(the_type< T > t)
BaggageType * baggage_
A pointer to the baggage we own and created.
TBranch * attach(the_type< long > t, TTree *tree, const std::string &branch_name, bool can_create)
TBranch * attach(the_type< double > t, TTree *tree, const std::string &branch_name, bool can_create)
void update(const BaggageType &updated_obj)
virtual void stream(std::ostream &s) const =0
virtual TBranch * attach(TTree *tree, const std::string &branch_name, bool can_create)=0
friend std::ostream & operator<<(std::ostream &s, const std::unique_ptr< framework::Bus::Seat > &seat)
friend std::ostream & operator<<(std::ostream &s, const framework::Bus &b)
void board(const std::string &name)
TBranch * attach(TTree *tree, const std::string &name, bool can_create)
void stream(std::ostream &s) const
std::unordered_map< std::string, std::unique_ptr< Seat > > passengers_
void update(const std::string &name, const BaggageType &obj)
void clear(const std::string &name)
Passenger< BaggageType > & getRef(const std::string &name)
bool isOnBoard(const std::string &name)
const BaggageType & get(const std::string &name)