GGS(GenericGEANT4Simulation)Software  2.6.3
 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 
17 
32 
33 public:
38  GGSTClonesArrayService(const char *className);
39 
49 
62  TClonesArray* ProvideArray(int sizeHint = 0, bool clearElements = false);
63 
73  void TakeBackArray(TClonesArray* &array);
74 
79  void DeleteAll();
80 
81  void DumpMemInfo();
82 
83 private:
84  std::string _className;
85 
86  struct ArrayDescriptor {
87  TClonesArray* array; // Pointer to the array object.
88  int allocSize; // Allocated size, determined as TClonesArray::GetEntries at RecoverArray call.
89 
90  ArrayDescriptor() :
91  array(NULL), allocSize(0) {
92  }
93  ~ArrayDescriptor() {
94  if (array)
95  delete array;
96  }
97  bool operator<(const ArrayDescriptor &rhs) {
98  if (allocSize < rhs.allocSize)
99  return true;
100  else
101  return false;
102  }
103  };
104 
105  typedef std::list<ArrayDescriptor> ArrayList;
106  ArrayList _availableArrays;
107  ArrayList _assignedArrays;
108 };
109 
110 #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.