GGS(GenericGEANT4Simulation)Software
2.7.0
|
A service which manages a pool of reusable TClonesArray. More...
#include <GGSTClonesArrayService.h>
Public Member Functions | |
GGSTClonesArrayService (const char *className) | |
Constructor. More... | |
~GGSTClonesArrayService () | |
Destructor. More... | |
TClonesArray * | ProvideArray (int sizeHint=0, bool clearElements=false) |
Method to obtain an array from the service. More... | |
void | TakeBackArray (TClonesArray *&array) |
Gives an array back to the service. More... | |
void | DeleteAll () |
Delete all unassigned arrays in storage. More... | |
void | DumpMemInfo () |
A service which manages a pool of reusable TClonesArray.
This class takes care of managing a pool of TClonesArray. User routine can ask for TClonesArrays (possibly with a hint for desired size) and then release the array when finished. The released arrays can then be assigned to other routines which require them. The goal of this class is to prevent instantiating TClonesArrays when there are unused ones, and to assign available big arrays where they are most needed. The class owns the TClonesArray and will take care of deleting them. An array obtained with ProvideArray must never be explicitly deleted, it must instead be returned to the GGSTClonesArrayService by calling TakeBackArray.
Definition at line 30 of file GGSTClonesArrayService.h.
GGSTClonesArrayService::GGSTClonesArrayService | ( | const char * | className | ) |
Constructor.
className | The name of the class whose objects the TClonesArrays will contain. |
Definition at line 15 of file GGSTClonesArrayService.cpp.
GGSTClonesArrayService::~GGSTClonesArrayService | ( | ) |
Destructor.
When the service is destroyed it will destroy all the arrays it currently manages, including the assigned ones that may still be in use. It is user's responsibility to ensure that this does not happen.
TODO: Raise an exception when deleting assigned arrays?
Definition at line 19 of file GGSTClonesArrayService.cpp.
void GGSTClonesArrayService::DeleteAll | ( | ) |
Delete all unassigned arrays in storage.
This method deletes all the arrays managed by the service which are currently not assigned.
Definition at line 111 of file GGSTClonesArrayService.cpp.
TClonesArray * GGSTClonesArrayService::ProvideArray | ( | int | sizeHint = 0 , |
bool | clearElements = false |
||
) |
Method to obtain an array from the service.
This method will return an array which can be used by the caller. The array will always have GetEntries = 0, but the service will try to provide an array whose actually allocated elements are as close as possible to sizeHint. The existing array elements will be cleared if the clear flag is set to true, i.e. the TClonesArray::Clear("C") method will be called before returning the array.
sizeHint | The desired number of allocated elements. |
clearElements | if true the elements in the TClonesArray are cleared. |
Definition at line 33 of file GGSTClonesArrayService.cpp.
void GGSTClonesArrayService::TakeBackArray | ( | TClonesArray *& | array | ) |
Gives an array back to the service.
This method should be called when an array obtained via ProvideArray is no longer needed. The service will clear and store it for future usage by some other applicant. If the array has not been retrieved by a call to ProvideArray, the service will adopt it and take care of its destruction.
array | The array to be returned to the service (will be set to NULL to avoid accidental delete). |
Definition at line 77 of file GGSTClonesArrayService.cpp.