Logo ROOT  
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\file RooDirItem.cxx
19\class RooDirItem
20\ingroup Roofitcore
21
22RooDirItem is a utility base class for RooFit objects that are to be attached
23to ROOT directories. Concrete classes inherit the appendToDir and removeToDir
24methods 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
37using namespace std;
38
40
41
42////////////////////////////////////////////////////////////////////////////////
43/// Default constructor
44
46{
47}
48
49
50////////////////////////////////////////////////////////////////////////////////
51/// Copy constructor
52
53RooDirItem::RooDirItem(const RooDirItem& /*other*/) : _dir(0)
54{
55}
56
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// Destructor
61
63{
64}
65
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// Remove object from directory it was added to
70
72{
73 if (_dir) {
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
86void 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
bool Bool_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:365
#define gDirectory
Definition: TDirectory.h:223
#define gROOT
Definition: TROOT.h:415
RooDirItem is a utility base class for RooFit objects that are to be attached to ROOT directories.
Definition: RooDirItem.h:22
virtual ~RooDirItem()
Destructor.
Definition: RooDirItem.cxx:62
void appendToDir(TObject *obj, Bool_t forceMemoryResident=kFALSE)
Append object to directory.
Definition: RooDirItem.cxx:86
RooDirItem()
Default constructor.
Definition: RooDirItem.cxx:45
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
Definition: RooDirItem.cxx:71
TDirectory * _dir
Definition: RooDirItem.h:33
virtual TList * GetList() const
Definition: TDirectory.h:159
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:819
Mother of all ROOT objects.
Definition: TObject.h:37
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
Basic string class.
Definition: TString.h:131
TString & Append(const char *cs)
Definition: TString.h:559