ROOT logo
// @(#)root/eve:$Id: TEveChunkManager.cxx 21310 2007-12-10 19:05:45Z matevz $
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TEveChunkManager.h"

//______________________________________________________________________________
// TEveChunkManager
//
// Vector-like container with chunked memory allocation.
//
// Allocation chunk can accommodate fN atoms of byte-size fS each.
// The chunks themselves are TArrayCs and are stored in a std::vector<TArrayC*>.
// Holes in the structure are not supported, neither is removal of atoms.
// The structure can be Refit() to occupy a single contiguous array.
//

ClassImp(TEveChunkManager)
ClassImp(TEveChunkManager::iterator)

void TEveChunkManager::ReleaseChunks()
{
   // Release all memory chunks.

   for (Int_t i=0; i<fVecSize; ++i)
      delete fChunks[i];
   fChunks.clear();
}

//______________________________________________________________________________
TEveChunkManager::TEveChunkManager() :
   fS(0), fN(0),
   fSize(0), fVecSize(0), fCapacity(0)
{
   // Default constructor.
   // Call reset for initialization.
}

//______________________________________________________________________________
TEveChunkManager::TEveChunkManager(Int_t atom_size, Int_t chunk_size) :
   fS(atom_size), fN(chunk_size),
   fSize(0), fVecSize(0), fCapacity(0)
{
   // Constructor.
}

//______________________________________________________________________________
TEveChunkManager::~TEveChunkManager()
{
   // Destructor.

   ReleaseChunks();
}

/******************************************************************************/

//______________________________________________________________________________
void TEveChunkManager::Reset(Int_t atom_size, Int_t chunk_size)
{
   // Empty the container and reset it with given atom and chunk sizes.

   ReleaseChunks();
   fS = atom_size;
   fN = chunk_size;
   fSize = fVecSize = fCapacity = 0;
}

//______________________________________________________________________________
void TEveChunkManager::Refit()
{
   // Refit the container so that all current data fits into a single
   // chunk.

   if (fSize == 0 || (fVecSize == 1 && fSize == fCapacity))
      return;

   TArrayC* one = new TArrayC(fS*fSize);
   Char_t*  pos = one->fArray;
   for (Int_t i=0; i<fVecSize; ++i)
   {
      Int_t size = fS * NAtoms(i);
      memcpy(pos, fChunks[i]->fArray, size);
      pos += size;
   }
   ReleaseChunks();
   fN = fCapacity = fSize;
   fVecSize = 1;
   fChunks.push_back(one);
}

/******************************************************************************/

//______________________________________________________________________________
Char_t* TEveChunkManager::NewChunk()
{
   // Allocate a new memory chunk and register it.

   fChunks.push_back(new TArrayC(fS*fN));
   ++fVecSize;
   fCapacity += fN;
   return fChunks.back()->fArray;
}
 TEveChunkManager.cxx:1
 TEveChunkManager.cxx:2
 TEveChunkManager.cxx:3
 TEveChunkManager.cxx:4
 TEveChunkManager.cxx:5
 TEveChunkManager.cxx:6
 TEveChunkManager.cxx:7
 TEveChunkManager.cxx:8
 TEveChunkManager.cxx:9
 TEveChunkManager.cxx:10
 TEveChunkManager.cxx:11
 TEveChunkManager.cxx:12
 TEveChunkManager.cxx:13
 TEveChunkManager.cxx:14
 TEveChunkManager.cxx:15
 TEveChunkManager.cxx:16
 TEveChunkManager.cxx:17
 TEveChunkManager.cxx:18
 TEveChunkManager.cxx:19
 TEveChunkManager.cxx:20
 TEveChunkManager.cxx:21
 TEveChunkManager.cxx:22
 TEveChunkManager.cxx:23
 TEveChunkManager.cxx:24
 TEveChunkManager.cxx:25
 TEveChunkManager.cxx:26
 TEveChunkManager.cxx:27
 TEveChunkManager.cxx:28
 TEveChunkManager.cxx:29
 TEveChunkManager.cxx:30
 TEveChunkManager.cxx:31
 TEveChunkManager.cxx:32
 TEveChunkManager.cxx:33
 TEveChunkManager.cxx:34
 TEveChunkManager.cxx:35
 TEveChunkManager.cxx:36
 TEveChunkManager.cxx:37
 TEveChunkManager.cxx:38
 TEveChunkManager.cxx:39
 TEveChunkManager.cxx:40
 TEveChunkManager.cxx:41
 TEveChunkManager.cxx:42
 TEveChunkManager.cxx:43
 TEveChunkManager.cxx:44
 TEveChunkManager.cxx:45
 TEveChunkManager.cxx:46
 TEveChunkManager.cxx:47
 TEveChunkManager.cxx:48
 TEveChunkManager.cxx:49
 TEveChunkManager.cxx:50
 TEveChunkManager.cxx:51
 TEveChunkManager.cxx:52
 TEveChunkManager.cxx:53
 TEveChunkManager.cxx:54
 TEveChunkManager.cxx:55
 TEveChunkManager.cxx:56
 TEveChunkManager.cxx:57
 TEveChunkManager.cxx:58
 TEveChunkManager.cxx:59
 TEveChunkManager.cxx:60
 TEveChunkManager.cxx:61
 TEveChunkManager.cxx:62
 TEveChunkManager.cxx:63
 TEveChunkManager.cxx:64
 TEveChunkManager.cxx:65
 TEveChunkManager.cxx:66
 TEveChunkManager.cxx:67
 TEveChunkManager.cxx:68
 TEveChunkManager.cxx:69
 TEveChunkManager.cxx:70
 TEveChunkManager.cxx:71
 TEveChunkManager.cxx:72
 TEveChunkManager.cxx:73
 TEveChunkManager.cxx:74
 TEveChunkManager.cxx:75
 TEveChunkManager.cxx:76
 TEveChunkManager.cxx:77
 TEveChunkManager.cxx:78
 TEveChunkManager.cxx:79
 TEveChunkManager.cxx:80
 TEveChunkManager.cxx:81
 TEveChunkManager.cxx:82
 TEveChunkManager.cxx:83
 TEveChunkManager.cxx:84
 TEveChunkManager.cxx:85
 TEveChunkManager.cxx:86
 TEveChunkManager.cxx:87
 TEveChunkManager.cxx:88
 TEveChunkManager.cxx:89
 TEveChunkManager.cxx:90
 TEveChunkManager.cxx:91
 TEveChunkManager.cxx:92
 TEveChunkManager.cxx:93
 TEveChunkManager.cxx:94
 TEveChunkManager.cxx:95
 TEveChunkManager.cxx:96
 TEveChunkManager.cxx:97
 TEveChunkManager.cxx:98
 TEveChunkManager.cxx:99
 TEveChunkManager.cxx:100
 TEveChunkManager.cxx:101
 TEveChunkManager.cxx:102
 TEveChunkManager.cxx:103
 TEveChunkManager.cxx:104
 TEveChunkManager.cxx:105
 TEveChunkManager.cxx:106
 TEveChunkManager.cxx:107
 TEveChunkManager.cxx:108
 TEveChunkManager.cxx:109