Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TEveChunkManager.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/eve:$Id$
0002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TEveChunkManager
0013 #define ROOT_TEveChunkManager
0014 
0015 #include "TEveUtil.h"
0016 
0017 #include "TArrayC.h"
0018 
0019 #include <vector>
0020 #include <set>
0021 
0022 /******************************************************************************/
0023 // TEveChunkManager
0024 /******************************************************************************/
0025 
0026 class TEveChunkManager
0027 {
0028 private:
0029    TEveChunkManager(const TEveChunkManager&) = delete;
0030    TEveChunkManager& operator=(const TEveChunkManager&) = delete;
0031 
0032 protected:
0033    Int_t fS;        // Size of atom
0034    Int_t fN;        // Number of atoms in a chunk
0035 
0036    Int_t fSize;     // Size of container, number of atoms
0037    Int_t fVecSize;  // Number of allocated chunks
0038    Int_t fCapacity; // Available capacity within the chunks
0039 
0040    std::vector<TArrayC*> fChunks; // Memory blocks
0041 
0042    void ReleaseChunks();
0043 
0044 public:
0045    TEveChunkManager();
0046    TEveChunkManager(Int_t atom_size, Int_t chunk_size);
0047    virtual ~TEveChunkManager();
0048 
0049    void Reset(Int_t atom_size, Int_t chunk_size);
0050    void Refit();
0051 
0052    Int_t    S() const { return fS; }
0053    Int_t    N() const { return fN; }
0054 
0055    Int_t    Size()     const { return fSize; }
0056    Int_t    VecSize()  const { return fVecSize; }
0057    Int_t    Capacity() const { return fCapacity; }
0058 
0059    Char_t* Atom(Int_t idx)   const { return fChunks[idx/fN]->fArray + idx%fN*fS; }
0060    Char_t* Chunk(Int_t chk)  const { return fChunks[chk]->fArray; }
0061    Int_t   NAtoms(Int_t chk) const { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
0062 
0063    Char_t* NewAtom();
0064    Char_t* NewChunk();
0065 
0066 
0067    // Iterator
0068 
0069    struct iterator
0070    {
0071       TEveChunkManager *fPlex;
0072       Char_t           *fCurrent;
0073       Int_t             fAtomIndex;
0074       Int_t             fNextChunk;
0075       Int_t             fAtomsToGo;
0076 
0077       const std::set<Int_t>           *fSelection;
0078       std::set<Int_t>::const_iterator  fSelectionIterator;
0079 
0080       iterator(TEveChunkManager* p) :
0081          fPlex(p), fCurrent(nullptr), fAtomIndex(-1),
0082          fNextChunk(0), fAtomsToGo(0), fSelection(nullptr), fSelectionIterator() {}
0083       iterator(TEveChunkManager& p) :
0084          fPlex(&p), fCurrent(nullptr), fAtomIndex(-1),
0085          fNextChunk(0), fAtomsToGo(0), fSelection(nullptr), fSelectionIterator() {}
0086       iterator(const iterator& i) :
0087          fPlex(i.fPlex), fCurrent(i.fCurrent), fAtomIndex(i.fAtomIndex),
0088          fNextChunk(i.fNextChunk), fAtomsToGo(i.fAtomsToGo),
0089          fSelection(i.fSelection), fSelectionIterator(i.fSelectionIterator) {}
0090 
0091       iterator& operator=(const iterator& i) {
0092          fPlex = i.fPlex; fCurrent = i.fCurrent; fAtomIndex = i.fAtomIndex;
0093          fNextChunk = i.fNextChunk; fAtomsToGo = i.fAtomsToGo;
0094          fSelection = i.fSelection; fSelectionIterator = i.fSelectionIterator;
0095          return *this;
0096       }
0097 
0098       Bool_t  next();
0099       void    reset() { fCurrent = nullptr; fAtomIndex = -1; fNextChunk = fAtomsToGo = 0; }
0100 
0101       Char_t* operator()() { return fCurrent; }
0102       Char_t* operator*()  { return fCurrent; }
0103       Int_t   index()      { return fAtomIndex; }
0104    };
0105 
0106    ClassDef(TEveChunkManager, 1); // Vector-like container with chunked memory allocation.
0107 };
0108 
0109 
0110 //______________________________________________________________________________
0111 inline Char_t* TEveChunkManager::NewAtom()
0112 {
0113    Char_t *a = (fSize >= fCapacity) ? NewChunk() : Atom(fSize);
0114    ++fSize;
0115    return a;
0116 }
0117 
0118 
0119 /******************************************************************************/
0120 // Templated some-class TEveChunkVector
0121 /******************************************************************************/
0122 
0123 template<class T>
0124 class TEveChunkVector : public TEveChunkManager
0125 {
0126 private:
0127    TEveChunkVector(const TEveChunkVector&);            // Not implemented
0128    TEveChunkVector& operator=(const TEveChunkVector&); // Not implemented
0129 
0130 public:
0131    TEveChunkVector()                 : TEveChunkManager() {}
0132    TEveChunkVector(Int_t chunk_size) : TEveChunkManager(sizeof(T), chunk_size) {}
0133    ~TEveChunkVector() override {}
0134 
0135    void Reset(Int_t chunk_size) { Reset(sizeof(T), chunk_size); }
0136 
0137    T* At(Int_t idx)  { return reinterpret_cast<T*>(Atom(idx)); }
0138    T& Ref(Int_t idx) { return *At(idx); }
0139 
0140    ClassDefOverride(TEveChunkVector, 1); // Templated class for specific atom classes (given as template argument).
0141 };
0142 
0143 #endif