ROOT  6.06/09
Reference Guide
TFilePrefetch.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Elvin Sindrilaru 19/05/2011
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TFilePrefetch
13 #define ROOT_TFilePrefetch
14 
15 #ifndef ROOT_TFile
16 #include "TFile.h"
17 #endif
18 #ifndef ROOT_TThread
19 #include "TThread.h"
20 #endif
21 #ifndef ROOT_TFPBlock
22 #include "TFPBlock.h"
23 #endif
24 #ifndef ROOT_TCondition
25 #include "TCondition.h"
26 #endif
27 #ifndef ROOT_TSemaphore
28 #include "TSemaphore.h"
29 #endif
30 #ifndef ROOT_TMD5
31 #include "TMD5.h"
32 #endif
33 #ifndef ROOT_TObject
34 #include "TObject.h"
35 #endif
36 #ifndef ROOT_TString
37 #include "TString.h"
38 #endif
39 #ifndef ROOT_TObjString
40 #include "TObjString.h"
41 #endif
42 #ifndef ROOT_TMutex
43 #include "TMutex.h"
44 #endif
45 #ifndef ROOT_TObjArray
46 #include "TObjArray.h"
47 #endif
48 #ifndef ROOT_TStopwatch
49 #include "TStopwatch.h"
50 #endif
51 
52 
53 class TFilePrefetch : public TObject {
54 
55 private:
56  TFile *fFile; // reference to the file
57  TList *fPendingBlocks; // list of pending blocks to be read
58  TList *fReadBlocks; // list of blocks read
59  TThread *fConsumer; // consumer thread
60  TMutex *fMutexPendingList; // mutex for the pending list
61  TMutex *fMutexReadList; // mutex for the list of read blocks
62  TCondition *fNewBlockAdded; // signal the addition of a new pending block
63  TCondition *fReadBlockAdded; // signal the addition of a new red block
64  TSemaphore *fSemMasterWorker; // semaphore used to kill the consumer thread
65  TSemaphore *fSemWorkerMaster; // semaphore used to notify the master that worker is killed
66  TSemaphore *fSemChangeFile; // semaphore used when changin a file in TChain
67  TString fPathCache; // path to the cache directory
68  TStopwatch fWaitTime; // time wating to prefetch a buffer (in usec)
69  Bool_t fThreadJoined; // mark if async thread was joined
70 
71  static TThread::VoidRtnFunc_t ThreadProc(void*); //create a joinable worker thread
72 
73 public:
75  virtual ~TFilePrefetch();
76 
77  void ReadAsync(TFPBlock*, Bool_t&);
78  void ReadListOfBlocks();
79 
82 
83  void AddReadBlock(TFPBlock*);
85  void ReadBlock(Long64_t*, Int_t*, Int_t);
87 
88  TThread *GetThread() const;
90 
91  Bool_t SetCache(const char*);
93  char *GetBlockFromCache(const char*, Int_t);
95 
96  Int_t SumHex(const char*);
99 
100  void SetFile(TFile*);
102  void WaitFinishPrefetch();
103 
104  ClassDef(TFilePrefetch, 0); // File block prefetcher
105 };
106 
107 #endif
void AddPendingBlock(TFPBlock *)
Safe method to add a block to the pendingList.
Definition: TMutex.h:37
void *(* VoidRtnFunc_t)(void *)
Definition: TThread.h:61
void ReadAsync(TFPBlock *, Bool_t &)
Read one block and insert it in prefetchBuffers list.
Bool_t BinarySearchReadList(TFPBlock *, Long64_t, Int_t, Int_t *)
Search for a requested element in a block and return the index.
long long Long64_t
Definition: RtypesCore.h:69
Bool_t CheckBlockInCache(char *&, TFPBlock *)
Test if the block is in cache.
TSemaphore * fSemMasterWorker
Definition: TFilePrefetch.h:64
static TThread::VoidRtnFunc_t ThreadProc(void *)
Execution loop of the consumer thread.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Bool_t fThreadJoined
Definition: TFilePrefetch.h:69
Long64_t GetWaitTime()
Return the time spent wating for buffer to be read in microseconds.
Basic string class.
Definition: TString.h:137
TStopwatch fWaitTime
Definition: TFilePrefetch.h:68
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TCondition * fNewBlockAdded
Definition: TFilePrefetch.h:62
TThread * fConsumer
Definition: TFilePrefetch.h:59
Int_t ThreadStart()
Used to start the consumer thread.
void SaveBlockInCache(TFPBlock *)
Save the block content in cache.
TSemaphore * fSemChangeFile
Definition: TFilePrefetch.h:66
TMutex * fMutexPendingList
Definition: TFilePrefetch.h:60
ClassDef(TFilePrefetch, 0)
TString fPathCache
Definition: TFilePrefetch.h:67
void SetFile(TFile *)
Change the file.
This class represents the encapsulation of a block request.
Definition: TFPBlock.h:24
A doubly linked list.
Definition: TList.h:47
void AddReadBlock(TFPBlock *)
Safe method to add a block to the readList.
TThread * GetThread() const
Return reference to the consumer thread.
void WaitFinishPrefetch()
Killing the async prefetching thread.
Bool_t ReadBuffer(char *, Long64_t, Int_t)
Return a prefetched element.
Int_t SumHex(const char *)
Sum up individual hex values to obtain a decimal value.
void ReadListOfBlocks()
Get blocks specified in prefetchBlocks.
virtual ~TFilePrefetch()
Destructor.
TCondition * fReadBlockAdded
Definition: TFilePrefetch.h:63
The prefetching mechanism uses two classes (TFilePrefetch and TFPBlock) to prefetch in advance a bloc...
Definition: TFilePrefetch.h:53
Mother of all ROOT objects.
Definition: TObject.h:58
char * GetBlockFromCache(const char *, Int_t)
Return a buffer from cache.
Bool_t SetCache(const char *)
Set the path of the cache directory.
void ReadBlock(Long64_t *, Int_t *, Int_t)
Create a TFPBlock object or recycle one and add it to the prefetchBlocks list.
TCondition * GetCondNewBlock() const
TList * fReadBlocks
Definition: TFilePrefetch.h:58
TFilePrefetch(TFile *)
TSemaphore * fSemWorkerMaster
Definition: TFilePrefetch.h:65
TList * fPendingBlocks
Definition: TFilePrefetch.h:57
TFPBlock * GetPendingBlock()
Safe method to remove a block from the pendingList.
TMutex * fMutexReadList
Definition: TFilePrefetch.h:61
TFPBlock * CreateBlockObj(Long64_t *, Int_t *, Int_t)
Create a new block or recycle an old one.
Stopwatch class.
Definition: TStopwatch.h:30