00001 /***************************************************************************** 00002 * Project: RooFit * 00003 * Package: RooFitCore * 00004 * @(#)root/roofitcore:$Id: RooDirItem.cxx 25184 2008-08-20 13:59:55Z wouter $ 00005 * Authors: * 00006 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * 00007 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * 00008 * * 00009 * Copyright (c) 2000-2005, Regents of the University of California * 00010 * and Stanford University. All rights reserved. * 00011 * * 00012 * Redistribution and use in source and binary forms, * 00013 * with or without modification, are permitted according to the terms * 00014 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * 00015 *****************************************************************************/ 00016 00017 ////////////////////////////////////////////////////////////////////////////// 00018 // 00019 // BEGIN_HTML 00020 // RooDirItem is a utility base class for RooFit objects that are to be attached 00021 // to ROOT directories. Concrete classes inherit the appendToDir and removeToDir 00022 // methods that can be used to safely attach and detach one self from a TDirectory 00023 // END_HTML 00024 // 00025 00026 #include "RooFit.h" 00027 00028 #include "Riostream.h" 00029 #include "Riostream.h" 00030 #include "TROOT.h" 00031 #include "TList.h" 00032 #include "TDirectoryFile.h" 00033 #include "TString.h" 00034 #include "RooDirItem.h" 00035 00036 ClassImp(RooDirItem) ; 00037 00038 00039 //_____________________________________________________________________________ 00040 RooDirItem::RooDirItem() : _dir(0) 00041 { 00042 // Default constructor 00043 } 00044 00045 00046 //_____________________________________________________________________________ 00047 RooDirItem::RooDirItem(const RooDirItem& /*other*/) : _dir(0) 00048 { 00049 // Copy constructor 00050 } 00051 00052 00053 00054 //_____________________________________________________________________________ 00055 RooDirItem::~RooDirItem() 00056 { 00057 // Destructor 00058 } 00059 00060 00061 00062 //_____________________________________________________________________________ 00063 void RooDirItem::removeFromDir(TObject* obj) 00064 { 00065 // Remove object from directory it was added to 00066 00067 if (_dir) { 00068 if (!_dir->TestBit(TDirectoryFile::kCloseDirectory)) 00069 _dir->GetList()->Remove(obj) ; 00070 } 00071 } 00072 00073 00074 00075 //_____________________________________________________________________________ 00076 void RooDirItem::appendToDir(TObject* obj, Bool_t forceMemoryResident) 00077 { 00078 // Append object to directory. If forceMemoryResident is 00079 // true, force addition to ROOT memory directory if that 00080 // is not the current directory 00081 00082 if (forceMemoryResident) { 00083 // Append self forcibly to memory directory 00084 00085 TString pwd(gDirectory->GetPath()) ; 00086 TString memDir(gROOT->GetName()) ; 00087 memDir.Append(":/") ; 00088 Bool_t notInMemNow= (pwd!=memDir) ; 00089 00090 //cout << "RooDirItem::appendToDir pwd=" << pwd << " memDir=" << memDir << endl ; 00091 00092 if (notInMemNow) { 00093 gDirectory->cd(memDir) ; 00094 } 00095 00096 _dir = gDirectory ; 00097 gDirectory->Append(obj) ; 00098 00099 if (notInMemNow) { 00100 gDirectory->cd(pwd) ; 00101 } 00102 00103 } else { 00104 // Append self to present gDirectory 00105 _dir = gDirectory ; 00106 gDirectory->Append(obj) ; 00107 } 00108 } 00109