GGS(GenericGEANT4Simulation)Software  2.6.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 
17 
32 
33 public:
38  GGSTClonesArrayService(const char *className);
39 
49 
59  TClonesArray* ProvideArray(int sizeHint = 0);
60 
70  void TakeBackArray(TClonesArray* &array);
71 
76  void DeleteAll();
77 
78 private:
79  const char *_className;
80 
81  struct ArrayDescriptor {
82  TClonesArray* array; // Pointer to the array object.
83  int allocSize; // Allocated size, determined as TClonesArray::GetEntries at RecoverArray call.
84 
85  ArrayDescriptor() :
86  array(NULL), allocSize(0) {
87  }
88  ~ArrayDescriptor() {
89  if (array)
90  delete array;
91  }
92  bool operator<(const ArrayDescriptor &rhs) {
93  if (allocSize < rhs.allocSize)
94  return true;
95  else
96  return false;
97  }
98  };
99 
100  typedef std::list<ArrayDescriptor> ArrayList;
101  ArrayList _availableArrays;
102  ArrayList _assignedArrays;
103 };
104 
105 #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)
Method to obtain an array from the service.
void TakeBackArray(TClonesArray *&array)
Gives an array back to the service.
GGSTClonesArrayService(const char *className)
Constructor.