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
16 Vector-like container with chunked memory allocation.
17 
18 Allocation chunk can accommodate fN atoms of byte-size fS each.
19 The chunks themselves are TArrayCs and are stored in a std::vector<TArrayC*>.
20 Holes in the structure are not supported, neither is removal of atoms.
21 The 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 {
61  ReleaseChunks();
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Empty the container and reset it with given atom and chunk sizes.
66 
67 void TEveChunkManager::Reset(Int_t atom_size, Int_t chunk_size)
68 {
69  ReleaseChunks();
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  }
92  ReleaseChunks();
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)
140  fSelectionIterator = fSelection->begin();
141  else
143 
144  if (fSelectionIterator != fSelection->end())
145  {
148  return kTRUE;
149  }
150  else
151  {
152  return kFALSE;
153  }
154  }
155 }
TEveChunkManager::fChunks
std::vector< TArrayC * > fChunks
Definition: TEveChunkManager.h:46
TEveChunkManager::fSize
Int_t fSize
Definition: TEveChunkManager.h:42
TEveChunkManager::iterator
Definition: TEveChunkManager.h:75
TEveChunkManager::~TEveChunkManager
virtual ~TEveChunkManager()
Destructor.
Definition: TEveChunkManager.cxx:59
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TEveChunkManager::iterator::fAtomIndex
Int_t fAtomIndex
Definition: TEveChunkManager.h:79
TEveChunkManager::S
Int_t S() const
Definition: TEveChunkManager.h:58
TEveChunkManager::fN
Int_t fN
Definition: TEveChunkManager.h:40
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TArrayC::fArray
Char_t * fArray
Definition: TArrayC.h:36
TEveChunkManager::Chunk
Char_t * Chunk(Int_t chk) const
Definition: TEveChunkManager.h:66
TEveChunkManager::iterator::fNextChunk
Int_t fNextChunk
Definition: TEveChunkManager.h:80
TEveChunkManager::iterator::fAtomsToGo
Int_t fAtomsToGo
Definition: TEveChunkManager.h:81
bool
TEveChunkManager.h
TEveChunkManager::NAtoms
Int_t NAtoms(Int_t chk) const
Definition: TEveChunkManager.h:67
TEveChunkManager::VecSize
Int_t VecSize() const
Definition: TEveChunkManager.h:62
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TEveChunkManager::fCapacity
Int_t fCapacity
Definition: TEveChunkManager.h:44
TEveChunkManager::ReleaseChunks
void ReleaseChunks()
Release all memory chunks.
Definition: TEveChunkManager.cxx:30
TEveChunkManager::Refit
void Refit()
Refit the container so that all current data fits into a single chunk.
Definition: TEveChunkManager.cxx:79
TEveChunkManager::fS
Int_t fS
Definition: TEveChunkManager.h:39
TArrayC
Definition: TArrayC.h:27
TEveChunkManager::Reset
void Reset(Int_t atom_size, Int_t chunk_size)
Empty the container and reset it with given atom and chunk sizes.
Definition: TEveChunkManager.cxx:67
TEveChunkManager
Definition: TEveChunkManager.h:26
TEveChunkManager::Atom
Char_t * Atom(Int_t idx) const
Definition: TEveChunkManager.h:65
TEveChunkManager::iterator::fCurrent
Char_t * fCurrent
Definition: TEveChunkManager.h:78
TEveChunkManager::iterator::fSelectionIterator
std::set< Int_t >::const_iterator fSelectionIterator
Definition: TEveChunkManager.h:84
fSize
size_t fSize
Definition: DeclareConverters.h:342
TEveChunkManager::iterator::fSelection
const std::set< Int_t > * fSelection
Definition: TEveChunkManager.h:83
TEveChunkManager::iterator::next
Bool_t next()
Go to next atom.
Definition: TEveChunkManager.cxx:112
Char_t
char Char_t
Definition: RtypesCore.h:33
TEveChunkManager::NewChunk
Char_t * NewChunk()
Allocate a new memory chunk and register it.
Definition: TEveChunkManager.cxx:101
TEveChunkManager::iterator::fPlex
TEveChunkManager * fPlex
Definition: TEveChunkManager.h:77
TEveChunkManager::fVecSize
Int_t fVecSize
Definition: TEveChunkManager.h:43
int
TEveChunkManager::TEveChunkManager
TEveChunkManager()
Default constructor.
Definition: TEveChunkManager.cxx:41