ROOT  6.06/09
Reference Guide
RooDirItem.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 //////////////////////////////////////////////////////////////////////////////
18 //
19 // BEGIN_HTML
20 // RooDirItem is a utility base class for RooFit objects that are to be attached
21 // to ROOT directories. Concrete classes inherit the appendToDir and removeToDir
22 // methods that can be used to safely attach and detach one self from a TDirectory
23 // END_HTML
24 //
25 
26 #include "RooFit.h"
27 
28 #include "Riostream.h"
29 #include "Riostream.h"
30 #include "TROOT.h"
31 #include "TList.h"
32 #include "TDirectoryFile.h"
33 #include "TString.h"
34 #include "RooDirItem.h"
35 
36 using namespace std;
37 
39 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Default constructor
43 
45 {
46 }
47 
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Copy constructor
51 
52 RooDirItem::RooDirItem(const RooDirItem& /*other*/) : _dir(0)
53 {
54 }
55 
56 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Destructor
60 
62 {
63 }
64 
65 
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Remove object from directory it was added to
69 
71 {
72  if (_dir) {
74  _dir->GetList()->Remove(obj) ;
75  }
76 }
77 
78 
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Append object to directory. If forceMemoryResident is
82 /// true, force addition to ROOT memory directory if that
83 /// is not the current directory
84 
85 void RooDirItem::appendToDir(TObject* obj, Bool_t forceMemoryResident)
86 {
87  if (forceMemoryResident) {
88  // Append self forcibly to memory directory
89 
90  TString pwd(gDirectory->GetPath()) ;
91  TString memDir(gROOT->GetName()) ;
92  memDir.Append(":/") ;
93  Bool_t notInMemNow= (pwd!=memDir) ;
94 
95  //cout << "RooDirItem::appendToDir pwd=" << pwd << " memDir=" << memDir << endl ;
96 
97  if (notInMemNow) {
98  gDirectory->cd(memDir) ;
99  }
100 
101  _dir = gDirectory ;
102  gDirectory->Append(obj) ;
103 
104  if (notInMemNow) {
105  gDirectory->cd(pwd) ;
106  }
107 
108  } else {
109  // Append self to present gDirectory
110  _dir = gDirectory ;
111  gDirectory->Append(obj) ;
112  }
113 }
114 
#define gDirectory
Definition: TDirectory.h:218
virtual TList * GetList() const
Definition: TDirectory.h:154
#define gROOT
Definition: TROOT.h:340
Basic string class.
Definition: TString.h:137
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
virtual ~RooDirItem()
Destructor.
Definition: RooDirItem.cxx:61
RooDirItem()
Default constructor.
Definition: RooDirItem.cxx:44
void appendToDir(TObject *obj, Bool_t forceMemoryResident=kFALSE)
Append object to directory.
Definition: RooDirItem.cxx:85
TString & Append(const char *cs)
Definition: TString.h:492
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:674
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
Definition: RooDirItem.cxx:70
TDirectory * _dir
Definition: RooDirItem.h:33
ClassImp(RooDirItem)
Mother of all ROOT objects.
Definition: TObject.h:58
TObject * obj