26 inline int xtod(
char c) {
return (c>=
'0' && c<=
'9') ? c-
'0' : ((c>=
'A' && c<=
'F') ? c-
'A'+10 : ((c>=
'a' && c<=
'f') ? c-
'a'+10 : 0)); }
55 fPrefetchFinished(kFALSE)
57 fPendingBlocks =
new TList();
58 fReadBlocks =
new TList();
60 fPendingBlocks->SetOwner();
61 fReadBlocks->SetOwner();
89 std::lock_guard<std::mutex> lk(fMutexPendingList);
90 fPrefetchFinished =
kTRUE;
92 fNewBlockAdded.notify_one();
95 fThreadJoined =
kTRUE;
96 fPrefetchFinished =
kFALSE;
107 if (CheckBlockInCache(path, block)){
113 if (fFile->GetArchive()) {
115 block->
SetPos(i, block->
GetPos(i) - fFile->GetArchiveOffset());
130 while((block = GetPendingBlock())){
131 ReadAsync(block, inCache);
134 SaveBlockInCache(block);
146 while (first <= last){
147 mid = first + (last -
first) / 2;
148 if ((offset >= blockObj->
GetPos(mid) && offset <= (blockObj->
GetPos(mid) + blockObj->
GetLen(mid))
149 && ( (offset + len) <= blockObj->
GetPos(mid) + blockObj->
GetLen(mid)))){
169 return Long64_t(fWaitTime.RealTime()*1.e+6);
181 std::unique_lock<std::mutex> lk(fMutexReadList);
186 if (BinarySearchReadList(blockObj, offset, len, &index)){
194 fWaitTime.Start(kFALSE);
195 fReadBlockAdded.wait(lk);
202 pBuff += (offset - blockObj->
GetPos(index));
203 memcpy(buf, pBuff, len);
213 TFPBlock* block = CreateBlockObj(offset, len, nblock);
214 AddPendingBlock(block);
222 fMutexPendingList.lock();
223 fPendingBlocks->Add(block);
224 fMutexPendingList.unlock();
226 fNewBlockAdded.notify_one();
238 fSemChangeFile->Post();
239 std::unique_lock<std::mutex> lk(fMutexPendingList);
241 fNewBlockAdded.wait(lk, [&]{
return fPendingBlocks->GetSize() > 0 || fPrefetchFinished; });
243 fSemChangeFile->Wait();
246 if (fPendingBlocks->GetSize()){
247 block = (
TFPBlock*)fPendingBlocks->First();
248 block = (
TFPBlock*)fPendingBlocks->Remove(block);
258 fMutexReadList.lock();
262 movedBlock = (
TFPBlock*)fReadBlocks->Remove(movedBlock);
267 fReadBlocks->Add(block);
268 fMutexReadList.unlock();
271 fReadBlockAdded.notify_one();
282 fMutexReadList.lock();
285 blockObj =
static_cast<TFPBlock*
>(fReadBlocks->First());
286 fReadBlocks->Remove(blockObj);
287 fMutexReadList.unlock();
291 fMutexReadList.unlock();
292 blockObj =
new TFPBlock(offset, len, noblock);
316 if (!fThreadJoined) {
317 fSemChangeFile->Wait();
322 fMutexPendingList.lock();
323 fPendingBlocks->Clear();
324 fMutexPendingList.unlock();
326 fMutexReadList.lock();
327 fReadBlocks->Clear();
328 fMutexReadList.unlock();
332 if (!fThreadJoined) {
333 fSemChangeFile->Post();
346 rc = fConsumer->Run();
376 const char* ptr =
hex;
379 result +=
xtod(ptr[i]);
389 if (fPathCache ==
"")
411 value = SumHex(fileName);
414 dirName.
Form(
"%i", value);
416 fullPath +=
"/" + dirName +
"/" + fileName;
420 path =
new char[fullPath.
Length() + 1];
421 strlcpy(path, fullPath,fullPath.
Length() + 1);
438 strPath +=
"?filetype=raw";
439 TFile* file =
new TFile(strPath);
444 buffer = (
char*) calloc(length,
sizeof(
char));
445 file->ReadBuffer(buffer, 0, length);
447 fFile->fBytesRead +=
length;
448 fFile->fgBytesRead +=
length;
449 fFile->SetReadCalls(fFile->GetReadCalls() + 1);
450 fFile->fgReadCalls++;
455 gPerfStats->FileReadEvent(fFile, length, start);
468 if (fPathCache ==
"")
485 TString fullPath( fPathCache );
487 dirName.
Form(
"%i", value);
494 fullPath += (
"/" + fileName);
497 fullPath +=
"?filetype=raw";
500 fullPath +=
"?filetype=raw";
void AddPendingBlock(TFPBlock *)
Safe method to add a block to the pendingList.
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.
void ReallocBlock(Long64_t *, Int_t *, Int_t)
Reallocate the block's buffer based on the length of the elements it will contain.
Bool_t CheckBlockInCache(char *&, TFPBlock *)
Test if the block is in cache.
void Final()
MD5 finalization, ends an MD5 message-digest operation, writing the the message digest and zeroizing ...
char * GetPtrToPiece(Int_t index) const
Get block buffer.
static TThread::VoidRtnFunc_t ThreadProc(void *)
Execution loop of the consumer thread.
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
static const int kMAX_READ_SIZE
Long64_t GetWaitTime()
Return the time spent wating for buffer to be read in microseconds.
Int_t ThreadStart()
Used to start the consumer thread.
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
void SaveBlockInCache(TFPBlock *)
Save the block content in cache.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
const char * Data() const
void SetPos(Int_t, Long64_t)
Set pos value for index idx.
const char * AsString() const
Return message digest as string.
This code implements the MD5 message-digest algorithm.
std::map< std::string, std::string >::const_iterator iter
R__EXTERN TVirtualMonitoringWriter * gMonitoringWriter
Bool_t IsPrefetchFinished() const
void SetBuffer(char *)
Set block buffer.
void SetFile(TFile *)
Change the file.
This class represents the encapsulation of a block request.
void AddReadBlock(TFPBlock *)
Safe method to add a block to the readList.
TThread * GetThread() const
Return reference to the consumer thread.
char * GetBuffer() const
Get block buffer.
Double_t length(const TVector2 &v)
void Update(const UChar_t *buf, UInt_t len)
Update TMD5 object to reflect the concatenation of another buffer full of bytes.
R__EXTERN TSystem * gSystem
void WaitFinishPrefetch()
Killing the async prefetching thread.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Int_t GetLen(Int_t) const
Get length of the element at index i.
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.
void *(* VoidRtnFunc_t)(void *)
Long64_t GetPos(Int_t) const
Get position of the element at index i.
The TTimeStamp encapsulates seconds and ns since EPOCH.
The prefetching mechanism uses two classes (TFilePrefetch and TFPBlock) to prefetch in advance a bloc...
virtual Bool_t SendFileReadProgress(TFile *)
char * GetBlockFromCache(const char *, Int_t)
Return a buffer from cache.
Int_t GetNoElem() const
Return number of elements in the block.
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.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Long64_t GetDataSize() const
Return size of the data in the block.
TFPBlock * GetPendingBlock()
Safe method to remove a block from the pendingList.
TFPBlock * CreateBlockObj(Long64_t *, Int_t *, Int_t)
Create a new block or recycle an old one.