LDMX Software
|
A bus passenger. More...
Classes | |
class | DeleteObjectStatus |
Empty class to access protected status bit. More... | |
struct | the_type |
A simple, empty struct to allow us to pass the type of baggage to functions as a parameter. More... | |
Public Member Functions | |
Passenger () | |
Constructor. | |
virtual | ~Passenger () |
Destructor. | |
virtual TBranch * | attach (TTree *tree, const std::string &branch_name, bool can_create) |
Attach this passenger to the input tree. | |
const BaggageType & | get () const |
Get the object this passenger is carrying. | |
void | update (const BaggageType &updated_obj) |
Update this passenger's baggage. | |
virtual void | clear () |
Reset the object we are carrying to an undefined state. | |
virtual void | stream (std::ostream &s) const |
Stream the passenger's object to the input ostream. | |
Public Member Functions inherited from framework::Bus::Seat | |
virtual | ~Seat () |
Destructor. | |
Private Member Functions | |
template<typename T > | |
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. | |
TBranch * | attachBasic (TTree *tree, const std::string &branch_name, bool can_create) |
Attach a basic type. | |
TBranch * | attach (the_type< bool > t, TTree *tree, const std::string &branch_name, bool can_create) |
Specialization for bools. | |
TBranch * | attach (the_type< short > t, TTree *tree, const std::string &branch_name, bool can_create) |
Specialization for shorts. | |
TBranch * | attach (the_type< int > t, TTree *tree, const std::string &branch_name, bool can_create) |
Specialization for ints. | |
TBranch * | attach (the_type< long > t, TTree *tree, const std::string &branch_name, bool can_create) |
Specialization for longs. | |
TBranch * | attach (the_type< float > t, TTree *tree, const std::string &branch_name, bool can_create) |
Specialization for floats. | |
TBranch * | attach (the_type< double > t, TTree *tree, const std::string &branch_name, bool can_create) |
Specialization for doubles. | |
void | clear (the_type< bool > t) |
Clear bool by setting it to false. | |
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. | |
void | clear (the_type< long > t) |
Clear long by setting it to the minimum defined by the compiler. | |
void | clear (the_type< float > t) |
Clear float by setting it to the minimum defined by the compiler. | |
void | clear (the_type< double > t) |
Clear double by setting it to the minimum defined by the compiler. | |
template<typename T > | |
void | clear (the_type< T > t) |
Clear a general class by calling its 'Clear' method. | |
template<typename Content > | |
void | clear (the_type< std::vector< Content > > t) |
Clear a vector by calling the std::vector::clear method. | |
template<typename Key , typename Val > | |
void | clear (the_type< std::map< Key, Val > > t) |
Clear a map by calling the std::map::clear method. | |
template<typename T > | |
void | post_update (the_type< T > t) |
In general, don't do anything after an object has been updated. | |
template<typename T > | |
void | stream (the_type< T > t, std::ostream &s) const |
For std::vector, use the sort method after the contents are updated. | |
template<typename Content > | |
void | stream (the_type< std::vector< Content > > t, std::ostream &s) const |
Stream a vector of objects by looping through them. | |
template<typename Key , typename Val > | |
void | stream (the_type< std::map< Key, Val > > t, std::ostream &s) const |
Stream a map of objects by looping through them. | |
Private Attributes | |
BaggageType * | baggage_ |
A pointer to the baggage we own and created. | |
Friends | |
std::ostream & | operator<< (std::ostream &s, const framework::Bus::Passenger< BaggageType > &p) |
Stream this object to the output stream. | |
A bus passenger.
We store the bus passenger's baggage as a dynamically created object. This is necessary so that we can interface with the ROOT TTree.
Here we do all the heavy lifting of carrying a certain type of object with specializations for clearing, sorting, and printing.
The method of specializing the clear, post_update, and attach methods to the different types of passenger's baggage is derived from a helpful blog post. Basically, the idea is to add a parameter input into the functions that "stores" the type that we are currently carrying. This allows the compiler to choose the best method from the overloaded functions by matching the types of parameters.
in] BaggageType the type of object that this passenger carries
|
inline |
Constructor.
Dynamically create a default constructed instance of our baggage.
Definition at line 299 of file Bus.h.
|
inlinevirtual |
Destructor.
Clean up after ourselves by deleting the object we created earlier in the constructor.
Definition at line 318 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Specialization for bools.
t | Unused, only helping compiler choose the correct method | |
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
Definition at line 544 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::attachBasic().
|
inlineprivate |
Specialization for doubles.
t | Unused, only helping compiler choose the correct method | |
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
Definition at line 624 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::attachBasic().
|
inlineprivate |
Specialization for floats.
t | Unused, only helping compiler choose the correct method | |
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
Definition at line 608 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::attachBasic().
|
inlineprivate |
Specialization for ints.
t | Unused, only helping compiler choose the correct method | |
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
Definition at line 576 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::attachBasic().
|
inlineprivate |
Specialization for longs.
t | Unused, only helping compiler choose the correct method | |
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
Definition at line 592 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::attachBasic().
|
inlineprivate |
Specialization for shorts.
t | Unused, only helping compiler choose the correct method | |
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
Definition at line 560 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::attachBasic().
|
inlineprivate |
Attach to a (potentially) new branch on the input tree.
This is the attachment mechanism used for all non-basic types. The specializations for the basic types (BSILFD - bool, short, int, long, float, double) use attachBasic which is slightly different in its branching.
With complicated objects like most of our event bus baggage, ROOT is able to deduce the type as long as we load a ROOT dictionary with all of the classes defined inside of it.
t | Unused, only helping compiler choose the correct method | |
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
If the branch already exists, we need to explicitly remind ROOT that we own the object we are going to pass and it shouldn't try to delete it. Then we set the branch object to our baggage_.
Idk why this is necessary. The docs say that you can tell ROOT you own an object by using a non-null pointer passed to SetObject (or its descendent SetAddress); however, in the implementation of TBranchElement::SetAddressImpl, the kDeleteObject status bit is merely tested and the validity of the passed reference is never checked. This means the bits value is leftover from however the branch was initialized which when reading is ROOT-owned objects.
If the branch doesn't already exist and we are allowed to make one, we make a new one passing our baggage.
Definition at line 458 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlinevirtual |
Attach this passenger to the input tree.
Now we know what type of object this passenger is carrying, so we can attach it to the tree.
If the 'can_create' parameter is true and a branch of the input name doesn't exist on the tree, we create a new branch of the input branch name. If this parameter is false, we simply return the nullptr signifying that this branch doesn't exist.
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
Implements framework::Bus::Seat.
Definition at line 343 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::attach().
Referenced by framework::Bus::Passenger< BaggageType >::attach().
|
inlineprivate |
Attach a basic type.
We assume that the current baggage is one of BSILFD bool, short, int, long, float, double
We need this attaching mechanism to be different from the higher-level objects because TTree requires different inputs and returns different outputs for the basic types.
[in] | tree | pointer to TTree to attach to |
[in] | branch_name | name of branch we should attach to |
[in] | can_create | allow us to create a branch on tree if needed |
Definition at line 513 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
Referenced by framework::Bus::Passenger< BaggageType >::attach(), framework::Bus::Passenger< BaggageType >::attach(), framework::Bus::Passenger< BaggageType >::attach(), framework::Bus::Passenger< BaggageType >::attach(), framework::Bus::Passenger< BaggageType >::attach(), and framework::Bus::Passenger< BaggageType >::attach().
|
inlinevirtual |
Reset the object we are carrying to an undefined state.
We call the overloaded, templated clear method that allows the compiler to deduce which implementation to use depending on the type of baggage we are carrying.
Implements framework::Bus::Seat.
Definition at line 377 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::clear().
Referenced by framework::Bus::Passenger< BaggageType >::clear().
|
inlineprivate |
Clear bool by setting it to false.
t | Unused, only helping compiler choose the correct method |
Definition at line 634 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Clear double by setting it to the minimum defined by the compiler.
t | Unused, only helping compiler choose the correct method |
Definition at line 672 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Clear float by setting it to the minimum defined by the compiler.
t | Unused, only helping compiler choose the correct method |
Definition at line 664 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Clear int by setting it to the minimum defined by the compiler.
t | Unused, only helping compiler choose the correct method |
Definition at line 648 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Clear long by setting it to the minimum defined by the compiler.
t | Unused, only helping compiler choose the correct method |
Definition at line 656 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Clear short by setting it to the minimum defined by the compiler.
t | Unused, only helping compiler choose the correct method |
Definition at line 640 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Clear a map by calling the std::map::clear method.
t | Unused, only helping compiler choose the correct method |
Definition at line 705 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Clear a vector by calling the std::vector::clear method.
t | Unused, only helping compiler choose the correct method |
Definition at line 696 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Clear a general class by calling its 'Clear' method.
t | Unused, only helping compiler choose the correct method |
Definition at line 687 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inline |
Get the object this passenger is carrying.
Definition at line 352 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
In general, don't do anything after an object has been updated.
t | Unused, only helping compiler choose the correct method |
Definition at line 715 of file Bus.h.
Referenced by framework::Bus::Passenger< BaggageType >::update().
|
inlinevirtual |
Stream the passenger's object to the input ostream.
We call the overloaded, templated stream method that allows the compiler to deduce which implementation to use depending on the type of baggage we are carrying.
Implements framework::Bus::Seat.
Definition at line 386 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::stream().
Referenced by framework::Bus::Passenger< BaggageType >::stream().
|
inlineprivate |
Stream a map of objects by looping through them.
t | Unused, only helping compiler choose the correct method |
s | ostream to write to |
Definition at line 777 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
Stream a vector of objects by looping through them.
t | Unused, only helping compiler choose the correct method |
s | ostream to write to |
Definition at line 757 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_.
|
inlineprivate |
For std::vector, use the sort method after the contents are updated.
t | Unused, only helping compiler choose the correct method template <typename Content> void post_update(the_type<std::vector<Content>> t) { std::sort(baggage_->begin(), baggage_->end()); } Stream a basic type that has its own definition of 'operator<<'. |
t | Unused, only helping compiler choose the correct method |
s | ostream to write to |
Definition at line 743 of file Bus.h.
|
inline |
Update this passenger's baggage.
[in] | updated_obj | BaggageType to copy into our object |
Definition at line 365 of file Bus.h.
References framework::Bus::Passenger< BaggageType >::baggage_, and framework::Bus::Passenger< BaggageType >::post_update().
|
friend |
|
private |
A pointer to the baggage we own and created.
Definition at line 790 of file Bus.h.
Referenced by framework::Bus::Passenger< BaggageType >::attach(), framework::Bus::Passenger< BaggageType >::attachBasic(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::clear(), framework::Bus::Passenger< BaggageType >::get(), framework::Bus::Passenger< BaggageType >::stream(), framework::Bus::Passenger< BaggageType >::stream(), framework::Bus::Passenger< BaggageType >::update(), and framework::Bus::Passenger< BaggageType >::~Passenger().