75 ClassImp(TFileDrawMap);
80 TFileDrawMap::TFileDrawMap() :TNamed()
92 TFileDrawMap::TFileDrawMap(
const TFile *file,
const char *keys, Option_t *option)
93 : TNamed(
"TFileDrawMap",
"")
103 if (file->GetEND() > 1000000) {
108 fFrame =
new TH1D(
"hmapframe",
"",1000,0,fXsize);
109 fFrame->SetDirectory(0);
110 fFrame->SetBit(TH1::kNoStats);
111 fFrame->SetBit(kCanDelete);
112 fFrame->SetMinimum(0);
114 fFrame->GetYaxis()->SetTitle(
"MBytes");
116 fFrame->GetYaxis()->SetTitle(
"KBytes");
118 fFrame->GetXaxis()->SetTitle(
"Bytes");
119 fYsize = 1 + Int_t(file->GetEND()/fXsize);
120 fFrame->SetMaximum(fYsize);
121 fFrame->GetYaxis()->SetLimits(0,fYsize);
138 TFileDrawMap::~TFileDrawMap()
152 void TFileDrawMap::AnimateTree(
const char *branches)
154 TString ourbranches( GetName() );
155 Ssiz_t pos = ourbranches.Index(
", basket=");
156 if (pos == kNPOS)
return;
157 ourbranches.Remove(pos);
158 pos = ourbranches.Index(
", branch=");
159 if (pos == kNPOS)
return;
160 ourbranches[pos] = 0;
162 TTree *tree = (TTree*)fFile->Get(ourbranches.Data());
165 if (strlen(branches) > 0) info = branches;
166 else info = ourbranches.Data()+pos+9;
167 printf(
"Animating tree, branches=%s\n",info.Data());
174 while((comma = strrchr((
char*)info.Data(),
','))) {
177 while (*comma ==
' ') comma++;
178 branch = tree->GetBranch(comma);
180 nzip += (Int_t)branch->GetZipBytes();
181 branch->SetUniqueID(0);
185 comma = (
char*)info.Data();
186 while (*comma ==
' ') comma++;
187 branch = tree->GetBranch(comma);
189 nzip += (Int_t)branch->GetZipBytes();
190 branch->SetUniqueID(0);
193 Double_t fractionRead = Double_t(nzip)/Double_t(fFile->GetEND());
194 Int_t nbranches = list.GetEntries();
197 Int_t nentries = (Int_t)tree->GetEntries();
199 Int_t stime = (Int_t)(100./(nentries*fractionRead));
200 if (stime < 10) {stime=1; sleep = nentries/400;}
201 gPad->SetDoubleBuffer(0);
202 gVirtualX->SetDrawMode(TVirtualX::kInvert);
203 for (Int_t entry=0;entry<nentries;entry++) {
204 for (Int_t ib=0;ib<nbranches;ib++) {
205 branch = (TBranch*)list.At(ib);
206 Int_t nbaskets = branch->GetListOfBaskets()->GetSize();
207 Int_t basket = TMath::BinarySearch(nbaskets,branch->GetBasketEntry(), (Long64_t) entry);
208 Int_t nbytes = branch->GetBasketBytes()[basket];
209 Int_t bseek = branch->GetBasketSeek(basket);
210 Int_t entry0 = branch->GetBasketEntry()[basket];
211 Int_t entryn = branch->GetBasketEntry()[basket+1];
212 Int_t eseek = (Int_t)(bseek + nbytes*Double_t(entry-entry0)/Double_t(entryn-entry0));
213 DrawMarker(ib,branch->GetUniqueID());
214 DrawMarker(ib,eseek);
215 branch->SetUniqueID(eseek);
216 gSystem->ProcessEvents();
217 if (entry%sleep == 0) gSystem->Sleep(stime);
226 Int_t TFileDrawMap::DistancetoPrimitive(Int_t px, Int_t py)
228 Int_t pxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
229 Int_t pxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
230 Int_t pymin = gPad->YtoAbsPixel(gPad->GetUymin());
231 Int_t pymax = gPad->YtoAbsPixel(gPad->GetUymax());
232 if (px > pxmin && px < pxmax && py > pymax && py < pymin) {
233 SetName(GetObjectInfo(px,py));
236 return fFrame->DistancetoPrimitive(px,py);
242 void TFileDrawMap::DrawMarker(Int_t marker, Long64_t eseek)
244 Int_t iy = gPad->YtoAbsPixel(eseek/fXsize);
245 Int_t ix = gPad->XtoAbsPixel(eseek%fXsize);
247 Int_t mark = marker%4;
251 gVirtualX->DrawLine(ix-3*d,iy,ix,iy);
252 gVirtualX->DrawLine(ix-d,iy+d,ix,iy);
253 gVirtualX->DrawLine(ix-d,iy-d,ix,iy);
254 gVirtualX->DrawLine(ix-d,iy-d,ix-d,iy+d);
258 gVirtualX->DrawLine(ix-d,iy-d,ix+d,iy-d);
259 gVirtualX->DrawLine(ix+d,iy-d,ix,iy+d);
260 gVirtualX->DrawLine(ix,iy+d,ix-d,iy-d);
264 gVirtualX->DrawLine(ix-d,iy-d,ix+d,iy-d);
265 gVirtualX->DrawLine(ix+d,iy-d,ix+d,iy+d);
266 gVirtualX->DrawLine(ix+d,iy+d,ix-d,iy+d);
267 gVirtualX->DrawLine(ix-d,iy+d,ix-d,iy-d);
271 gVirtualX->DrawLine(ix-d,iy,ix+d,iy);
272 gVirtualX->DrawLine(ix,iy-d,ix,iy+d);
280 void TFileDrawMap::DrawObject()
282 TVirtualPad *padsave = gROOT->GetSelectedPad();
283 if (padsave == gPad) {
285 gROOT->MakeDefCanvas();
291 char *info =
new char[fName.Length()+1];
292 strlcpy(info,fName.Data(),fName.Length()+1);
293 char *cbasket = (
char*)strstr(info,
", basket=");
296 char *cbranch = (
char*)strstr(info,
", branch=");
297 if (!cbranch)
return;
300 TTree *tree = (TTree*)fFile->Get(info);
301 if (tree) tree->Draw(cbranch);
306 TObject *obj = GetObject();
307 if (obj) obj->Draw();
314 void TFileDrawMap::DumpObject()
316 TObject *obj = GetObject();
321 char *centry = (
char*)strstr(GetName(),
"entry=");
324 sscanf(centry+6,
"%d",&entry);
325 TString info(GetName());
326 char *colon = (
char*)strstr((
char*)info.Data(),
"::");
330 TTree *tree; fFile->GetObject(info.Data(),tree);
331 if (tree) tree->Show(entry);
337 void TFileDrawMap::ExecuteEvent(Int_t event, Int_t px, Int_t py)
339 fFrame->ExecuteEvent(event,px,py);
345 TObject *TFileDrawMap::GetObject()
347 if (strstr(GetName(),
"entry="))
return 0;
348 char *info =
new char[fName.Length()+1];
349 strlcpy(info,fName.Data(),fName.Length()+1);
350 char *colon = strstr(info,
"::");
351 if (!colon)
return 0;
354 return fFile->Get(info);
362 char *TFileDrawMap::GetObjectInfo(Int_t px, Int_t py)
const
367 GetObjectInfoDir(fFile, px, py, info);
368 return (
char*)info.Data();
376 Bool_t TFileDrawMap::GetObjectInfoDir(TDirectory *dir, Int_t px, Int_t py, TString &info)
const
378 Double_t x = gPad->AbsPixeltoX(px);
379 Double_t y = gPad->AbsPixeltoY(py);
381 Long64_t pbyte = (Long64_t)(fXsize*iy+x);
384 TDirectory *dirsav = gDirectory;
387 TIter next(dir->GetListOfKeys());
389 while ((key = (TKey*)next())) {
390 TDirectory *curdir = gDirectory;
391 TClass *cl = TClass::GetClass(key->GetClassName());
393 if (cl && cl == TDirectoryFile::Class()) {
394 curdir->cd(key->GetName());
395 TDirectory *subdir = gDirectory;
396 Bool_t gotInfo = GetObjectInfoDir(subdir, px, py, info);
405 if (cl && cl->InheritsFrom(TTree::Class())) {
406 TTree *tree = (TTree*)gDirectory->Get(key->GetName());
407 TIter nextb(tree->GetListOfLeaves());
409 while ((leaf = (TLeaf*)nextb())) {
410 TBranch *branch = leaf->GetBranch();
411 Int_t nbaskets = branch->GetMaxBaskets();
412 Int_t offsets = branch->GetEntryOffsetLen();
413 Int_t len = leaf->GetLen();
414 for (Int_t i=0;i<nbaskets;i++) {
415 bseek = branch->GetBasketSeek(i);
417 nbytes = branch->GetBasketBytes()[i];
418 if (pbyte >= bseek && pbyte < bseek+nbytes) {
419 Int_t entry = branch->GetBasketEntry()[i];
420 if (!offsets) entry += (pbyte-bseek)/len;
421 if (curdir == (TDirectory*)fFile) {
422 info.Form(
"%s%s, branch=%s, basket=%d, entry=%d",curdir->GetPath(),key->GetName(),branch->GetName(),i,entry);
424 info.Form(
"%s/%s, branch=%s, basket=%d, entry=%d",curdir->GetPath(),key->GetName(),branch->GetName(),i,entry);
431 nbytes = key->GetNbytes();
432 bseek = key->GetSeekKey();
433 if (pbyte >= bseek && pbyte < bseek+nbytes) {
434 if (curdir == (TDirectory*)fFile) {
435 info.Form(
"%s%s ::%s, nbytes=%d",curdir->GetPath(),key->GetName(),key->GetClassName(),nbytes);
437 info.Form(
"%s/%s ::%s, nbytes=%d",curdir->GetPath(),key->GetName(),key->GetClassName(),nbytes);
444 if (pbyte >= dir->GetSeekKeys() && pbyte < dir->GetSeekKeys()+dir->GetNbytesKeys()) {
445 info.Form(
"%sKeys List, nbytes=%d",dir->GetPath(),dir->GetNbytesKeys());
449 if (dir == (TDirectory*)fFile) {
451 if (pbyte >= fFile->GetSeekInfo() && pbyte < fFile->GetSeekInfo()+fFile->GetNbytesInfo()) {
452 info.Form(
"%sStreamerInfo List, nbytes=%d",dir->GetPath(),fFile->GetNbytesInfo());
457 if (pbyte >= fFile->GetSeekFree() && pbyte < fFile->GetSeekFree()+fFile->GetNbytesFree()) {
458 info.Form(
"%sFree List, nbytes=%d",dir->GetPath(),fFile->GetNbytesFree());
463 info.Form(
"(byte=%lld)",pbyte);
471 void TFileDrawMap::InspectObject()
473 TObject *obj = GetObject();
474 if (obj) obj->Inspect();
480 void TFileDrawMap::Paint(Option_t *)
483 if (!fOption.Contains(
"same")) {
486 if (fFrame->GetMaximumStored() < -1000) {
487 fFrame->SetMaximum(fYsize+1);
488 fFrame->SetMinimum(0);
489 fFrame->GetYaxis()->SetLimits(0,fYsize+1);
495 PaintDir(fFile, fKeys.Data());
497 fFrame->Draw(
"sameaxis");
503 void TFileDrawMap::PaintBox(TBox &box, Long64_t bseek, Int_t nbytes)
505 Int_t iy = bseek/fXsize;
506 Int_t ix = bseek%fXsize;
507 Int_t ny = 1+(nbytes+ix)/fXsize;
508 Double_t xmin,ymin,xmax,ymax;
509 for (Int_t j=0;j<ny;j++) {
510 if (j == 0) xmin = (Double_t)ix;
512 xmax = xmin + nbytes;
513 if (xmax > fXsize) xmax = fXsize;
516 nbytes -= (Int_t)(xmax-xmin);
517 if (xmax < gPad->GetUxmin())
continue;
518 if (xmin > gPad->GetUxmax())
continue;
519 if (xmin < gPad->GetUxmin()) xmin = gPad->GetUxmin();
520 if (xmax > gPad->GetUxmax()) xmax = gPad->GetUxmax();
521 if (ymax < gPad->GetUymin())
continue;
522 if (ymin > gPad->GetUymax())
continue;
523 if (ymin < gPad->GetUymin()) ymin = gPad->GetUymin();
524 if (ymax > gPad->GetUymax()) ymax = gPad->GetUymax();
526 box.PaintBox(xmin,ymin,xmax,ymax);
533 void TFileDrawMap::PaintDir(TDirectory *dir,
const char *keys)
535 TDirectory *dirsav = gDirectory;
536 TIter next(dir->GetListOfKeys());
540 TRegexp re(keys,kTRUE);
541 while ((key = (TKey*)next())) {
542 Int_t nbytes = key->GetNbytes();
543 Long64_t bseek = key->GetSeekKey();
544 TClass *cl = TClass::GetClass(key->GetClassName());
546 color = (Int_t)(cl->GetUniqueID()%20);
550 box.SetFillColor(color);
551 box.SetFillStyle(1001);
552 TString s = key->GetName();
553 if (strcmp(fKeys.Data(),key->GetName()) && s.Index(re) == kNPOS)
continue;
555 if (cl && cl == TDirectoryFile::Class()) {
556 TDirectory *curdir = gDirectory;
557 gDirectory->cd(key->GetName());
558 TDirectory *subdir = gDirectory;
559 PaintDir(subdir,
"*");
562 PaintBox(box,bseek,nbytes);
564 if (cl && cl->InheritsFrom(TTree::Class())) {
565 TTree *tree = (TTree*)gDirectory->Get(key->GetName());
566 TIter nextb(tree->GetListOfLeaves());
568 while ((leaf = (TLeaf*)nextb())) {
569 TBranch *branch = leaf->GetBranch();
570 color = branch->GetFillColor();
571 if (color == 0) color = 1;
572 box.SetFillColor(color);
573 Int_t nbaskets = branch->GetMaxBaskets();
574 for (Int_t i=0;i<nbaskets;i++) {
575 bseek = branch->GetBasketSeek(i);
577 nbytes = branch->GetBasketBytes()[i];
578 PaintBox(box,bseek,nbytes);
584 box.SetFillColor(50);
585 box.SetFillStyle(1001);
586 PaintBox(box,dir->GetSeekKeys(),dir->GetNbytesKeys());
587 if (dir == (TDirectory*)fFile) {
590 box.SetFillStyle(3008);
591 PaintBox(box,fFile->GetSeekInfo(),fFile->GetNbytesInfo());
594 box.SetFillStyle(1001);
595 PaintBox(box,fFile->GetSeekFree(),fFile->GetNbytesFree());