Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
THbookKey.cxx
Go to the documentation of this file.
1 // @(#)root/hbook:$Id$
2 // Author: Rene Brun 20/02/2002
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, 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 #include "THbookKey.h"
13 #include "THbookTree.h"
14 #include "TBrowser.h"
15 
16 ClassImp(THbookKey);
17 
18 /** \class THbookKey
19  \ingroup Hist
20  \brief HBOOK Key
21 */
22 
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 ///constructor
26 
27 THbookKey::THbookKey(Int_t id, THbookFile *file)
28 {
29  fDirectory = file;
30  fID = id;
31  char name[10];
32  snprintf(name,10,"h%d",id);
33  SetName(name);
34 }
35 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 
39 THbookKey::~THbookKey()
40 {
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Read object from disk and call its Browse() method.
45 /// If object with same name already exist in memory delete it (like
46 /// TDirectory::Get() is doing), except when the key references a
47 /// folder in which case we don't want to re-read the folder object
48 /// since it might contain new objects not yet saved.
49 
50 void THbookKey::Browse(TBrowser *b)
51 {
52  fDirectory->cd();
53 
54  TObject *obj = fDirectory->GetList()->FindObject(GetName());
55  if (obj && !obj->IsFolder()) {
56  if (obj->InheritsFrom(TCollection::Class()))
57  obj->Delete(); // delete also collection elements
58  delete obj;
59  obj = 0;
60  }
61 
62  if (!obj)
63  obj = fDirectory->Get(fID);
64 
65  if (b && obj) {
66  obj->Browse(b);
67  b->SetRefreshFlag(kTRUE);
68  }
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 ///an hbook key is not a folder
73 
74 Bool_t THbookKey::IsFolder() const
75 {
76  Bool_t ret = kFALSE;
77 
78 
79  return( ret );
80 }