Logo ROOT  
Reference Guide
REveChunkManager.hxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2018
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, 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_REveChunkManager
13 #define ROOT_REveChunkManager
14 
15 #include <ROOT/REveUtil.hxx>
16 
17 #include "TArrayC.h"
18 
19 #include <vector>
20 
21 namespace ROOT {
22 namespace Experimental {
23 
24 /******************************************************************************/
25 // REveChunkManager
26 /******************************************************************************/
27 
29 {
30 private:
33 
34 protected:
35  Int_t fS; // Size of atom
36  Int_t fN; // Number of atoms in a chunk
37 
38  Int_t fSize; // Size of container, number of atoms
39  Int_t fVecSize; // Number of allocated chunks
40  Int_t fCapacity; // Available capacity within the chunks
41 
42  std::vector<TArrayC*> fChunks; // Memory blocks
43 
44  void ReleaseChunks();
45 
46 public:
48  REveChunkManager(Int_t atom_size, Int_t chunk_size);
49  virtual ~REveChunkManager();
50 
51  void Reset(Int_t atom_size, Int_t chunk_size);
52  void Refit();
53 
54  Int_t S() const { return fS; }
55  Int_t N() const { return fN; }
56 
57  Int_t Size() const { return fSize; }
58  Int_t VecSize() const { return fVecSize; }
59  Int_t Capacity() const { return fCapacity; }
60 
61  Char_t* Atom(Int_t idx) const { return fChunks[idx/fN]->fArray + idx%fN*fS; }
62  Char_t* Chunk(Int_t chk) const { return fChunks[chk]->fArray; }
63  Int_t NAtoms(Int_t chk) const { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
64 
65  Char_t* NewAtom();
66  Char_t* NewChunk();
67 
68 
69  // Iterator
70 
71  struct iterator
72  {
74  Char_t *fCurrent{nullptr};
78 
79  const std::set<Int_t> *fSelection{nullptr};
80  std::set<Int_t>::const_iterator fSelectionIterator;
81 
83 
84 /* iterator(const iterator &i) :
85  fPlex(i.fPlex), fCurrent(i.fCurrent), fAtomIndex(i.fAtomIndex),
86  fNextChunk(i.fNextChunk), fAtomsToGo(i.fAtomsToGo),
87  fSelection(i.fSelection), fSelectionIterator(i.fSelectionIterator) {}
88 
89  iterator& operator=(const iterator& i) {
90  fPlex = i.fPlex; fCurrent = i.fCurrent; fAtomIndex = i.fAtomIndex;
91  fNextChunk = i.fNextChunk; fAtomsToGo = i.fAtomsToGo;
92  fSelection = i.fSelection; fSelectionIterator = i.fSelectionIterator;
93  return *this;
94  }
95 */
96 
97  Bool_t next();
98  void reset() { fCurrent = nullptr; fAtomIndex = -1; fNextChunk = fAtomsToGo = 0; }
99 
100  Char_t* operator()() { return fCurrent; }
101  Char_t* operator*() { return fCurrent; }
102  Int_t index() { return fAtomIndex; }
103  };
104 
105 };
106 
107 
108 //______________________________________________________________________________
110 {
111  Char_t *a = (fSize >= fCapacity) ? NewChunk() : Atom(fSize);
112  ++fSize;
113  return a;
114 }
115 
116 
117 /******************************************************************************/
118 // Templated some-class REveChunkVector
119 /******************************************************************************/
120 
121 template<class T>
123 {
124 private:
127 
128 public:
129  REveChunkVector() = default;
130  REveChunkVector(Int_t chunk_size) : REveChunkManager(sizeof(T), chunk_size) {}
131  virtual ~REveChunkVector() {}
132 
133  void Reset(Int_t chunk_size) { Reset(sizeof(T), chunk_size); }
134 
135  T *At(Int_t idx) { return reinterpret_cast<T*>(Atom(idx)); }
136  T &Ref(Int_t idx) { return *At(idx); }
137 };
138 
139 } // namespace Experimental
140 } // namespace ROOT
141 
142 #endif
ROOT::Experimental::REveChunkManager::iterator::fSelection
const std::set< Int_t > * fSelection
Definition: REveChunkManager.hxx:79
ROOT::Experimental::REveChunkVector::Ref
T & Ref(Int_t idx)
Definition: REveChunkManager.hxx:136
ROOT::Experimental::REveChunkManager::iterator::fSelectionIterator
std::set< Int_t >::const_iterator fSelectionIterator
Definition: REveChunkManager.hxx:80
ROOT::Experimental::REveChunkManager::Capacity
Int_t Capacity() const
Definition: REveChunkManager.hxx:59
ROOT::Experimental::REveChunkManager::~REveChunkManager
virtual ~REveChunkManager()
Destructor.
Definition: REveChunkManager.cxx:59
ROOT::Experimental::REveChunkManager::iterator::index
Int_t index()
Definition: REveChunkManager.hxx:102
ROOT::Experimental::REveChunkManager::fS
Int_t fS
Definition: REveChunkManager.hxx:35
ROOT::Experimental::REveChunkManager::iterator
Definition: REveChunkManager.hxx:72
ROOT::Experimental::REveChunkManager::iterator::reset
void reset()
Definition: REveChunkManager.hxx:98
ROOT::Experimental::REveChunkVector::operator=
REveChunkVector & operator=(const REveChunkVector &)=delete
ROOT::Experimental::REveChunkManager::Size
Int_t Size() const
Definition: REveChunkManager.hxx:57
ROOT::Experimental::REveChunkVector::~REveChunkVector
virtual ~REveChunkVector()
Definition: REveChunkManager.hxx:131
ROOT::Experimental::REveChunkManager::N
Int_t N() const
Definition: REveChunkManager.hxx:55
ROOT::Experimental::REveChunkManager::fChunks
std::vector< TArrayC * > fChunks
Definition: REveChunkManager.hxx:42
bool
ROOT::Experimental::REveChunkManager::operator=
REveChunkManager & operator=(const REveChunkManager &)=delete
ROOT::Experimental::REveChunkManager::fVecSize
Int_t fVecSize
Definition: REveChunkManager.hxx:39
ROOT::Experimental::REveChunkManager
Definition: REveChunkManager.hxx:29
ROOT::Experimental::REveChunkManager::S
Int_t S() const
Definition: REveChunkManager.hxx:54
ROOT::Experimental::REveChunkManager::iterator::fCurrent
Char_t * fCurrent
Definition: REveChunkManager.hxx:74
ROOT::Experimental::REveChunkManager::iterator::operator*
Char_t * operator*()
Definition: REveChunkManager.hxx:101
ROOT::Experimental::REveChunkManager::iterator::fPlex
REveChunkManager & fPlex
Definition: REveChunkManager.hxx:73
ROOT::Experimental::REveChunkVector::REveChunkVector
REveChunkVector()=default
ROOT::Experimental::REveChunkVector::Reset
void Reset(Int_t chunk_size)
Definition: REveChunkManager.hxx:133
a
auto * a
Definition: textangle.C:12
TArrayC.h
ROOT::Experimental::REveChunkManager::NewChunk
Char_t * NewChunk()
Allocate a new memory chunk and register it.
Definition: REveChunkManager.cxx:101
ROOT::Experimental::REveChunkManager::REveChunkManager
REveChunkManager(const REveChunkManager &)=delete
ROOT::Experimental::REveChunkManager::Reset
void Reset(Int_t atom_size, Int_t chunk_size)
Empty the container and reset it with given atom and chunk sizes.
Definition: REveChunkManager.cxx:67
ROOT::Experimental::REveChunkManager::Refit
void Refit()
Refit the container so that all current data fits into a single chunk.
Definition: REveChunkManager.cxx:79
ROOT::Experimental::REveChunkManager::Chunk
Char_t * Chunk(Int_t chk) const
Definition: REveChunkManager.hxx:62
ROOT::Experimental::REveChunkVector::REveChunkVector
REveChunkVector(Int_t chunk_size)
Definition: REveChunkManager.hxx:130
ROOT::Experimental::REveChunkManager::REveChunkManager
REveChunkManager()
Default constructor.
Definition: REveChunkManager.cxx:41
ROOT::Experimental::REveChunkManager::iterator::fAtomIndex
Int_t fAtomIndex
Definition: REveChunkManager.hxx:75
ROOT::Experimental::REveChunkManager::fN
Int_t fN
Definition: REveChunkManager.hxx:36
ROOT::Experimental::REveChunkManager::iterator::fAtomsToGo
Int_t fAtomsToGo
Definition: REveChunkManager.hxx:77
ROOT::Experimental::REveChunkManager::ReleaseChunks
void ReleaseChunks()
Release all memory chunks.
Definition: REveChunkManager.cxx:30
ROOT::Experimental::REveChunkManager::iterator::fNextChunk
Int_t fNextChunk
Definition: REveChunkManager.hxx:76
REveUtil.hxx
ROOT::Experimental::REveChunkManager::iterator::iterator
iterator(REveChunkManager &p)
Definition: REveChunkManager.hxx:82
ROOT::Experimental::REveChunkManager::fCapacity
Int_t fCapacity
Definition: REveChunkManager.hxx:40
ROOT::Experimental::REveChunkManager::fSize
Int_t fSize
Definition: REveChunkManager.hxx:38
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
ROOT::Experimental::REveChunkManager::VecSize
Int_t VecSize() const
Definition: REveChunkManager.hxx:58
ROOT::Experimental::REveChunkManager::iterator::operator()
Char_t * operator()()
Definition: REveChunkManager.hxx:100
ROOT::Experimental::REveChunkVector::REveChunkVector
REveChunkVector(const REveChunkVector &)=delete
ROOT::Experimental::REveChunkManager::NewAtom
Char_t * NewAtom()
Definition: REveChunkManager.hxx:109
Char_t
char Char_t
Definition: RtypesCore.h:33
ROOT::Experimental::REveChunkManager::iterator::next
Bool_t next()
Go to next atom.
Definition: REveChunkManager.cxx:112
ROOT::Experimental::REveChunkVector::At
T * At(Int_t idx)
Definition: REveChunkManager.hxx:135
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Experimental::REveChunkVector
Definition: REveChunkManager.hxx:123
ROOT::Experimental::REveChunkManager::Atom
Char_t * Atom(Int_t idx) const
Definition: REveChunkManager.hxx:61
ROOT::Experimental::REveChunkManager::NAtoms
Int_t NAtoms(Int_t chk) const
Definition: REveChunkManager.hxx:63
int