Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:11:39

0001 // @(#)root/eve7:$Id$
0002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2018
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2019, 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_REveChunkManager
0013 #define ROOT_REveChunkManager
0014 
0015 #include <ROOT/REveUtil.hxx>
0016 
0017 #include "TArrayC.h"
0018 
0019 #include <vector>
0020 #include <set>
0021 
0022 namespace ROOT {
0023 namespace Experimental {
0024 
0025 /******************************************************************************/
0026 // REveChunkManager
0027 /******************************************************************************/
0028 
0029 class REveChunkManager
0030 {
0031 private:
0032    REveChunkManager(const REveChunkManager&) = delete;
0033    REveChunkManager& operator=(const REveChunkManager&) = delete;
0034 
0035 protected:
0036    Int_t fS;        // Size of atom
0037    Int_t fN;        // Number of atoms in a chunk
0038 
0039    Int_t fSize;     // Size of container, number of atoms
0040    Int_t fVecSize;  // Number of allocated chunks
0041    Int_t fCapacity; // Available capacity within the chunks
0042 
0043    std::vector<TArrayC*> fChunks; // Memory blocks
0044 
0045    void ReleaseChunks();
0046 
0047 public:
0048    REveChunkManager();
0049    REveChunkManager(Int_t atom_size, Int_t chunk_size);
0050    virtual ~REveChunkManager();
0051 
0052    void Reset(Int_t atom_size, Int_t chunk_size);
0053    void Refit();
0054 
0055    Int_t    S() const { return fS; }
0056    Int_t    N() const { return fN; }
0057 
0058    Int_t    Size()     const { return fSize; }
0059    Int_t    VecSize()  const { return fVecSize; }
0060    Int_t    Capacity() const { return fCapacity; }
0061 
0062    Char_t* Atom(Int_t idx)   const { return fChunks[idx/fN]->fArray + idx%fN*fS; }
0063    Char_t* Chunk(Int_t chk)  const { return fChunks[chk]->fArray; }
0064    Int_t   NAtoms(Int_t chk) const { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
0065 
0066    Char_t* NewAtom();
0067    Char_t* NewChunk();
0068 
0069 
0070    // Iterator
0071 
0072    struct iterator
0073    {
0074       REveChunkManager &fPlex;
0075       Char_t           *fCurrent{nullptr};
0076       Int_t             fAtomIndex{-1};
0077       Int_t             fNextChunk{0};
0078       Int_t             fAtomsToGo{0};
0079 
0080       const std::set<Int_t>           *fSelection{nullptr};
0081       std::set<Int_t>::const_iterator  fSelectionIterator;
0082 
0083       iterator(REveChunkManager &p) : fPlex(p) {}
0084 
0085 /*      iterator(const iterator &i) :
0086          fPlex(i.fPlex), fCurrent(i.fCurrent), fAtomIndex(i.fAtomIndex),
0087          fNextChunk(i.fNextChunk), fAtomsToGo(i.fAtomsToGo),
0088          fSelection(i.fSelection), fSelectionIterator(i.fSelectionIterator) {}
0089 
0090       iterator& operator=(const iterator& i) {
0091          fPlex = i.fPlex; fCurrent = i.fCurrent; fAtomIndex = i.fAtomIndex;
0092          fNextChunk = i.fNextChunk; fAtomsToGo = i.fAtomsToGo;
0093          fSelection = i.fSelection; fSelectionIterator = i.fSelectionIterator;
0094          return *this;
0095       }
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 };
0107 
0108 
0109 //______________________________________________________________________________
0110 inline Char_t* REveChunkManager::NewAtom()
0111 {
0112    Char_t *a = (fSize >= fCapacity) ? NewChunk() : Atom(fSize);
0113    ++fSize;
0114    return a;
0115 }
0116 
0117 
0118 /******************************************************************************/
0119 // Templated some-class REveChunkVector
0120 /******************************************************************************/
0121 
0122 template<class T>
0123 class REveChunkVector : public REveChunkManager
0124 {
0125 private:
0126    REveChunkVector(const REveChunkVector&) = delete;
0127    REveChunkVector& operator=(const REveChunkVector&) = delete;
0128 
0129 public:
0130    REveChunkVector() = default;
0131    REveChunkVector(Int_t chunk_size) : REveChunkManager(sizeof(T), chunk_size) {}
0132    ~REveChunkVector() override {}
0133 
0134    void Reset(Int_t chunk_size) { Reset(sizeof(T), chunk_size); }
0135 
0136    T *At(Int_t idx)  { return reinterpret_cast<T*>(Atom(idx)); }
0137    T &Ref(Int_t idx) { return *At(idx); }
0138 };
0139 
0140 } // namespace Experimental
0141 } // namespace ROOT
0142 
0143 #endif