8#include <unordered_map>
12#include "TBranchElement.h"
42 template <
typename BaggageType>
43 const BaggageType&
get(
const std::string& name) {
44 return getRef<BaggageType>(name).get();
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) {
84 getRef<BaggageType>(name).update(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();
152 s << n <<
" : " << handle << std::endl;
205 virtual TBranch*
attach(TTree* tree,
const std::string& branch_name,
206 bool can_create) = 0;
223 virtual void stream(std::ostream& s)
const = 0;
239 std::ostream& s,
const std::unique_ptr<framework::Bus::Seat>& seat) {
286 template <
typename BaggageType>
343 virtual TBranch*
attach(TTree* tree,
const std::string& branch_name,
365 void update(
const BaggageType& updated_obj) {
386 virtual void stream(std::ostream& s)
const {
430 static int bit() {
return TBranchElement::EStatusBits::kDeleteObject; }
457 template <
typename T>
460 TBranch* branch = tree->GetBranch(branch_name.c_str());
475 if (
dynamic_cast<TBranchElement*
>(branch)) {
476 branch->SetBit(DeleteObjectStatus::bit(),
false);
479 }
else if (can_create) {
484 branch = tree->Branch(branch_name.c_str(),
baggage_, 100000, 3);
515 TBranch* branch = tree->GetBranch(branch_name.c_str());
520 }
else if (can_create) {
521 static const std::map<std::string, std::string> cpp_to_root_type_name =
522 {{
"b",
"O"}, {
"s",
"S"}, {
"i",
"I"},
523 {
"l",
"L"}, {
"f",
"F"}, {
"d",
"D"}};
525 std::string cpp_type =
typeid(*baggage_).name();
526 branch = tree->Branch(
528 (branch_name +
"/" + cpp_to_root_type_name.at(cpp_type)).c_str());
545 const std::string& branch_name,
bool can_create) {
561 const std::string& branch_name,
bool can_create) {
577 const std::string& branch_name,
bool can_create) {
593 const std::string& branch_name,
bool can_create) {
609 const std::string& branch_name,
bool can_create) {
625 const std::string& branch_name,
bool can_create) {
641 *
baggage_ = std::numeric_limits<BaggageType>::min();
649 *
baggage_ = std::numeric_limits<BaggageType>::min();
657 *
baggage_ = std::numeric_limits<BaggageType>::min();
665 *
baggage_ = std::numeric_limits<BaggageType>::min();
673 *
baggage_ = std::numeric_limits<BaggageType>::min();
686 template <
typename T>
695 template <
typename Content>
704 template <
typename Key,
typename Val>
714 template <
typename T>
742 template <
typename T>
756 template <
typename Content>
776 template <
typename Key,
typename Val>
809 template <
typename BaggageType>
821 std::unordered_map<std::string, std::unique_ptr<Seat>>
passengers_;
Empty class to access protected status bit.
void clear(the_type< std::map< Key, Val > > t)
Clear a map by calling the std::map::clear method.
virtual void stream(std::ostream &s) const
Stream the passenger's object to the input ostream.
const BaggageType & get() const
Get the object this passenger is carrying.
void clear(the_type< short > t)
Clear short by setting it to the minimum defined by the compiler.
void clear(the_type< int > t)
Clear int by setting it to the minimum defined by the compiler.
TBranch * attach(the_type< long > t, TTree *tree, const std::string &branch_name, bool can_create)
Specialization for longs.
void stream(the_type< T > t, std::ostream &s) const
For std::vector, use the sort method after the contents are updated.
void clear(the_type< double > t)
Clear double by setting it to the minimum defined by the compiler.
virtual TBranch * attach(TTree *tree, const std::string &branch_name, bool can_create)
Attach this passenger to the input tree.
void clear(the_type< float > t)
Clear float by setting it to the minimum defined by the compiler.
void stream(the_type< std::map< Key, Val > > t, std::ostream &s) const
Stream a map of objects by looping through them.
TBranch * attachBasic(TTree *tree, const std::string &branch_name, bool can_create)
Attach a basic type.
TBranch * attach(the_type< short > t, TTree *tree, const std::string &branch_name, bool can_create)
Specialization for shorts.
BaggageType * baggage_
A pointer to the baggage we own and created.
friend std::ostream & operator<<(std::ostream &s, const framework::Bus::Passenger< BaggageType > &p)
Stream this object to the output stream.
virtual void clear()
Reset the object we are carrying to an undefined state.
TBranch * attach(the_type< T > t, TTree *tree, const std::string &branch_name, bool can_create)
Attach to a (potentially) new branch on the input tree.
void clear(the_type< bool > t)
Clear bool by setting it to false.
TBranch * attach(the_type< double > t, TTree *tree, const std::string &branch_name, bool can_create)
Specialization for doubles.
void post_update(the_type< T > t)
In general, don't do anything after an object has been updated.
void update(const BaggageType &updated_obj)
Update this passenger's baggage.
virtual ~Passenger()
Destructor.
TBranch * attach(the_type< bool > t, TTree *tree, const std::string &branch_name, bool can_create)
Specialization for bools.
void clear(the_type< long > t)
Clear long by setting it to the minimum defined by the compiler.
void stream(the_type< std::vector< Content > > t, std::ostream &s) const
Stream a vector of objects by looping through them.
TBranch * attach(the_type< int > t, TTree *tree, const std::string &branch_name, bool can_create)
Specialization for ints.
void clear(the_type< std::vector< Content > > t)
Clear a vector by calling the std::vector::clear method.
TBranch * attach(the_type< float > t, TTree *tree, const std::string &branch_name, bool can_create)
Specialization for floats.
void clear(the_type< T > t)
Clear a general class by calling its 'Clear' method.
The handle of a bus passenger.
virtual void stream(std::ostream &s) const =0
Define how we should stream the object to the input stream.
friend std::ostream & operator<<(std::ostream &s, const std::unique_ptr< framework::Bus::Seat > &seat)
Stream this object to the output stream.
virtual void clear()=0
Clear this passenger.
virtual TBranch * attach(TTree *tree, const std::string &branch_name, bool can_create)=0
Attach this passenger to the input tree.
virtual ~Seat()
Destructor.
const BaggageType & get(const std::string &name)
Get the baggage carried by the passenger with the passed name.
void update(const std::string &name, const BaggageType &obj)
Update the object a passenger is carrying.
void clear()
Reset the objects carried by the passengers.
friend std::ostream & operator<<(std::ostream &s, const framework::Bus &b)
Allow for the bus to be streamed to an ostream.
void stream(std::ostream &s) const
Write the bus to the input ostream.
bool isOnBoard(const std::string &name)
Check if a passenger is on the bus.
TBranch * attach(TTree *tree, const std::string &name, bool can_create)
Attach the input tree to the object a passenger is carrying.
void board(const std::string &name)
Board a new passenger onto the bus.
void everybodyOff()
Kicks all of the passengers off the bus and therefore destroys any objects they are carrying.
Passenger< BaggageType > & getRef(const std::string &name)
Get a reference to a passenger on the bus.
std::unordered_map< std::string, std::unique_ptr< Seat > > passengers_
Map of passenger names to the seats filled by passengers.
All classes in the ldmx-sw project use this namespace.
A simple, empty struct to allow us to pass the type of baggage to functions as a parameter.