Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 \file RooDirItem.cxx
19 \class RooDirItem
20 \ingroup Roofitcore
21 
22 RooDirItem is a utility base class for RooFit objects that are to be attached
23 to ROOT directories. Concrete classes inherit the appendToDir and removeToDir
24 methods that can be used to safely attach and detach one self from a TDirectory
25 **/
26 
27 #include "RooFit.h"
28 
29 #include "Riostream.h"
30 #include "Riostream.h"
31 #include "TROOT.h"
32 #include "TList.h"
33 #include "TDirectoryFile.h"
34 #include "TString.h"
35 #include "RooDirItem.h"
36 
37 using namespace std;
38 
39 ClassImp(RooDirItem); ;
40 
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Default constructor
44 
45 RooDirItem::RooDirItem() : _dir(0)
46 {
47 }
48 
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Copy constructor
52 
53 RooDirItem::RooDirItem(const RooDirItem& /*other*/) : _dir(0)
54 {
55 }
56 
57 
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Destructor
61 
62 RooDirItem::~RooDirItem()
63 {
64 }
65 
66 
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Remove object from directory it was added to
70 
71 void RooDirItem::removeFromDir(TObject* obj)
72 {
73  if (_dir) {
74  if (!_dir->TestBit(TDirectoryFile::kCloseDirectory))
75  _dir->GetList()->Remove(obj) ;
76  }
77 }
78 
79 
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Append object to directory. If forceMemoryResident is
83 /// true, force addition to ROOT memory directory if that
84 /// is not the current directory
85 
86 void RooDirItem::appendToDir(TObject* obj, Bool_t forceMemoryResident)
87 {
88  if (forceMemoryResident) {
89  // Append self forcibly to memory directory
90 
91  TString pwd(gDirectory->GetPath()) ;
92  TString memDir(gROOT->GetName()) ;
93  memDir.Append(":/") ;
94  Bool_t notInMemNow= (pwd!=memDir) ;
95 
96  //cout << "RooDirItem::appendToDir pwd=" << pwd << " memDir=" << memDir << endl ;
97 
98  if (notInMemNow) {
99  gDirectory->cd(memDir) ;
100  }
101 
102  _dir = gDirectory ;
103  gDirectory->Append(obj) ;
104 
105  if (notInMemNow) {
106  gDirectory->cd(pwd) ;
107  }
108 
109  } else {
110  // Append self to present gDirectory
111  _dir = gDirectory ;
112  gDirectory->Append(obj) ;
113  }
114 }
115