Logo ROOT   6.12/07
Reference Guide
TEveChunkManager.h
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TEveChunkManager
13 #define ROOT_TEveChunkManager
14 
15 #include "TEveUtil.h"
16 
17 #include "TObject.h"
18 #include "TArrayC.h"
19 
20 #include <vector>
21 
22 
23 /******************************************************************************/
24 // TEveChunkManager
25 /******************************************************************************/
26 
28 {
29 private:
30  TEveChunkManager(const TEveChunkManager&); // Not implemented
31  TEveChunkManager& operator=(const TEveChunkManager&); // Not implemented
32 
33 protected:
34  Int_t fS; // Size of atom
35  Int_t fN; // Number of atoms in a chunk
36 
37  Int_t fSize; // Size of container, number of atoms
38  Int_t fVecSize; // Number of allocated chunks
39  Int_t fCapacity; // Available capacity within the chunks
40 
41  std::vector<TArrayC*> fChunks; // Memory blocks
42 
43  void ReleaseChunks();
44 
45 public:
47  TEveChunkManager(Int_t atom_size, Int_t chunk_size);
48  virtual ~TEveChunkManager();
49 
50  void Reset(Int_t atom_size, Int_t chunk_size);
51  void Refit();
52 
53  Int_t S() const { return fS; }
54  Int_t N() const { return fN; }
55 
56  Int_t Size() const { return fSize; }
57  Int_t VecSize() const { return fVecSize; }
58  Int_t Capacity() const { return fCapacity; }
59 
60  Char_t* Atom(Int_t idx) const { return fChunks[idx/fN]->fArray + idx%fN*fS; }
61  Char_t* Chunk(Int_t chk) const { return fChunks[chk]->fArray; }
62  Int_t NAtoms(Int_t chk) const { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
63 
64  Char_t* NewAtom();
65  Char_t* NewChunk();
66 
67 
68  // Iterator
69 
70  struct iterator
71  {
77 
78  const std::set<Int_t> *fSelection;
79  std::set<Int_t>::const_iterator fSelectionIterator;
80 
82  fPlex(p), fCurrent(0), fAtomIndex(-1),
83  fNextChunk(0), fAtomsToGo(0), fSelection(0), fSelectionIterator() {}
85  fPlex(&p), fCurrent(0), fAtomIndex(-1),
86  fNextChunk(0), fAtomsToGo(0), fSelection(0), fSelectionIterator() {}
87  iterator(const iterator& i) :
88  fPlex(i.fPlex), fCurrent(i.fCurrent), fAtomIndex(i.fAtomIndex),
89  fNextChunk(i.fNextChunk), fAtomsToGo(i.fAtomsToGo),
90  fSelection(i.fSelection), fSelectionIterator(i.fSelectionIterator) {}
91 
93  fPlex = i.fPlex; fCurrent = i.fCurrent; fAtomIndex = i.fAtomIndex;
94  fNextChunk = i.fNextChunk; fAtomsToGo = i.fAtomsToGo;
95  fSelection = i.fSelection; fSelectionIterator = i.fSelectionIterator;
96  return *this;
97  }
98 
99  Bool_t next();
100  void reset() { fCurrent = 0; fAtomIndex = -1; fNextChunk = fAtomsToGo = 0; }
101 
102  Char_t* operator()() { return fCurrent; }
103  Char_t* operator*() { return fCurrent; }
104  Int_t index() { return fAtomIndex; }
105  };
106 
107  ClassDef(TEveChunkManager, 1); // Vector-like container with chunked memory allocation.
108 };
109 
110 
111 //______________________________________________________________________________
113 {
114  Char_t *a = (fSize >= fCapacity) ? NewChunk() : Atom(fSize);
115  ++fSize;
116  return a;
117 }
118 
119 
120 /******************************************************************************/
121 // Templated some-class TEveChunkVector
122 /******************************************************************************/
123 
124 template<class T>
126 {
127 private:
128  TEveChunkVector(const TEveChunkVector&); // Not implemented
129  TEveChunkVector& operator=(const TEveChunkVector&); // Not implemented
130 
131 public:
133  TEveChunkVector(Int_t chunk_size) : TEveChunkManager(sizeof(T), chunk_size) {}
134  virtual ~TEveChunkVector() {}
135 
136  void Reset(Int_t chunk_size) { Reset(sizeof(T), chunk_size); }
137 
138  T* At(Int_t idx) { return reinterpret_cast<T*>(Atom(idx)); }
139  T& Ref(Int_t idx) { return *At(idx); }
140 
141  ClassDef(TEveChunkVector, 1); // Templated class for specific atom classes (given as template argument).
142 };
143 
144 #endif
const std::set< Int_t > * fSelection
TEveChunkManager * fPlex
double T(double x)
Definition: ChebyshevPol.h:34
Char_t * NewChunk()
Allocate a new memory chunk and register it.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual ~TEveChunkManager()
Destructor.
TEveChunkManager()
Default constructor.
#define ClassDef(name, id)
Definition: Rtypes.h:320
void Refit()
Refit the container so that all current data fits into a single chunk.
void Reset(Int_t chunk_size)
void Reset(Int_t atom_size, Int_t chunk_size)
Empty the container and reset it with given atom and chunk sizes.
Int_t Size() const
Int_t S() const
iterator & operator=(const iterator &i)
Char_t * Atom(Int_t idx) const
Int_t Capacity() const
Char_t * Chunk(Int_t chk) const
auto * a
Definition: textangle.C:12
T * At(Int_t idx)
Vector-like container with chunked memory allocation.
std::vector< TArrayC * > fChunks
Int_t NAtoms(Int_t chk) const
TEveChunkVector(Int_t chunk_size)
iterator(TEveChunkManager *p)
iterator(const iterator &i)
virtual ~TEveChunkVector()
char Char_t
Definition: RtypesCore.h:29
TEveChunkManager & operator=(const TEveChunkManager &)
Bool_t next()
Go to next atom.
T & Ref(Int_t idx)
Int_t VecSize() const
void ReleaseChunks()
Release all memory chunks.
std::set< Int_t >::const_iterator fSelectionIterator
Int_t N() const
iterator(TEveChunkManager &p)