Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TArrayC.h"
18
19#include <vector>
20#include <set>
21
22/******************************************************************************/
23// TEveChunkManager
24/******************************************************************************/
25
27{
28private:
31
32protected:
33 Int_t fS; // Size of atom
34 Int_t fN; // Number of atoms in a chunk
35
36 Int_t fSize; // Size of container, number of atoms
37 Int_t fVecSize; // Number of allocated chunks
38 Int_t fCapacity; // Available capacity within the chunks
39
40 std::vector<TArrayC*> fChunks; // Memory blocks
41
42 void ReleaseChunks();
43
44public:
46 TEveChunkManager(Int_t atom_size, Int_t chunk_size);
47 virtual ~TEveChunkManager();
48
49 void Reset(Int_t atom_size, Int_t chunk_size);
50 void Refit();
51
52 Int_t S() const { return fS; }
53 Int_t N() const { return fN; }
54
55 Int_t Size() const { return fSize; }
56 Int_t VecSize() const { return fVecSize; }
57 Int_t Capacity() const { return fCapacity; }
58
59 Char_t* Atom(Int_t idx) const { return fChunks[idx/fN]->fArray + idx%fN*fS; }
60 Char_t* Chunk(Int_t chk) const { return fChunks[chk]->fArray; }
61 Int_t NAtoms(Int_t chk) const { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
62
63 Char_t* NewAtom();
65
66
67 // Iterator
68
69 struct iterator
70 {
76
77 const std::set<Int_t> *fSelection;
78 std::set<Int_t>::const_iterator fSelectionIterator;
79
81 fPlex(p), fCurrent(nullptr), fAtomIndex(-1),
84 fPlex(&p), fCurrent(nullptr), fAtomIndex(-1),
86 iterator(const iterator& i) :
90
95 return *this;
96 }
97
98 Bool_t next();
99 void reset() { fCurrent = nullptr; fAtomIndex = -1; fNextChunk = fAtomsToGo = 0; }
100
102 Char_t* operator*() { return fCurrent; }
103 Int_t index() { return fAtomIndex; }
104 };
105
106 ClassDef(TEveChunkManager, 1); // Vector-like container with chunked memory allocation.
107};
108
109
110//______________________________________________________________________________
112{
113 Char_t *a = (fSize >= fCapacity) ? NewChunk() : Atom(fSize);
114 ++fSize;
115 return a;
116}
117
118
119/******************************************************************************/
120// Templated some-class TEveChunkVector
121/******************************************************************************/
122
123template<class T>
125{
126private:
127 TEveChunkVector(const TEveChunkVector&); // Not implemented
128 TEveChunkVector& operator=(const TEveChunkVector&); // Not implemented
129
130public:
132 TEveChunkVector(Int_t chunk_size) : TEveChunkManager(sizeof(T), chunk_size) {}
133 ~TEveChunkVector() override {}
134
135 void Reset(Int_t chunk_size) { Reset(sizeof(T), chunk_size); }
136
137 T* At(Int_t idx) { return reinterpret_cast<T*>(Atom(idx)); }
138 T& Ref(Int_t idx) { return *At(idx); }
139
140 ClassDefOverride(TEveChunkVector, 1); // Templated class for specific atom classes (given as template argument).
141};
142
143#endif
#define a(i)
Definition RSha256.hxx:99
char Char_t
Definition RtypesCore.h:37
#define ClassDef(name, id)
Definition Rtypes.h:342
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
winID h TVirtualViewer3D TVirtualGLPainter p
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
TEveChunkManager & operator=(const TEveChunkManager &)=delete
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.
Int_t VecSize() const
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(const TEveChunkManager &)=delete
TEveChunkManager()
Default constructor.
TEveChunkVector(const TEveChunkVector &)
~TEveChunkVector() override
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 &)
iterator(TEveChunkManager &p)
iterator & operator=(const iterator &i)
iterator(TEveChunkManager *p)
iterator(const iterator &i)
Bool_t next()
Go to next atom.
const std::set< Int_t > * fSelection
std::set< Int_t >::const_iterator fSelectionIterator
unsigned long Atom
Definition xatom.h:9