Logo ROOT  
Reference Guide
TEveChunkManager.cxx
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#include "TEveChunkManager.h"
13
14/** \class TEveChunkManager
15\ingroup TEve
16Vector-like container with chunked memory allocation.
17
18Allocation chunk can accommodate fN atoms of byte-size fS each.
19The chunks themselves are TArrayCs and are stored in a std::vector<TArrayC*>.
20Holes in the structure are not supported, neither is removal of atoms.
21The structure can be Refit() to occupy a single contiguous array.
22*/
23
26
27////////////////////////////////////////////////////////////////////////////////
28/// Release all memory chunks.
29
31{
32 for (Int_t i=0; i<fVecSize; ++i)
33 delete fChunks[i];
34 fChunks.clear();
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Default constructor.
39/// Call reset for initialization.
40
42 fS(0), fN(0),
43 fSize(0), fVecSize(0), fCapacity(0)
44{
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Constructor.
49
51 fS(atom_size), fN(chunk_size),
52 fSize(0), fVecSize(0), fCapacity(0)
53{
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Destructor.
58
60{
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Empty the container and reset it with given atom and chunk sizes.
66
67void TEveChunkManager::Reset(Int_t atom_size, Int_t chunk_size)
68{
70 fS = atom_size;
71 fN = chunk_size;
72 fSize = fVecSize = fCapacity = 0;
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Refit the container so that all current data fits into a single
77/// chunk.
78
80{
81 if (fSize == 0 || (fVecSize == 1 && fSize == fCapacity))
82 return;
83
84 TArrayC* one = new TArrayC(fS*fSize);
85 Char_t* pos = one->fArray;
86 for (Int_t i=0; i<fVecSize; ++i)
87 {
88 Int_t size = fS * NAtoms(i);
89 memcpy(pos, fChunks[i]->fArray, size);
90 pos += size;
91 }
93 fN = fCapacity = fSize;
94 fVecSize = 1;
95 fChunks.push_back(one);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Allocate a new memory chunk and register it.
100
102{
103 fChunks.push_back(new TArrayC(fS*fN));
104 ++fVecSize;
105 fCapacity += fN;
106 return fChunks.back()->fArray;
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Go to next atom.
111
113{
114 if (fSelection == 0)
115 {
116 if (fAtomsToGo <= 0)
117 {
118 if (fNextChunk < fPlex->VecSize())
119 {
122 ++fNextChunk;
123 }
124 else
125 {
126 return kFALSE;
127 }
128 }
129 else
130 {
131 fCurrent += fPlex->S();
132 }
133 ++fAtomIndex;
134 --fAtomsToGo;
135 return kTRUE;
136 }
137 else
138 {
139 if (fAtomIndex == -1)
141 else
143
144 if (fSelectionIterator != fSelection->end())
145 {
148 return kTRUE;
149 }
150 else
151 {
152 return kFALSE;
153 }
154 }
155}
size_t fSize
char Char_t
Definition: RtypesCore.h:31
const Bool_t kFALSE
Definition: RtypesCore.h:90
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
Array of chars or bytes (8 bits per element).
Definition: TArrayC.h:27
Char_t * fArray
Definition: TArrayC.h:30
Vector-like container with chunked memory allocation.
void ReleaseChunks()
Release all memory chunks.
Char_t * Chunk(Int_t chk) 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.
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.
TEveChunkManager()
Default constructor.
Int_t S() const
Bool_t next()
Go to next atom.
TEveChunkManager * fPlex
const std::set< Int_t > * fSelection
std::set< Int_t >::const_iterator fSelectionIterator