GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSTClonesArrayService.h
Go to the documentation of this file.
1 /*
2  * GGSTClonesArrayService.h
3  *
4  * Created on: 27 Jul 2013
5  * Author: Nicola Mori
6  */
7 
10 #ifndef GGSTCLONESARRAYSERVICE_H_
11 #define GGSTCLONESARRAYSERVICE_H_
12 
13 #include "TClonesArray.h"
14 
15 #include <list>
16 
31 
32 public:
37  GGSTClonesArrayService(const char *className);
38 
48 
61  TClonesArray *ProvideArray(int sizeHint = 0, bool clearElements = false);
62 
72  void TakeBackArray(TClonesArray *&array);
73 
78  void DeleteAll();
79 
80  void DumpMemInfo();
81 
82 private:
83  std::string _className;
84 
85  struct ArrayDescriptor {
86  TClonesArray *array; // Pointer to the array object.
87  int allocSize; // Allocated size, determined as TClonesArray::GetEntries at RecoverArray call.
88 
89  ArrayDescriptor() : array(NULL), allocSize(0) {}
90  ~ArrayDescriptor() {
91  if (array)
92  delete array;
93  }
94  bool operator<(const ArrayDescriptor &rhs) {
95  if (allocSize < rhs.allocSize)
96  return true;
97  else
98  return false;
99  }
100  };
101 
102  typedef std::list<ArrayDescriptor> ArrayList;
103  ArrayList _availableArrays;
104  ArrayList _assignedArrays;
105 };
106 
107 #endif /* GGSTCLONESARRAYSERVICE_H_ */
A service which manages a pool of reusable TClonesArray.
void DeleteAll()
Delete all unassigned arrays in storage.
TClonesArray * ProvideArray(int sizeHint=0, bool clearElements=false)
Method to obtain an array from the service.
void TakeBackArray(TClonesArray *&array)
Gives an array back to the service.
GGSTClonesArrayService(const char *className)
Constructor.