00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TEveChunkManager
00013 #define ROOT_TEveChunkManager
00014
00015 #include "TEveUtil.h"
00016
00017 #include "TObject.h"
00018 #include "TArrayC.h"
00019
00020 #include <vector>
00021
00022
00023
00024
00025
00026
00027 class TEveChunkManager
00028 {
00029 private:
00030 TEveChunkManager(const TEveChunkManager&);
00031 TEveChunkManager& operator=(const TEveChunkManager&);
00032
00033 protected:
00034 Int_t fS;
00035 Int_t fN;
00036
00037 Int_t fSize;
00038 Int_t fVecSize;
00039 Int_t fCapacity;
00040
00041 std::vector<TArrayC*> fChunks;
00042
00043 void ReleaseChunks();
00044
00045 public:
00046 TEveChunkManager();
00047 TEveChunkManager(Int_t atom_size, Int_t chunk_size);
00048 virtual ~TEveChunkManager();
00049
00050 void Reset(Int_t atom_size, Int_t chunk_size);
00051 void Refit();
00052
00053 Int_t S() const { return fS; }
00054 Int_t N() const { return fN; }
00055
00056 Int_t Size() const { return fSize; }
00057 Int_t VecSize() const { return fVecSize; }
00058 Int_t Capacity() const { return fCapacity; }
00059
00060 Char_t* Atom(Int_t idx) const { return fChunks[idx/fN]->fArray + idx%fN*fS; }
00061 Char_t* Chunk(Int_t chk) const { return fChunks[chk]->fArray; }
00062 Int_t NAtoms(Int_t chk) const { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
00063
00064 Char_t* NewAtom();
00065 Char_t* NewChunk();
00066
00067
00068
00069
00070 struct iterator
00071 {
00072 TEveChunkManager *fPlex;
00073 Char_t *fCurrent;
00074 Int_t fAtomIndex;
00075 Int_t fNextChunk;
00076 Int_t fAtomsToGo;
00077
00078 const std::set<Int_t> *fSelection;
00079 std::set<Int_t>::const_iterator fSelectionIterator;
00080
00081 iterator(TEveChunkManager* p) :
00082 fPlex(p), fCurrent(0), fAtomIndex(-1),
00083 fNextChunk(0), fAtomsToGo(0), fSelection(0), fSelectionIterator() {}
00084 iterator(TEveChunkManager& p) :
00085 fPlex(&p), fCurrent(0), fAtomIndex(-1),
00086 fNextChunk(0), fAtomsToGo(0), fSelection(0), fSelectionIterator() {}
00087 iterator(const iterator& i) :
00088 fPlex(i.fPlex), fCurrent(i.fCurrent), fAtomIndex(i.fAtomIndex),
00089 fNextChunk(i.fNextChunk), fAtomsToGo(i.fAtomsToGo),
00090 fSelection(i.fSelection), fSelectionIterator(i.fSelectionIterator) {}
00091
00092 iterator& operator=(const iterator& i) {
00093 fPlex = i.fPlex; fCurrent = i.fCurrent; fAtomIndex = i.fAtomIndex;
00094 fNextChunk = i.fNextChunk; fAtomsToGo = i.fAtomsToGo;
00095 fSelection = i.fSelection; fSelectionIterator = i.fSelectionIterator;
00096 return *this;
00097 }
00098
00099 Bool_t next();
00100 void reset() { fCurrent = 0; fAtomIndex = -1; fNextChunk = fAtomsToGo = 0; }
00101
00102 Char_t* operator()() { return fCurrent; }
00103 Char_t* operator*() { return fCurrent; }
00104 Int_t index() { return fAtomIndex; }
00105 };
00106
00107 ClassDef(TEveChunkManager, 1);
00108 };
00109
00110
00111
00112 inline Char_t* TEveChunkManager::NewAtom()
00113 {
00114 Char_t *a = (fSize >= fCapacity) ? NewChunk() : Atom(fSize);
00115 ++fSize;
00116 return a;
00117 }
00118
00119
00120
00121
00122
00123
00124 template<class T>
00125 class TEveChunkVector : public TEveChunkManager
00126 {
00127 private:
00128 TEveChunkVector(const TEveChunkVector&);
00129 TEveChunkVector& operator=(const TEveChunkVector&);
00130
00131 public:
00132 TEveChunkVector() : TEveChunkManager() {}
00133 TEveChunkVector(Int_t chunk_size) : TEveChunkManager(sizeof(T), chunk_size) {}
00134 virtual ~TEveChunkVector() {}
00135
00136 void Reset(Int_t chunk_size) { Reset(sizeof(T), chunk_size); }
00137
00138 T* At(Int_t idx) { return reinterpret_cast<T*>(Atom(idx)); }
00139 T& Ref(Int_t idx) { return *At(idx); }
00140
00141 ClassDef(TEveChunkVector, 1);
00142 };
00143
00144 #endif