All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CachedBandBlocksManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/memory/CachedBandBlocksManager.cpp
22 
23  \brief RAM cached and tiled raster band blocks manager.
24 */
25 
26 // TerraLib
27 #include "../common/PlatformUtils.h"
28 #include "../raster/Band.h"
29 #include "../raster/BandProperty.h"
31 
32 // STL
33 #include <algorithm>
34 
36 {
37  m_rasterPtr = 0;
45 }
46 
48 {
49  initState();
50 }
51 
53 {
54  free();
55 }
56 
58  const te::rst::Raster& externalRaster, const unsigned char maxMemPercentUsed,
59  const unsigned int dataPrefetchThreshold)
60 {
61  free();
62 
63  // Finding the global block dimensions
64 
65  unsigned int maxBlockSizeBytes = 0;
66 
67  for( unsigned int bandIdx = 0 ; bandIdx < externalRaster.getNumberOfBands() ;
68  ++bandIdx )
69  {
70  if( maxBlockSizeBytes < (unsigned int)externalRaster.getBand( bandIdx )->getBlockSize() )
71  maxBlockSizeBytes = (unsigned int)externalRaster.getBand( bandIdx )->getBlockSize();
72  }
73 
74  const double totalPhysMem = (double)te::common::GetTotalPhysicalMemory();
75  const double usedVMem = (double)te::common::GetUsedVirtualMemory();
76  const double totalVMem = ( (double)te::common::GetTotalVirtualMemory() ) /
77  2.0;
78  const double freeVMem = ( ((double)maxMemPercentUsed) / 100.0 ) *
79  std::min( totalPhysMem, ( ( totalVMem <= usedVMem ) ? 0.0 : ( totalVMem - usedVMem ) ) );
80  const unsigned int maxNumberOfCacheBlocks = (unsigned int)
81  std::max( 1.0, std::ceil( freeVMem / ((double)maxBlockSizeBytes) ) );
82 
83  return initialize( maxNumberOfCacheBlocks, externalRaster, dataPrefetchThreshold );
84 }
85 
87  const unsigned int maxNumberOfCacheBlocks,
88  const te::rst::Raster& externalRaster,
89  const unsigned int dataPrefetchThreshold)
90 {
91  free();
92 
93  // Finding the global block dimensions
94 
95  unsigned int numberOfRasterBlocks = 0;
96 
97  for( unsigned int bandIdx = 0 ; bandIdx < externalRaster.getNumberOfBands() ;
98  ++bandIdx )
99  {
100  if( m_globalBlocksNumberX < (unsigned int)externalRaster.getBand( bandIdx )->getProperty()->m_nblocksx )
101  m_globalBlocksNumberX = (unsigned int)externalRaster.getBand( bandIdx )->getProperty()->m_nblocksx;
102 
103  if( m_globalBlocksNumberY < (unsigned int)externalRaster.getBand( bandIdx )->getProperty()->m_nblocksy )
104  m_globalBlocksNumberY = (unsigned int)externalRaster.getBand( bandIdx )->getProperty()->m_nblocksy;
105 
106  if( m_globalBlockSizeBytes < (unsigned int)externalRaster.getBand( bandIdx )->getBlockSize() )
107  m_globalBlockSizeBytes = (unsigned int)externalRaster.getBand( bandIdx )->getBlockSize();
108 
109  numberOfRasterBlocks +=
110  ( externalRaster.getBand( bandIdx )->getProperty()->m_nblocksx *
111  externalRaster.getBand( bandIdx )->getProperty()->m_nblocksy );
112  }
113 
114  // Allocating the internal structures
115 
116  m_rasterPtr = (te::rst::Raster*)&externalRaster;
117  m_dataPrefetchThreshold = dataPrefetchThreshold;
118 
119  m_maxNumberOfCacheBlocks = std::min( maxNumberOfCacheBlocks, numberOfRasterBlocks );
120  m_maxNumberOfCacheBlocks = std::max( m_maxNumberOfCacheBlocks, (unsigned int)1 );
121 
122  unsigned int blockBIdx = 0;
123  m_blocksPointers.resize( externalRaster.getNumberOfBands() );
124 
125  for( blockBIdx = 0 ; blockBIdx < m_blocksPointers.size() ; ++blockBIdx )
126  {
127  m_blocksPointers[ blockBIdx ].resize( m_globalBlocksNumberY );
128 
129  for( unsigned int blockYIdx = 0 ; blockYIdx < m_globalBlocksNumberY ;
130  ++blockYIdx )
131  {
132  m_blocksPointers[ blockBIdx ][ blockYIdx ].resize( m_globalBlocksNumberX, 0 );
133  }
134  }
135 
136  if( m_dataPrefetchThreshold )
137  {
138  m_threadParams.m_rasterPtr = (te::rst::Raster*)&externalRaster;
139  m_threadParams.m_dataPrefetchThreshold = dataPrefetchThreshold;
140  m_threadParams.m_taskFinished = false;
141  m_threadParams.m_task = ThreadParameters::InvalidTaskT;
142  m_threadParams.m_blockPtr= 0;
143  m_threadParams.m_exchangeBlockPtr= 0;
144  m_threadParams.m_blockB = 0;
145  m_threadParams.m_blockX = 0;
146  m_threadParams.m_blockY = 0;
147  m_threadParams.m_threadDataBlockHandler.reset( new unsigned char[
148  m_globalBlockSizeBytes ] );
149 
150  m_threadHandler.reset( new boost::thread( threadEntry, &m_threadParams ) );
151  }
152 
153  return true;
154 }
155 
157 {
158  // Stopping the thread
159 
160  if( m_dataPrefetchThreshold )
161  {
162  {
163  boost::lock_guard<boost::mutex> lock(m_threadParams.m_doTaskMutex);
164  m_threadParams.m_task = ThreadParameters::SuicideTastT;
165  m_threadParams.m_doTaskCondVar.notify_one();
166  }
167 
168  m_threadHandler->join();
169  m_threadHandler.reset();
170  }
171 
172  // flushing the ram data, if necessary
173 
174  if( ( m_rasterPtr != 0 ) &&
175  ( m_rasterPtr->getAccessPolicy() & te::common::WAccess ) )
176  {
177  unsigned int blockBIdx = 0;
178  unsigned int blockYIdx = 0;
179  unsigned int blockXIdx = 0;
180  void* blockPtr = 0;
181 
182  for( blockBIdx = 0 ; blockBIdx < m_blocksPointers.size() ; ++blockBIdx )
183  {
184  for( blockYIdx = 0 ; blockYIdx < m_globalBlocksNumberY ;
185  ++blockYIdx )
186  {
187  for( blockXIdx = 0 ; blockXIdx < m_globalBlocksNumberX ;
188  ++blockXIdx )
189  {
190  blockPtr = m_blocksPointers[ blockBIdx ][ blockYIdx ][ blockXIdx ];
191 
192  if( blockPtr )
193  {
194  m_rasterPtr->getBand( blockBIdx )->write( blockXIdx, blockYIdx,
195  blockPtr );
196  }
197  }
198  }
199  }
200  }
201 
202  m_blocksPointers.clear();
203 
204  unsigned char* blockPtr = 0;
205  for( std::vector< unsigned char* >::size_type blocksHandlerIdx = 0 ;
206  blocksHandlerIdx < m_blocksHandler.size() ; ++blocksHandlerIdx )
207  {
208  blockPtr = m_blocksHandler[ blocksHandlerIdx ];
209  if( blockPtr )
210  {
211  delete[]( blockPtr );
212  }
213  }
214  m_blocksHandler.clear();
215 
216  m_blocksFifo.clear();
217  m_threadHandler.reset();
218  m_threadParams.m_threadDataBlockHandler.reset();
219 
220  initState();
221 }
222 
224  unsigned int x, unsigned int y )
225 {
226  assert( m_rasterPtr );
227  assert( band < m_rasterPtr->getNumberOfBands() );
228  assert( x < m_globalBlocksNumberX );
229  assert( y < m_globalBlocksNumberY );
230  assert( x < (unsigned int)m_rasterPtr->getBand( band )->getProperty()->m_nblocksx );
231  assert( y < (unsigned int)m_rasterPtr->getBand( band )->getProperty()->m_nblocksy );
232 
233  m_getBlockPointer_BlkPtr = m_blocksPointers[ band ][ y ][ x ];
234 
235  if( m_getBlockPointer_BlkPtr == 0 )
236  {
237  // Is swapp necessary ?
238  if( m_blocksHandler.size() < m_maxNumberOfCacheBlocks )
239  {
240  m_getBlockPointer_BlkPtr = new unsigned char[ m_globalBlockSizeBytes ];
241  m_blocksHandler.push_back( m_getBlockPointer_BlkPtr );
242 
243  // add FIFO information of the new block
244  BlockIndex newBlockFifoIndex;
245  newBlockFifoIndex.m_b = band;
246  newBlockFifoIndex.m_y = y;
247  newBlockFifoIndex.m_x = x;
248  m_blocksFifo.push_back( newBlockFifoIndex );
249  }
250  else
251  {
252  BlockIndex& choosedSwapBlockIndex = m_blocksFifo[
253  m_blocksFifoNextSwapBlockIndex ];
254 
255  m_getBlockPointer_BlkPtr = m_blocksPointers[ choosedSwapBlockIndex.m_b ][
256  choosedSwapBlockIndex.m_y ][ choosedSwapBlockIndex.m_x ];
257  assert( m_getBlockPointer_BlkPtr );
258  m_blocksPointers[ choosedSwapBlockIndex.m_b ][
259  choosedSwapBlockIndex.m_y ][ choosedSwapBlockIndex.m_x ] = 0;
260 
261  // writing the block choosed for swap, if necessary
262  if( m_rasterPtr->getAccessPolicy() & te::common::WAccess )
263  {
264  if( m_dataPrefetchThreshold )
265  {
266  // request a block writing to the thread
267  {
268  boost::lock_guard<boost::mutex> lock(m_threadParams.m_doTaskMutex);
269 
270  m_threadParams.m_blockB = choosedSwapBlockIndex.m_b;
271  m_threadParams.m_blockX = choosedSwapBlockIndex.m_x;
272  m_threadParams.m_blockY = choosedSwapBlockIndex.m_y;
273  m_threadParams.m_blockPtr = m_getBlockPointer_BlkPtr;
274  m_threadParams.m_exchangeBlockPtr = 0;
275  m_threadParams.m_task = ThreadParameters::WriteTaskT;
276  m_threadParams.m_taskFinished = false;
277  }
278 
279  m_threadParams.m_doTaskCondVar.notify_one();
280 
281  // wait for the block writing request to finish
282  while( ! m_threadParams.m_taskFinished )
283  {
284  boost::unique_lock<boost::mutex> lock(
285  m_threadParams.m_taskFinishedMutex);
286 
287  while( ! m_threadParams.m_taskFinished )
288  {
289  m_threadParams.m_taskFinishedCondVar.wait( lock );
290  }
291  }
292  }
293  else
294  {
295  m_rasterPtr->getBand( choosedSwapBlockIndex.m_b )->write(
296  choosedSwapBlockIndex.m_x, choosedSwapBlockIndex.m_y,
297  m_getBlockPointer_BlkPtr );
298  }
299  }
300 
301  // advances the next swap block fifo index
302  choosedSwapBlockIndex.m_b = band;
303  choosedSwapBlockIndex.m_y = y;
304  choosedSwapBlockIndex.m_x = x;
305  m_blocksFifoNextSwapBlockIndex = ( m_blocksFifoNextSwapBlockIndex + 1 ) %
306  ((unsigned int)m_blocksFifo.size());
307  }
308 
309  // reading the required block
310  if( m_dataPrefetchThreshold )
311  {
312  // request a block reading to the thread
313  {
314  boost::lock_guard<boost::mutex> lock(m_threadParams.m_doTaskMutex);
315 
316  m_threadParams.m_blockB = band;
317  m_threadParams.m_blockX = x;
318  m_threadParams.m_blockY = y;
319  m_threadParams.m_blockPtr = 0;
320  m_threadParams.m_exchangeBlockPtr = m_getBlockPointer_BlkPtr;
321  m_threadParams.m_task = ThreadParameters::ReadTaskT;
322  m_threadParams.m_taskFinished = false;
323 
324  m_threadParams.m_doTaskCondVar.notify_one();
325  }
326 
327  // wait for the block reading request to finish
328  {
329  boost::unique_lock<boost::mutex> lock(
330  m_threadParams.m_taskFinishedMutex);
331 
332  while( ! m_threadParams.m_taskFinished )
333  {
334  m_threadParams.m_taskFinishedCondVar.wait( lock );
335  }
336  }
337 
338  m_threadParams.m_taskFinished = false;
339 
340  m_blocksPointers[ band ][ y ][ x ] = m_threadParams.m_blockPtr;
341  m_getBlockPointer_BlkPtr = m_threadParams.m_blockPtr;
342  }
343  else
344  {
345  m_rasterPtr->getBand( band )->read( x, y, m_getBlockPointer_BlkPtr );
346  m_blocksPointers[ band ][ y ][ x ] = m_getBlockPointer_BlkPtr;
347  }
348 
349 
350  }
351 
352  return m_getBlockPointer_BlkPtr;
353 }
354 
356 {
357 // std::cout << std::endl << "Thread started" << std::endl;
358 
359  assert( paramsPtr );
360  assert( paramsPtr->m_rasterPtr );
361 
362  // internal data block to exchange
363  unsigned char* internalExchangeBlockPtr = paramsPtr->m_threadDataBlockHandler.get();
364  assert( internalExchangeBlockPtr );
365 
366  int globalReadAheadDirectionVectorX = 0;
367  int globalReadAheadDirectionVectorY = 0;
368  int globalReadAheadDirectionVectorB = 0;
369  bool globalReadAheadBlockReady = false;
370  int globalReadAheadBlockB = 0;
371  int globalReadAheadBlockX = 0;
372  int globalReadAheadBlockY = 0;
373  int lastReadBlockX = 0;
374  int lastReadBlockY = 0;
375  int lastReadBlockB = 0;
376 
377  int currentReadDirectionVectorX = 0;
378  int currentReadDirectionVectorY = 0;
379  int currentReadDirectionVectorB = 0;
380  int nextReadAheadBlkB = 0;
381  int nextReadAheadBlkX = 0;
382  int nextReadAheadBlkY = 0;
383  bool doReadAhead = false;
384 
385  while( true )
386  {
387  // wait for a task
388  boost::unique_lock<boost::mutex> lock( paramsPtr->m_doTaskMutex );
389  while( paramsPtr->m_task == ThreadParameters::InvalidTaskT )
390  {
391  paramsPtr->m_doTaskCondVar.wait( lock );
392  }
393 
394  if( paramsPtr->m_task == ThreadParameters::ReadTaskT )
395  {
396 // std::cout << std::endl << "Starting a read task" << std::endl;
397 
398  assert( paramsPtr->m_blockPtr == 0 );
399  assert( paramsPtr->m_exchangeBlockPtr );
400 
401  if( globalReadAheadBlockReady
402  && ( globalReadAheadBlockB == (int)paramsPtr->m_blockB )
403  && ( globalReadAheadBlockX == (int)paramsPtr->m_blockX )
404  && ( globalReadAheadBlockY == (int)paramsPtr->m_blockY ) )
405  {
406 // std::cout << std::endl << "Read-ahead block is avaliable, it will be used" << std::endl;
407 
408  // use the read-ahed block
409  paramsPtr->m_blockPtr = internalExchangeBlockPtr;
410  globalReadAheadBlockReady = false;
411  internalExchangeBlockPtr = paramsPtr->m_exchangeBlockPtr;
412 
413 // std::cout << std::endl << "Read-ahead block used." << std::endl;
414  }
415  else
416  {
417 // std::cout << std::endl << "Read-ahead block not avaliable, block will be read from raster" << std::endl;
418 
419  // read from the external raster
420  paramsPtr->m_rasterPtr->getBand( paramsPtr->m_blockB )->read( paramsPtr->m_blockX,
421  paramsPtr->m_blockY, paramsPtr->m_exchangeBlockPtr );
422  paramsPtr->m_blockPtr = paramsPtr->m_exchangeBlockPtr;
423 
424 // std::cout << std::endl << "Block readed from raster." << std::endl;
425  }
426 
427  // notifying the task finishment
428 
429  {
430  boost::lock_guard<boost::mutex> lock( paramsPtr->m_taskFinishedMutex );
431 
432  paramsPtr->m_taskFinished = true;
433  paramsPtr->m_task = ThreadParameters::InvalidTaskT;
434 
435  paramsPtr->m_taskFinishedCondVar.notify_one();
436  }
437 
438  // defining if read-ahed must be done
439 
440  if( paramsPtr->m_dataPrefetchThreshold )
441  {
442  currentReadDirectionVectorX = ( ((int)paramsPtr->m_blockX) - lastReadBlockX );
443  currentReadDirectionVectorY = ( ((int)paramsPtr->m_blockY) - lastReadBlockY );
444  currentReadDirectionVectorB = ( ((int)paramsPtr->m_blockB) - lastReadBlockB );
445 
446  doReadAhead = false;
447 
448  if( ( std::abs( currentReadDirectionVectorX ) < 2 ) &&
449  ( std::abs( currentReadDirectionVectorY ) < 2 )
450  && ( std::abs( currentReadDirectionVectorB ) < 2 ) )
451  {
452  globalReadAheadDirectionVectorX += currentReadDirectionVectorX;
453  globalReadAheadDirectionVectorY += currentReadDirectionVectorY;
454  globalReadAheadDirectionVectorB += currentReadDirectionVectorB;
455 
456  if( ((unsigned int)std::abs( globalReadAheadDirectionVectorB )) >
457  paramsPtr->m_dataPrefetchThreshold )
458  {
459  if( globalReadAheadDirectionVectorB > 0 )
460  {
461  nextReadAheadBlkB = ((int)paramsPtr->m_blockB) + 1;
462  --globalReadAheadDirectionVectorB;
463  }
464  else
465  {
466  nextReadAheadBlkB = ((int)paramsPtr->m_blockB) - 1;
467  ++globalReadAheadDirectionVectorB;
468  }
469 
470  if( ( nextReadAheadBlkB >= 0 ) &&
471  ( nextReadAheadBlkB < (int)paramsPtr->m_rasterPtr->getNumberOfBands() ) )
472  doReadAhead = true;
473  else
474  nextReadAheadBlkB = ((int)paramsPtr->m_blockB);
475  }
476 
477  if( ((unsigned int)std::abs( globalReadAheadDirectionVectorX )) >
478  paramsPtr->m_dataPrefetchThreshold )
479  {
480  if( globalReadAheadDirectionVectorX > 0 )
481  {
482  nextReadAheadBlkX = ((int)paramsPtr->m_blockX) + 1;
483  --globalReadAheadDirectionVectorX;
484  }
485  else
486  {
487  nextReadAheadBlkX = ((int)paramsPtr->m_blockX) - 1;
488  ++globalReadAheadDirectionVectorX;
489  }
490 
491  if( ( nextReadAheadBlkX >= 0 ) &&
492  ( nextReadAheadBlkX <
493  paramsPtr->m_rasterPtr->getBand( nextReadAheadBlkB )->getProperty()->m_nblocksx ) )
494  doReadAhead = true;
495  else
496  nextReadAheadBlkX = ((int)paramsPtr->m_blockX);
497  }
498 
499  if( ((unsigned int)std::abs( globalReadAheadDirectionVectorY )) >
500  paramsPtr->m_dataPrefetchThreshold )
501  {
502  if( globalReadAheadDirectionVectorY > 0 )
503  {
504  nextReadAheadBlkY = ((int)paramsPtr->m_blockY) + 1;
505  --globalReadAheadDirectionVectorY;
506  }
507  else
508  {
509  nextReadAheadBlkY = ((int)paramsPtr->m_blockY) - 1;
510  ++globalReadAheadDirectionVectorY;
511  }
512 
513  if( ( nextReadAheadBlkY >= 0 ) &&
514  ( nextReadAheadBlkY <
515  paramsPtr->m_rasterPtr->getBand( nextReadAheadBlkB )->getProperty()->m_nblocksy ) )
516  doReadAhead = true;
517  else
518  nextReadAheadBlkY = ((int)paramsPtr->m_blockY);
519  }
520  }
521  else
522  {
523  globalReadAheadDirectionVectorX = 0;
524  globalReadAheadDirectionVectorY = 0;
525  globalReadAheadDirectionVectorB = 0;
526  }
527 
528  if( doReadAhead )
529  {
530 // std::cout << std::endl << "Reading-ahead a new block" << std::endl;
531 
532  assert( nextReadAheadBlkB < (int)paramsPtr->m_rasterPtr->getNumberOfBands() );
533  assert( nextReadAheadBlkX <
534  paramsPtr->m_rasterPtr->getBand( nextReadAheadBlkB )->getProperty()->m_nblocksx );
535  assert( nextReadAheadBlkY <
536  paramsPtr->m_rasterPtr->getBand( nextReadAheadBlkB )->getProperty()->m_nblocksy );
537 
538  paramsPtr->m_rasterPtr->getBand( nextReadAheadBlkB )->read( nextReadAheadBlkX,
539  nextReadAheadBlkY, internalExchangeBlockPtr );
540 
541  globalReadAheadBlockX = nextReadAheadBlkX;
542  globalReadAheadBlockY = nextReadAheadBlkY;
543  globalReadAheadBlockB = nextReadAheadBlkB;
544  globalReadAheadBlockReady = true;
545 
546 // std::cout << std::endl << "Read-ahead block reading completed." << std::endl;
547  }
548  }
549 
550  lastReadBlockX = (int)paramsPtr->m_blockX;
551  lastReadBlockY = (int)paramsPtr->m_blockY;
552  lastReadBlockB = (int)paramsPtr->m_blockB;
553  }
554  else if( paramsPtr->m_task == ThreadParameters::WriteTaskT )
555  {
556 // std::cout << std::endl << "Starting a write task" << std::endl;
557 
558  assert( paramsPtr->m_blockPtr );
559  assert( paramsPtr->m_exchangeBlockPtr == 0 );
560 
561  paramsPtr->m_rasterPtr->getBand( paramsPtr->m_blockB )->write( paramsPtr->m_blockX,
562  paramsPtr->m_blockY, paramsPtr->m_blockPtr );
563 
564  // notifying the task finishment
565 
566  paramsPtr->m_taskFinished = true;
567  paramsPtr->m_task = ThreadParameters::InvalidTaskT;
568  paramsPtr->m_taskFinishedCondVar.notify_one();
569  }
570  else if( paramsPtr->m_task == ThreadParameters::SuicideTastT )
571  {
572 // std::cout << std::endl << "Thread ending" << std::endl;
573  return;
574  }
575 
576 // std::cout << std::endl << "Task ended" << std::endl;
577  }
578 }
579 
580 
unsigned int m_x
Block index over the X axis.
unsigned int m_globalBlocksNumberY
The maximum number of blocks (Y axis) for all bands.
unsigned int m_maxNumberOfCacheBlocks
The maximum number of cache blocks.
int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
Definition: Band.cpp:182
unsigned int m_blocksFifoNextSwapBlockIndex
The next block swapp index over m_blocksFifo.
unsigned int m_dataPrefetchThreshold
The user defined read-ahead threshold.
unsigned int m_globalBlocksNumberX
The maximum number of blocks (X axis) for all bands.
RAM cached and tiled raster band blocks manager.
unsigned char * m_exchangeBlockPtr
Exchange block pointer.
boost::mutex m_taskFinishedMutex
used by the thread to inform a task finishment.
void read(int x, int y, void *buffer) const
It reads a data block to the specified buffer.
Definition: Band.cpp:156
bool m_taskFinished
true when the thread has finished the required task.
void initState()
Initialize this instance to an initial state.
int m_nblocksy
The number of blocks in y.
Definition: BandProperty.h:146
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
unsigned int m_globalBlockSizeBytes
The maximum block size for all bands.
unsigned int m_y
Block index over the Y axis.
TaskType m_task
The required task to be performed (read/write/exit).
bool initialize(const te::rst::Raster &externalRaster, const unsigned char maxMemPercentUsed, const unsigned int dataPrefetchThreshold)
Initialize this instance to an initial state.
boost::mutex m_doTaskMutex
Used when wakenning the thread to perform some task.
te::rst::Raster * m_rasterPtr
External raster pointer.
unsigned long int GetTotalPhysicalMemory()
Returns the amount of total physical memory (bytes).
unsigned int m_dataPrefetchThreshold
The read-ahead data prefetch threshold (0-will disable prefetch, 1-data always prefetched, higher values will do prefetch when necessary).
boost::condition_variable m_taskFinishedCondVar
Used to wait for the required task finishment.
te::rst::Raster * m_rasterPtr
External raster pointer.
Internal read/write thread execution parameters.
int m_nblocksx
The number of blocks in x.
Definition: BandProperty.h:145
An abstract class for raster data strucutures.
Definition: Raster.h:70
BandProperty * getProperty()
Returns the band property.
Definition: Band.cpp:370
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
unsigned long int GetUsedVirtualMemory()
Returns the amount of used virtual memory (bytes) for the current process (physical + swapped)...
unsigned long int GetTotalVirtualMemory()
Returns the amount of total virtual memory (bytes) that can be claimed by the current process (physic...
static void threadEntry(ThreadParameters *paramsPtr)
Thread entry.
void write(int x, int y, void *buffer)
It writes a data block from the specified buffer.
Definition: Band.cpp:170
boost::condition_variable m_doTaskCondVar
Used by the thread when awakenning to perform some task.
boost::scoped_array< unsigned char > m_threadDataBlockHandler
A extra block used in exchange when a read-ahead task is performed.
void * getBlockPointer(unsigned int band, unsigned int x, unsigned int y)
Returns a pointer to the required data block.