Logo ROOT  
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{
29private:
30 TEveChunkManager(const TEveChunkManager&); // Not implemented
31 TEveChunkManager& operator=(const TEveChunkManager&); // Not implemented
32
33protected:
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
45public:
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();
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),
85 fPlex(&p), fCurrent(0), fAtomIndex(-1),
87 iterator(const iterator& i) :
91
96 return *this;
97 }
98
99 Bool_t next();
100 void reset() { fCurrent = 0; fAtomIndex = -1; fNextChunk = fAtomsToGo = 0; }
101
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
124template<class T>
126{
127private:
128 TEveChunkVector(const TEveChunkVector&); // Not implemented
129 TEveChunkVector& operator=(const TEveChunkVector&); // Not implemented
130
131public:
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
int Int_t
Definition: RtypesCore.h:41
char Char_t
Definition: RtypesCore.h:29
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:326
Vector-like container with chunked memory allocation.
void ReleaseChunks()
Release all memory chunks.
Char_t * Chunk(Int_t chk) const
Int_t Capacity() const
Int_t NAtoms(Int_t chk) const
std::vector< TArrayC * > fChunks
virtual ~TEveChunkManager()
Destructor.
Char_t * Atom(Int_t idx) const
void Reset(Int_t atom_size, Int_t chunk_size)
Empty the container and reset it with given atom and chunk sizes.
TEveChunkManager & operator=(const TEveChunkManager &)
Int_t VecSize() const
TEveChunkManager(const TEveChunkManager &)
Char_t * NewChunk()
Allocate a new memory chunk and register it.
void Refit()
Refit the container so that all current data fits into a single chunk.
Int_t Size() const
TEveChunkManager()
Default constructor.
Int_t N() const
Int_t S() const
virtual ~TEveChunkVector()
TEveChunkVector(const TEveChunkVector &)
void Reset(Int_t chunk_size)
T & Ref(Int_t idx)
TEveChunkVector(Int_t chunk_size)
T * At(Int_t idx)
TEveChunkVector & operator=(const TEveChunkVector &)
double T(double x)
Definition: ChebyshevPol.h:34
iterator(TEveChunkManager &p)
iterator & operator=(const iterator &i)
iterator(TEveChunkManager *p)
iterator(const iterator &i)
Bool_t next()
Go to next atom.
TEveChunkManager * fPlex
const std::set< Int_t > * fSelection
std::set< Int_t >::const_iterator fSelectionIterator
auto * a
Definition: textangle.C:12