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 "TArrayC.h"
18 
19 #include <vector>
20 #include <set>
21 
22 /******************************************************************************/
23 // TEveChunkManager
24 /******************************************************************************/
25 
27 {
28 private:
31 
32 protected:
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 
44 public:
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();
64  Char_t* NewChunk();
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(0), fAtomIndex(-1),
84  fPlex(&p), fCurrent(0), fAtomIndex(-1),
86  iterator(const iterator& i) :
90 
95  return *this;
96  }
97 
98  Bool_t next();
99  void reset() { fCurrent = 0; fAtomIndex = -1; fNextChunk = fAtomsToGo = 0; }
100 
101  Char_t* operator()() { return fCurrent; }
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 
123 template<class T>
125 {
126 private:
127  TEveChunkVector(const TEveChunkVector&); // Not implemented
128  TEveChunkVector& operator=(const TEveChunkVector&); // Not implemented
129 
130 public:
132  TEveChunkVector(Int_t chunk_size) : TEveChunkManager(sizeof(T), chunk_size) {}
133  virtual ~TEveChunkVector() {}
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  ClassDef(TEveChunkVector, 1); // Templated class for specific atom classes (given as template argument).
141 };
142 
143 #endif
TEveChunkManager::fChunks
std::vector< TArrayC * > fChunks
Definition: TEveChunkManager.h:40
TEveChunkManager::fSize
Int_t fSize
Definition: TEveChunkManager.h:36
TEveChunkManager::iterator
Definition: TEveChunkManager.h:70
TEveChunkVector
Definition: TEveChunkManager.h:125
TEveChunkManager::~TEveChunkManager
virtual ~TEveChunkManager()
Destructor.
Definition: TEveChunkManager.cxx:59
TEveChunkManager::iterator::fAtomIndex
Int_t fAtomIndex
Definition: TEveChunkManager.h:73
TEveChunkVector::~TEveChunkVector
virtual ~TEveChunkVector()
Definition: TEveChunkManager.h:133
TEveChunkManager::S
Int_t S() const
Definition: TEveChunkManager.h:52
TEveChunkVector::TEveChunkVector
TEveChunkVector()
Definition: TEveChunkManager.h:131
TEveChunkManager::fN
Int_t fN
Definition: TEveChunkManager.h:34
TEveChunkManager::iterator::iterator
iterator(TEveChunkManager &p)
Definition: TEveChunkManager.h:83
TEveChunkManager::Size
Int_t Size() const
Definition: TEveChunkManager.h:55
TEveChunkVector::operator=
TEveChunkVector & operator=(const TEveChunkVector &)
TEveChunkVector::TEveChunkVector
TEveChunkVector(Int_t chunk_size)
Definition: TEveChunkManager.h:132
TEveChunkManager::Chunk
Char_t * Chunk(Int_t chk) const
Definition: TEveChunkManager.h:60
TEveChunkManager::iterator::reset
void reset()
Definition: TEveChunkManager.h:99
TEveChunkManager::iterator::fNextChunk
Int_t fNextChunk
Definition: TEveChunkManager.h:74
TEveChunkManager::iterator::operator=
iterator & operator=(const iterator &i)
Definition: TEveChunkManager.h:91
TEveChunkManager::iterator::index
Int_t index()
Definition: TEveChunkManager.h:103
TEveChunkManager::iterator::operator()
Char_t * operator()()
Definition: TEveChunkManager.h:101
TEveChunkManager::iterator::fAtomsToGo
Int_t fAtomsToGo
Definition: TEveChunkManager.h:75
bool
TEveChunkManager::NewAtom
Char_t * NewAtom()
Definition: TEveChunkManager.h:111
TEveChunkManager::NAtoms
Int_t NAtoms(Int_t chk) const
Definition: TEveChunkManager.h:61
TEveUtil.h
TEveChunkManager::operator=
TEveChunkManager & operator=(const TEveChunkManager &)=delete
TEveChunkManager::VecSize
Int_t VecSize() const
Definition: TEveChunkManager.h:56
TEveChunkVector::TEveChunkVector
TEveChunkVector(const TEveChunkVector &)
a
auto * a
Definition: textangle.C:12
TArrayC.h
TEveChunkManager::fCapacity
Int_t fCapacity
Definition: TEveChunkManager.h:38
TEveChunkManager::ReleaseChunks
void ReleaseChunks()
Release all memory chunks.
Definition: TEveChunkManager.cxx:30
TEveChunkManager::TEveChunkManager
TEveChunkManager(const TEveChunkManager &)=delete
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:33
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::iterator::iterator
iterator(const iterator &i)
Definition: TEveChunkManager.h:86
TEveChunkVector::At
T * At(Int_t idx)
Definition: TEveChunkManager.h:137
TEveChunkManager::N
Int_t N() const
Definition: TEveChunkManager.h:53
TEveChunkManager
Vector-like container with chunked memory allocation.
Definition: TEveChunkManager.h:27
TEveChunkManager::Atom
Char_t * Atom(Int_t idx) const
Definition: TEveChunkManager.h:59
TEveChunkManager::iterator::fCurrent
Char_t * fCurrent
Definition: TEveChunkManager.h:72
TEveChunkManager::iterator::operator*
Char_t * operator*()
Definition: TEveChunkManager.h:102
TEveChunkManager::Capacity
Int_t Capacity() const
Definition: TEveChunkManager.h:57
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TEveChunkManager::iterator::fSelectionIterator
std::set< Int_t >::const_iterator fSelectionIterator
Definition: TEveChunkManager.h:78
TEveChunkVector::Ref
T & Ref(Int_t idx)
Definition: TEveChunkManager.h:138
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
TEveChunkManager::iterator::fSelection
const std::set< Int_t > * fSelection
Definition: TEveChunkManager.h:77
TEveChunkManager::iterator::next
Bool_t next()
Go to next atom.
Definition: TEveChunkManager.cxx:112
TEveChunkManager::iterator::iterator
iterator(TEveChunkManager *p)
Definition: TEveChunkManager.h:80
TEveChunkVector::Reset
void Reset(Int_t chunk_size)
Definition: TEveChunkManager.h:135
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:71
TEveChunkManager::fVecSize
Int_t fVecSize
Definition: TEveChunkManager.h:37
int
TEveChunkManager::TEveChunkManager
TEveChunkManager()
Default constructor.
Definition: TEveChunkManager.cxx:41