Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:38

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 
0021 namespace ROOT {
0022 namespace Experimental {
0023 
0024 /******************************************************************************/
0025 // REveChunkManager
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;        // Size of atom
0036    Int_t fN;        // Number of atoms in a chunk
0037 
0038    Int_t fSize;     // Size of container, number of atoms
0039    Int_t fVecSize;  // Number of allocated chunks
0040    Int_t fCapacity; // Available capacity within the chunks
0041 
0042    std::vector<TArrayC*> fChunks; // Memory blocks
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    // Iterator
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 /*      iterator(const iterator &i) :
0085          fPlex(i.fPlex), fCurrent(i.fCurrent), fAtomIndex(i.fAtomIndex),
0086          fNextChunk(i.fNextChunk), fAtomsToGo(i.fAtomsToGo),
0087          fSelection(i.fSelection), fSelectionIterator(i.fSelectionIterator) {}
0088 
0089       iterator& operator=(const iterator& i) {
0090          fPlex = i.fPlex; fCurrent = i.fCurrent; fAtomIndex = i.fAtomIndex;
0091          fNextChunk = i.fNextChunk; fAtomsToGo = i.fAtomsToGo;
0092          fSelection = i.fSelection; fSelectionIterator = i.fSelectionIterator;
0093          return *this;
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 // Templated some-class REveChunkVector
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 } // namespace Experimental
0140 } // namespace ROOT
0141 
0142 #endif