hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
Loading...
Searching...
No Matches
Bus Class Reference

#include <Bus.h>

Classes

class  Seat
class  Passenger

Public Member Functions

template<typename BaggageType>
const BaggageType & get (const std::string &name)
template<typename BaggageType>
void board (const std::string &name)
template<typename BaggageType>
void update (const std::string &name, const BaggageType &obj)
TBranch * attach (TTree *tree, const std::string &name, bool can_create)
bool isOnBoard (const std::string &name)
void clear ()
void clear (const std::string &name)
void everybodyOff ()
void stream (std::ostream &s) const

Private Member Functions

template<typename BaggageType>
Passenger< BaggageType > & getRef (const std::string &name)

Private Attributes

std::unordered_map< std::string, std::unique_ptr< Seat > > passengers_

Friends

std::ostream & operator<< (std::ostream &s, const framework::Bus &b)

Detailed Description

A map of bus passengers

This is the actual bus that the passengers ride on during event processing. At its core, it is simply a specialization of a map between branch names and handles to the bus passengers (Seats) with some special accessors for connecting TTrees and updating contents.

See also
Bus::Seat for how we keep a handle on the Passengers
Bus::Passenger for what actually carries the event objects

Definition at line 29 of file Bus.h.

Member Function Documentation

◆ attach()

TBranch * attach ( TTree * tree,
const std::string & name,
bool can_create )
inline

Attach the input tree to the object a passenger is carrying

Note
Does not check if passenger exists in the map of passengers. This means it would get pretty messy if you try to attach a TTree to a passenger that is the wrong type or is not already on the bus.
Does not check if branch on the tree is expecting the type that is carried by the passenger. Don't know how this will affect things, but it tends to produce a seg fault because serializing objects between different types gets very messy.
See also
Passenger::attach for how we attach a passenger
Parameters
[in]treepointer to TTree to attach to
[in]namename of passenger (and branch of tree)
[in]can_createtrue if we are allowed to create new branches on the tree
Returns
pointer to branch that we attached to (may be null)

Definition at line 107 of file Bus.h.

◆ board()

template<typename BaggageType>
void board ( const std::string & name)
inline

Board a new passenger onto the bus

Note
Does not check if we are overwriting any other passenger!

Creates a new passenger that carries an object of type BaggageType and puts this passenger into the map of passengers.

Note
If you are seeing some funky "Clear not defined" compiling error while attempting to use a newly created event bus object, you should check that the class you have written matches the requirements for any of the bus types in the documentation for Bus::Passenger.
Template Parameters

in] BaggageType type of object new passenger is carrying

Parameters
[in]nameName of new passenger (corresponds to branch name)

Definition at line 65 of file Bus.h.

◆ clear() [1/2]

void clear ( )
inline

Reset the objects carried by the passengers

See also
Passenger::clear for how we clear the individual passengers

Definition at line 126 of file Bus.h.

◆ clear() [2/2]

void clear ( const std::string & name)
inline

Reset the object carried by a single passenger

Useful when only a subset of the bus should be reset – for example resetting the output passengers at the start of an event while leaving the input passengers alone, since those are refilled from the input TTree rather than by the processor.

Passengers that are not on the bus are silently ignored.

See also
Passenger::clear for how we clear the individual passengers
Parameters
[in]namename of passenger to clear

Definition at line 143 of file Bus.h.

◆ everybodyOff()

void everybodyOff ( )
inline

Kicks all of the passengers off the bus and therefore destroys any objects they are carrying.

Note
This is where the Passengers are destructed and therefore their baggage is deleted.
See also
Bus::Passenger::~Passenger for comments about why you need to be careful.

Definition at line 158 of file Bus.h.

◆ get()

template<typename BaggageType>
const BaggageType & get ( const std::string & name)
inline

Get the baggage carried by the passenger with the passed name.

See also
getRef for getting the passenger
Exceptions
std::bad_castif BaggageType does not match type of object passenger is carrying
Template Parameters

in] BaggageType type of object carried by passenger

Parameters
[in]nameName of Passenger (corresponds to branch_name)
Returns
const reference to object carried by passenger

Definition at line 43 of file Bus.h.

◆ getRef()

template<typename BaggageType>
Passenger< BaggageType > & getRef ( const std::string & name)
inlineprivate

Get a reference to a passenger on the bus

Exceptions
std::bad_castif BaggageType does not match actual type of object the passenger is carrying.
Note
Since we are casting from a non-templated base class to a templated derived class, the exception thrown has no knowledge of why the types don't match. (i.e. There won't be an exception like 'can't convert float to int'.)
Template Parameters

in] BaggageType type of object passenger is carrying

Parameters
[in]nameName of passenger
Returns
reference to passenger

Definition at line 832 of file Bus.h.

◆ isOnBoard()

bool isOnBoard ( const std::string & name)
inline

Check if a passenger is on the bus

Parameters
[in]namename of passenger to check for
Returns
true if name is a key in the map

Definition at line 117 of file Bus.h.

◆ stream()

void stream ( std::ostream & s) const
inline

Write the bus to the input ostream.

Includes new-line characters to separate out the different objects carried on the bus.

Parameters
[in]sostream to write to

Definition at line 168 of file Bus.h.

◆ update()

template<typename BaggageType>
void update ( const std::string & name,
const BaggageType & obj )
inline

Update the object a passenger is carrying

See also
getRef for getting the passenger
Passenger::update for how we update a passenger
Exceptions
std::bad_castif BaggageType does not match type of object passenger is carrying
Template Parameters

in] BaggageType type of object carried by passenger

Parameters
[in]namename of passenger (corresponds to branch name)
[in]objupdate object that should be carried by passenger

Definition at line 83 of file Bus.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const framework::Bus & b )
friend

Allow for the bus to be streamed to an ostream

See also
stream for the implmentation
Parameters
[in]sostream to write to
[in]bBus to write out
Returns
modified ostream

Definition at line 182 of file Bus.h.

Member Data Documentation

◆ passengers_

std::unordered_map<std::string, std::unique_ptr<Seat> > passengers_
private

Map of passenger names to the seats filled by passengers

The passenger names are assumed to correspond to any branch name that the passenger's baggage might be attached to.

Definition at line 843 of file Bus.h.


The documentation for this class was generated from the following file: