Logo ROOT  
Reference Guide
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Elvin Sindrilaru 19/05/2011
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 *************************************************************************/
12#ifndef ROOT_TFilePrefetch
13#define ROOT_TFilePrefetch
15#include "TObject.h"
16#include "TString.h"
17#include "TStopwatch.h"
18#include "TThread.h"
19#include "TFile.h"
21#include <atomic>
22#include <condition_variable>
23#include <mutex>
26class TSemaphore;
27class TFPBlock;
29#include "TSemaphore.h"
30#include "TFPBlock.h"
33class TFilePrefetch : public TObject {
36 TFile *fFile; ///< reference to the file
37 TList *fPendingBlocks; ///< list of pending blocks to be read
38 TList *fReadBlocks; ///< list of blocks read
39 TThread *fConsumer; ///< consumer thread
40 std::mutex fMutexPendingList; ///< mutex for the pending list
41 std::mutex fMutexReadList; ///< mutex for the list of read blocks
42 std::condition_variable fNewBlockAdded; ///< signal the addition of a new pending block
43 std::condition_variable fReadBlockAdded; ///< signal the addition of a new red block
44 TSemaphore *fSemChangeFile; ///< semaphore used when changing a file in TChain
45 TString fPathCache; ///< path to the cache directory
46 TStopwatch fWaitTime; ///< time waiting to prefetch a buffer (in usec)
47 Bool_t fThreadJoined; ///< mark if async thread was joined
48 std::atomic<Bool_t> fPrefetchFinished; ///< true if prefetching is over
50 static TThread::VoidRtnFunc_t ThreadProc(void*); //create a joinable worker thread
54 virtual ~TFilePrefetch();
56 void ReadAsync(TFPBlock*, Bool_t&);
57 void ReadListOfBlocks();
64 void ReadBlock(Long64_t*, Int_t*, Int_t);
67 TThread *GetThread() const;
70 Bool_t SetCache(const char*);
72 char *GetBlockFromCache(const char*, Int_t);
75 Int_t SumHex(const char*);
80 std::condition_variable &GetCondNewBlock() { return fNewBlockAdded; };
81 void WaitFinishPrefetch();
84 ClassDefOverride(TFilePrefetch, 0); // File block prefetcher
long long Long64_t
Definition: RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
This class represents the encapsulation of a block request.
Definition: TFPBlock.h:22
The prefetching mechanism uses two classes (TFilePrefetch and TFPBlock) to prefetch in advance a bloc...
Definition: TFilePrefetch.h:33
std::condition_variable & GetCondNewBlock()
Definition: TFilePrefetch.h:80
Bool_t BinarySearchReadList(TFPBlock *, Long64_t, Int_t, Int_t *)
Search for a requested element in a block and return the index.
void ReadBlock(Long64_t *, Int_t *, Int_t)
Create a TFPBlock object or recycle one and add it to the prefetchBlocks list.
static TThread::VoidRtnFunc_t ThreadProc(void *)
Execution loop of the consumer thread.
Int_t SumHex(const char *)
Sum up individual hex values to obtain a decimal value.
TFilePrefetch(TFile *)
TSemaphore * fSemChangeFile
semaphore used when changing a file in TChain
Definition: TFilePrefetch.h:44
void ReadListOfBlocks()
Get blocks specified in prefetchBlocks.
TFPBlock * CreateBlockObj(Long64_t *, Int_t *, Int_t)
Create a new block or recycle an old one.
TThread * fConsumer
consumer thread
Definition: TFilePrefetch.h:39
std::condition_variable fNewBlockAdded
signal the addition of a new pending block
Definition: TFilePrefetch.h:42
void AddReadBlock(TFPBlock *)
Safe method to add a block to the readList.
Bool_t CheckBlockInCache(char *&, TFPBlock *)
Test if the block is in cache.
Long64_t GetWaitTime()
Return the time spent wating for buffer to be read in microseconds.
Bool_t fThreadJoined
mark if async thread was joined
Definition: TFilePrefetch.h:47
Bool_t SetCache(const char *)
Set the path of the cache directory.
TList * fReadBlocks
list of blocks read
Definition: TFilePrefetch.h:38
Int_t ThreadStart()
Used to start the consumer thread.
std::atomic< Bool_t > fPrefetchFinished
true if prefetching is over
Definition: TFilePrefetch.h:48
void ReadAsync(TFPBlock *, Bool_t &)
Read one block and insert it in prefetchBuffers list.
TFPBlock * GetPendingBlock()
Safe method to remove a block from the pendingList.
void AddPendingBlock(TFPBlock *)
Safe method to add a block to the pendingList.
Bool_t ReadBuffer(char *, Long64_t, Int_t)
Return a prefetched element.
virtual ~TFilePrefetch()
TString fPathCache
path to the cache directory
Definition: TFilePrefetch.h:45
std::mutex fMutexReadList
mutex for the list of read blocks
Definition: TFilePrefetch.h:41
TStopwatch fWaitTime
time waiting to prefetch a buffer (in usec)
Definition: TFilePrefetch.h:46
std::mutex fMutexPendingList
mutex for the pending list
Definition: TFilePrefetch.h:40
std::condition_variable fReadBlockAdded
signal the addition of a new red block
Definition: TFilePrefetch.h:43
void WaitFinishPrefetch()
Killing the async prefetching thread.
TThread * GetThread() const
Return reference to the consumer thread.
TFile * fFile
reference to the file
Definition: TFilePrefetch.h:36
TList * fPendingBlocks
list of pending blocks to be read
Definition: TFilePrefetch.h:37
void SetFile(TFile *file, TFile::ECacheAction action=TFile::kDisconnect)
Change the file.
char * GetBlockFromCache(const char *, Int_t)
Return a buffer from cache.
void SaveBlockInCache(TFPBlock *)
Save the block content in cache.
Bool_t IsPrefetchFinished() const
Definition: TFilePrefetch.h:82
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TTreeCache flushing semantics.
Definition: TFile.h:71
@ kDisconnect
Definition: TFile.h:71
A doubly linked list.
Definition: TList.h:38
Mother of all ROOT objects.
Definition: TObject.h:41
Stopwatch class.
Definition: TStopwatch.h:28
Basic string class.
Definition: TString.h:136
<div class="legacybox"><h2>Legacy Code</h2> TThread is a legacy interface: there will be no bug fixes...
Definition: TThread.h:40
void *(* VoidRtnFunc_t)(void *)
Definition: TThread.h:52
Definition: file.py:1