本文整理汇总了C++中TFile::GetCacheRead方法的典型用法代码示例。如果您正苦于以下问题:C++ TFile::GetCacheRead方法的具体用法?C++ TFile::GetCacheRead怎么用?C++ TFile::GetCacheRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFile
的用法示例。
在下文中一共展示了TFile::GetCacheRead方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: h2fast
void h2fast(const char *url , Bool_t draw=kFALSE, Long64_t cachesize=10000000, Int_t learn=1) {
// gEnv->SetValue("TFile.DavixLog", 10);
// gDebug= 0x02;
TStopwatch sw;
TTree* T = NULL;
sw.Start();
Long64_t oldb = TFile::GetFileBytesRead();
TFile *f = TFile::Open(url);
if (!f || f->IsZombie()) {
printf("File h1big.root does not exist\n");
exit (-1);
}
// TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable);
T= (TTree*)f->Get("h42");
Long64_t nentries = T->GetEntries();
T->SetCacheSize(cachesize);
TTreeCache::SetLearnEntries(learn);
TFileCacheRead *tpf = f->GetCacheRead();
//tpf->SetEntryRange(0,nentries);
if (draw) T->Draw("rawtr","E33>20");
else {
TBranch *brawtr = T->GetBranch("rawtr");
TBranch *bE33 = T->GetBranch("E33");
Float_t E33;
bE33->SetAddress(&E33);
for (Long64_t i=0;i<nentries;i++) {
T->LoadTree(i);
bE33->GetEntry(i);
if (E33 > 0) brawtr->GetEntry(i);
}
}
if (tpf) tpf->Print();
printf("Bytes read = %lld\n",TFile::GetFileBytesRead()-oldb);
printf("Real Time = %7.3f s, CPUtime = %7.3f s\n",sw.RealTime(),sw.CpuTime());
delete T;
delete f;
}
示例2: runPrefetchReading
//.........这里部分代码省略.........
// for (Long64_t i=elast-1;i>=efirst;i--) {
if (i%freq == 0 || i==(elast-1)) fprintf(stderr,"i = %lld\n",i);
if (r.Rndm() > percententries) continue;
T->LoadTree(i);
if (percentbranches < 1.00) {
int nb = T->GetListOfBranches()->GetEntries();
int incr = nb * percentbranches;
for(int b=0;b<nb; b += incr) ((TBranch*)T->GetListOfBranches()->At(b))->GetEntry(i);
int count = 0;
int maxcount = 1000 + 100 ;
for(int x = 0; x < maxcount; ++x ) { /* waste cpu */ count = sin(cos((double)count)); }
} else {
T->GetEntry(i);
}
}
}
fprintf(stderr,"Done reading for the first pass, now closing the file\n");
file->Close();
delete file;
//...........................................................................
// Second read, actually reading the data from cache
//...........................................................................
fprintf(stderr,"Opening the file for the 2nd pass\n");
file = TFile::Open( filename, "TIMEOUT=30" );
if (!file || file->IsZombie()) return 1;
fprintf(stderr,"The file has been opened, setting up the TTree\n");
// Try the known names :)
for (unsigned int i = 0; i < sizeof(names)/sizeof(names[0]); ++i) {
file->GetObject(names[i], T);
if (T) break;
}
if (T==0) {
Error("runPrefetchReading","Could not find a tree which the conventional names in %s.",filename.Data());
return 2;
}
TFile::SetReadaheadSize(0); // (256*1024);
nentries = T->GetEntries();
efirst = 0;
elast = efirst+nentries;
if (cachesize == -2) {
gEnv->SetValue("TFile.AsyncReading", 0);
cachesize = -1;
}
T->SetCacheSize(cachesize);
if (cachesize != 0) {
T->SetCacheEntryRange(efirst,elast);
if (percentbranches < 1.00) {
int nb = T->GetListOfBranches()->GetEntries();
int incr = nb * percentbranches;
for(int b=0;b < nb; b += incr) T->AddBranchToCache(((TBranch*)T->GetListOfBranches()->At(b)),kTRUE);
} else {
T->AddBranchToCache("*");
}
T->StopCacheLearningPhase();
}
fprintf(stderr,"Setup done, starting the 2nd reading.\n");
for (Long64_t i = efirst; i < elast; i++) {
if (i % freq == 0){
// for (Long64_t i=elast-1;i>=efirst;i--) {
if (i%freq == 0 || i==(elast-1)) fprintf(stderr,"i = %lld\n",i);
if (r.Rndm() > percententries) continue;
T->LoadTree(i);
if (percentbranches < 1.00) {
int nb = T->GetListOfBranches()->GetEntries();
int incr = nb * percentbranches;
for(int b=0;b<nb; b += incr) {
((TBranch*)T->GetListOfBranches()->At(b))->GetEntry(i);
}
int count = 0;
int maxcount = 1000 + 100 ;
for(int x = 0; x < maxcount; ++x ) {
/* waste cpu */
count = sin(cos((double)count));
}
} else {
T->GetEntry(i);
}
}
}
fprintf(stderr, "Done with the 2nd reading\n");
fprintf(stderr, "fPrefetchedBlocks = %lli\n", file->GetCacheRead()->GetPrefetchedBlocks());
fprintf(stderr, "Delete tmp directory: /tmp/xcache\n" );
if (caching) system( "rm -r /tmp/xcache" );
file->Close();
delete file;
return 0;
}