TEveChunkManager.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveChunkManager.cxx 33124 2010-04-21 20:04:42Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveChunkManager.h"
00013 
00014 //______________________________________________________________________________
00015 //
00016 // Vector-like container with chunked memory allocation.
00017 //
00018 // Allocation chunk can accommodate fN atoms of byte-size fS each.
00019 // The chunks themselves are TArrayCs and are stored in a std::vector<TArrayC*>.
00020 // Holes in the structure are not supported, neither is removal of atoms.
00021 // The structure can be Refit() to occupy a single contiguous array.
00022 //
00023 
00024 ClassImp(TEveChunkManager);
00025 ClassImp(TEveChunkManager::iterator);
00026 
00027 //______________________________________________________________________________
00028 void TEveChunkManager::ReleaseChunks()
00029 {
00030    // Release all memory chunks.
00031 
00032    for (Int_t i=0; i<fVecSize; ++i)
00033       delete fChunks[i];
00034    fChunks.clear();
00035 }
00036 
00037 //______________________________________________________________________________
00038 TEveChunkManager::TEveChunkManager() :
00039    fS(0), fN(0),
00040    fSize(0), fVecSize(0), fCapacity(0)
00041 {
00042    // Default constructor.
00043    // Call reset for initialization.
00044 }
00045 
00046 //______________________________________________________________________________
00047 TEveChunkManager::TEveChunkManager(Int_t atom_size, Int_t chunk_size) :
00048    fS(atom_size), fN(chunk_size),
00049    fSize(0), fVecSize(0), fCapacity(0)
00050 {
00051    // Constructor.
00052 }
00053 
00054 //______________________________________________________________________________
00055 TEveChunkManager::~TEveChunkManager()
00056 {
00057    // Destructor.
00058 
00059    ReleaseChunks();
00060 }
00061 
00062 /******************************************************************************/
00063 
00064 //______________________________________________________________________________
00065 void TEveChunkManager::Reset(Int_t atom_size, Int_t chunk_size)
00066 {
00067    // Empty the container and reset it with given atom and chunk sizes.
00068 
00069    ReleaseChunks();
00070    fS = atom_size;
00071    fN = chunk_size;
00072    fSize = fVecSize = fCapacity = 0;
00073 }
00074 
00075 //______________________________________________________________________________
00076 void TEveChunkManager::Refit()
00077 {
00078    // Refit the container so that all current data fits into a single
00079    // chunk.
00080 
00081    if (fSize == 0 || (fVecSize == 1 && fSize == fCapacity))
00082       return;
00083 
00084    TArrayC* one = new TArrayC(fS*fSize);
00085    Char_t*  pos = one->fArray;
00086    for (Int_t i=0; i<fVecSize; ++i)
00087    {
00088       Int_t size = fS * NAtoms(i);
00089       memcpy(pos, fChunks[i]->fArray, size);
00090       pos += size;
00091    }
00092    ReleaseChunks();
00093    fN = fCapacity = fSize;
00094    fVecSize = 1;
00095    fChunks.push_back(one);
00096 }
00097 
00098 /******************************************************************************/
00099 
00100 //______________________________________________________________________________
00101 Char_t* TEveChunkManager::NewChunk()
00102 {
00103    // Allocate a new memory chunk and register it.
00104 
00105    fChunks.push_back(new TArrayC(fS*fN));
00106    ++fVecSize;
00107    fCapacity += fN;
00108    return fChunks.back()->fArray;
00109 }
00110 
00111 /******************************************************************************/
00112 
00113 //______________________________________________________________________________
00114 Bool_t TEveChunkManager::iterator::next()
00115 {
00116    // Go to next atom.
00117 
00118    if (fSelection == 0)
00119    {
00120       if (fAtomsToGo <= 0)
00121       {
00122          if (fNextChunk < fPlex->VecSize())
00123          {
00124             fCurrent   = fPlex->Chunk(fNextChunk);
00125             fAtomsToGo = fPlex->NAtoms(fNextChunk);
00126             ++fNextChunk;
00127          }
00128          else
00129          {
00130             return kFALSE;
00131          }
00132       }
00133       else
00134       {
00135          fCurrent += fPlex->S();
00136       }
00137       ++fAtomIndex;
00138       --fAtomsToGo;
00139       return kTRUE;
00140    }
00141    else
00142    {
00143       if (fAtomIndex == -1)
00144          fSelectionIterator = fSelection->begin();
00145       else
00146          ++fSelectionIterator;
00147 
00148       if (fSelectionIterator != fSelection->end())
00149       {
00150          fAtomIndex = *fSelectionIterator;
00151          fCurrent   =  fPlex->Atom(fAtomIndex);
00152          return kTRUE;
00153       }
00154       else
00155       {
00156          return kFALSE;
00157       }
00158    }
00159 }

Generated on Tue Jul 5 14:16:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1