|
| template<typename T> |
| TBranch * | attach (the_type< T > t, TTree *tree, const std::string &branch_name, bool can_create) |
| TBranch * | attachBasic (TTree *tree, const std::string &branch_name, bool can_create) |
| TBranch * | attach (the_type< bool > 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) |
| TBranch * | attach (the_type< int > t, TTree *tree, const std::string &branch_name, bool can_create) |
| TBranch * | attach (the_type< long > t, TTree *tree, const std::string &branch_name, bool can_create) |
| TBranch * | attach (the_type< float > 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 | clear (the_type< bool > t) |
| void | clear (the_type< short > t) |
| void | clear (the_type< int > t) |
| void | clear (the_type< long > t) |
| void | clear (the_type< float > t) |
| void | clear (the_type< double > t) |
| template<typename T> |
| void | clear (the_type< T > t) |
| template<typename Content> |
| void | clear (the_type< std::vector< Content > > t) |
| template<typename Key, typename Val> |
| void | clear (the_type< std::map< Key, Val > > t) |
| template<typename T> |
| void | post_update (the_type< T > t) |
| template<typename T> |
| void | stream (the_type< T > t, std::ostream &s) const |
| template<typename Content> |
| void | stream (the_type< std::vector< Content > > t, std::ostream &s) const |
| template<typename Key, typename Val> |
| void | stream (the_type< std::map< Key, Val > > t, std::ostream &s) const |
template<typename BaggageType>
class framework::Bus::Passenger< BaggageType >
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.
- Note
- Printing specialization is possible if we include the requirement that all event objects must define the 'operator<<' method.
Core Functions
- Define the type of "baggage" that is being carried on the event bus
- "Attach" the baggage to a output or input TTree for writing or reading
- "Update" the contents of the baggage
- "Clear" the baggage to a default or empty state at the end of each event
- "Print" the baggage to a ostream (via the operator<<)
Basic Structure
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.
Possible Types
- BSILFD - bool, short, int, long, float, double
- class with Clear() method defined
- std::vector of type with operator< defined
- std::map with key type that has operator< defined
- Template Parameters
-
in] BaggageType the type of object that this passenger carries
Definition at line 305 of file Bus.h.
template<typename BaggageType>
template<typename T>
| TBranch * attach |
( |
the_type< T > | t, |
|
|
TTree * | tree, |
|
|
const std::string & | branch_name, |
|
|
bool | can_create ) |
|
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.
- See also
- TBranchElement::SetObject for attaching an object to a branch that already exists
-
TTree::Branch for creating a new branch
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.
- Parameters
-
| 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 |
- Returns
- pointer to branch that we attached to (maybe be null)
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.
The extra . character informs ROOT to fully-specify the final sub-branch names after branch splitting. This is helpful for columnar analyses like with uproot, dask, and awkward.
Definition at line 476 of file Bus.h.
template<typename BaggageType>
| virtual TBranch * attach |
( |
TTree * | tree, |
|
|
const std::string & | branch_name, |
|
|
bool | can_create ) |
|
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.
- See also
- attach(the_type<T>,TTree*,const std::string&,bool) for how we attach to higher-level classes
-
attachBasic(TTree*,const std::string&,bool) for how we attach to basic types
- Parameters
-
| [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 |
- Returns
- pointer to branch that we attached to (maybe be null)
Implements Bus::Seat.
Definition at line 361 of file Bus.h.
template<typename BaggageType>
| TBranch * attachBasic |
( |
TTree * | tree, |
|
|
const std::string & | branch_name, |
|
|
bool | can_create ) |
|
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.
- See also
- TBranch::SetAddress for attaching a basic type to a branch that already exists
-
TTree::Branch for creating a new branch
-
typeid for identifying the type of an object
- Parameters
-
| [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 |
- Returns
- pointer to branch that we attached to (maybe be null)
Definition at line 535 of file Bus.h.