File indexing completed on 2025-01-18 10:10:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_REveChunkManager
0013 #define ROOT_REveChunkManager
0014
0015 #include <ROOT/REveUtil.hxx>
0016
0017 #include "TArrayC.h"
0018
0019 #include <vector>
0020
0021 namespace ROOT {
0022 namespace Experimental {
0023
0024
0025
0026
0027
0028 class REveChunkManager
0029 {
0030 private:
0031 REveChunkManager(const REveChunkManager&) = delete;
0032 REveChunkManager& operator=(const REveChunkManager&) = delete;
0033
0034 protected:
0035 Int_t fS;
0036 Int_t fN;
0037
0038 Int_t fSize;
0039 Int_t fVecSize;
0040 Int_t fCapacity;
0041
0042 std::vector<TArrayC*> fChunks;
0043
0044 void ReleaseChunks();
0045
0046 public:
0047 REveChunkManager();
0048 REveChunkManager(Int_t atom_size, Int_t chunk_size);
0049 virtual ~REveChunkManager();
0050
0051 void Reset(Int_t atom_size, Int_t chunk_size);
0052 void Refit();
0053
0054 Int_t S() const { return fS; }
0055 Int_t N() const { return fN; }
0056
0057 Int_t Size() const { return fSize; }
0058 Int_t VecSize() const { return fVecSize; }
0059 Int_t Capacity() const { return fCapacity; }
0060
0061 Char_t* Atom(Int_t idx) const { return fChunks[idx/fN]->fArray + idx%fN*fS; }
0062 Char_t* Chunk(Int_t chk) const { return fChunks[chk]->fArray; }
0063 Int_t NAtoms(Int_t chk) const { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
0064
0065 Char_t* NewAtom();
0066 Char_t* NewChunk();
0067
0068
0069
0070
0071 struct iterator
0072 {
0073 REveChunkManager &fPlex;
0074 Char_t *fCurrent{nullptr};
0075 Int_t fAtomIndex{-1};
0076 Int_t fNextChunk{0};
0077 Int_t fAtomsToGo{0};
0078
0079 const std::set<Int_t> *fSelection{nullptr};
0080 std::set<Int_t>::const_iterator fSelectionIterator;
0081
0082 iterator(REveChunkManager &p) : fPlex(p) {}
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 Bool_t next();
0098 void reset() { fCurrent = nullptr; fAtomIndex = -1; fNextChunk = fAtomsToGo = 0; }
0099
0100 Char_t* operator()() { return fCurrent; }
0101 Char_t* operator*() { return fCurrent; }
0102 Int_t index() { return fAtomIndex; }
0103 };
0104
0105 };
0106
0107
0108
0109 inline Char_t* REveChunkManager::NewAtom()
0110 {
0111 Char_t *a = (fSize >= fCapacity) ? NewChunk() : Atom(fSize);
0112 ++fSize;
0113 return a;
0114 }
0115
0116
0117
0118
0119
0120
0121 template<class T>
0122 class REveChunkVector : public REveChunkManager
0123 {
0124 private:
0125 REveChunkVector(const REveChunkVector&) = delete;
0126 REveChunkVector& operator=(const REveChunkVector&) = delete;
0127
0128 public:
0129 REveChunkVector() = default;
0130 REveChunkVector(Int_t chunk_size) : REveChunkManager(sizeof(T), chunk_size) {}
0131 ~REveChunkVector() override {}
0132
0133 void Reset(Int_t chunk_size) { Reset(sizeof(T), chunk_size); }
0134
0135 T *At(Int_t idx) { return reinterpret_cast<T*>(Atom(idx)); }
0136 T &Ref(Int_t idx) { return *At(idx); }
0137 };
0138
0139 }
0140 }
0141
0142 #endif