00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Riostream.h"
00013 #include "Strlen.h"
00014 #include "TDirectory.h"
00015 #include "TClassTable.h"
00016 #include "TInterpreter.h"
00017 #include "THashList.h"
00018 #include "TBrowser.h"
00019 #include "TROOT.h"
00020 #include "TError.h"
00021 #include "TClass.h"
00022 #include "TRegexp.h"
00023 #include "TSystem.h"
00024 #include "TVirtualMutex.h"
00025
00026 TDirectory *gDirectory;
00027 Bool_t TDirectory::fgAddDirectory = kTRUE;
00028
00029 const Int_t kMaxLen = 2048;
00030
00031
00032
00033
00034
00035
00036
00037
00038 ClassImp(TDirectory)
00039
00040
00041
00042
00043
00044 TDirectory::TDirectory() : TNamed(), fMother(0),fList(0),fContext(0)
00045 {
00046
00047
00048 }
00049
00050
00051 TDirectory::TDirectory(const char *name, const char *title, Option_t * , TDirectory* initMotherDir)
00052 : TNamed(name, title), fMother(0), fList(0),fContext(0)
00053 {
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 if (initMotherDir==0) initMotherDir = gDirectory;
00067
00068 if (strchr(name,'/')) {
00069 ::Error("TDirectory::TDirectory","directory name (%s) cannot contain a slash", name);
00070 gDirectory = 0;
00071 return;
00072 }
00073 if (strlen(GetName()) == 0) {
00074 ::Error("TDirectory::TDirectory","directory name cannot be \"\"");
00075 gDirectory = 0;
00076 return;
00077 }
00078
00079 Build(initMotherDir ? initMotherDir->GetFile() : 0, initMotherDir);
00080
00081 R__LOCKGUARD2(gROOTMutex);
00082 }
00083
00084
00085 TDirectory::TDirectory(const TDirectory &directory) : TNamed(directory)
00086 {
00087
00088 directory.Copy(*this);
00089 }
00090
00091
00092 TDirectory::~TDirectory()
00093 {
00094
00095
00096 if (!gROOT) {
00097 delete fList;
00098 return;
00099 }
00100
00101 if (fList) {
00102 fList->Delete("slow");
00103 SafeDelete(fList);
00104 }
00105
00106 CleanTargets();
00107
00108 TDirectory* mom = GetMotherDir();
00109
00110 if (mom) {
00111 mom->Remove(this);
00112 }
00113
00114 if (gDebug) {
00115 Info("~TDirectory", "dtor called for %s", GetName());
00116 }
00117 }
00118
00119
00120 void TDirectory::AddDirectory(Bool_t add)
00121 {
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 fgAddDirectory = add;
00136 }
00137
00138
00139 Bool_t TDirectory::AddDirectoryStatus()
00140 {
00141
00142 return fgAddDirectory;
00143 }
00144
00145
00146 void TDirectory::Append(TObject *obj, Bool_t replace )
00147 {
00148
00149
00150
00151
00152
00153 if (obj == 0 || fList == 0) return;
00154
00155 if (replace && obj->GetName() && obj->GetName()[0]) {
00156 TObject *old;
00157 while (0!=(old = GetList()->FindObject(obj->GetName()))) {
00158 Warning("Append","Replacing existing %s: %s (Potential memory leak).",
00159 obj->IsA()->GetName(),obj->GetName());
00160 ROOT::DirAutoAdd_t func = old->IsA()->GetDirectoryAutoAdd();
00161 if (func) {
00162 func(old,0);
00163 } else {
00164 Remove(old);
00165 }
00166 }
00167 }
00168
00169 fList->Add(obj);
00170 obj->SetBit(kMustCleanup);
00171 }
00172
00173
00174 void TDirectory::Browse(TBrowser *b)
00175 {
00176
00177
00178 if (b) {
00179 TObject *obj = 0;
00180 TIter nextin(fList);
00181
00182 cd();
00183
00184
00185 while ((obj = nextin())) {
00186 b->Add(obj, obj->GetName());
00187 }
00188 }
00189 }
00190
00191
00192 void TDirectory::Build(TFile* , TDirectory* motherDir)
00193 {
00194
00195
00196
00197
00198
00199
00200
00201 if (motherDir && strlen(GetName()) != 0) motherDir->Append(this);
00202
00203 fList = new THashList(100,50);
00204 fMother = motherDir;
00205 SetBit(kCanDelete);
00206 }
00207
00208
00209 void TDirectory::CleanTargets()
00210 {
00211
00212
00213 while (fContext) {
00214 fContext->fDirectory = 0;
00215 fContext = fContext->fNext;
00216 }
00217
00218 if (gDirectory == this) {
00219 TDirectory *cursav = GetMotherDir();
00220 if (cursav && cursav != this) {
00221 cursav->cd();
00222 } else {
00223 if (this == gROOT) {
00224 gDirectory = 0;
00225 } else {
00226 gROOT->cd();
00227 }
00228 }
00229 }
00230 }
00231
00232
00233 TObject *TDirectory::CloneObject(const TObject *obj, Bool_t autoadd )
00234 {
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 char *pobj = (char*)obj->IsA()->New();
00246 if (!pobj) return 0;
00247
00248 Int_t baseOffset = obj->IsA()->GetBaseClassOffset(TObject::Class());
00249 if (baseOffset==-1) {
00250
00251
00252
00253 Fatal("CloneObject","Incorrect detection of the inheritance from TObject for class %s.\n",
00254 obj->IsA()->GetName());
00255 }
00256 TObject *newobj = (TObject*)(pobj+baseOffset);
00257
00258
00259
00260
00261 TBuffer *buffer = (TBuffer*)gROOT->ProcessLine(Form("new TBufferFile(%d,10000);",TBuffer::kWrite));
00262 if (!buffer) return 0;
00263 buffer->MapObject(obj);
00264 const_cast<TObject*>(obj)->Streamer(*buffer);
00265
00266
00267 buffer->SetReadMode();
00268 buffer->ResetMap();
00269 buffer->SetBufferOffset(0);
00270 buffer->MapObject(newobj);
00271 newobj->Streamer(*buffer);
00272 newobj->ResetBit(kIsReferenced);
00273 newobj->ResetBit(kCanDelete);
00274
00275 delete buffer;
00276 if (autoadd) {
00277 ROOT::DirAutoAdd_t func = obj->IsA()->GetDirectoryAutoAdd();
00278 if (func) {
00279 func(newobj,this);
00280 }
00281 }
00282 return newobj;
00283 }
00284
00285
00286
00287 TDirectory *TDirectory::GetDirectory(const char *apath,
00288 Bool_t printError, const char *funcname)
00289 {
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 Int_t nch = 0;
00302 if (apath) nch = strlen(apath);
00303 if (!nch) {
00304 return this;
00305 }
00306
00307 if (funcname==0 || strlen(funcname)==0) funcname = "GetDirectory";
00308
00309 TDirectory *result = this;
00310
00311 char *path = new char[nch+1]; path[0] = 0;
00312 if (nch) strlcpy(path,apath,nch+1);
00313 char *s = (char*)strrchr(path, ':');
00314 if (s) {
00315 *s = '\0';
00316 R__LOCKGUARD2(gROOTMutex);
00317 TDirectory *f = (TDirectory *)gROOT->GetListOfFiles()->FindObject(path);
00318 if (!f && !strcmp(gROOT->GetName(), path)) f = gROOT;
00319 if (s) *s = ':';
00320 if (f) {
00321 result = f;
00322 if (s && *(s+1)) result = f->GetDirectory(s+1,printError,funcname);
00323 delete [] path; return result;
00324 } else {
00325 if (printError) Error(funcname, "No such file %s", path);
00326 delete [] path; return 0;
00327 }
00328 }
00329
00330
00331 if (path[0] == '/') {
00332 TDirectory *td = gROOT;
00333 result = td->GetDirectory(path+1,printError,funcname);
00334 delete [] path; return result;
00335 }
00336
00337 TObject *obj;
00338 char *slash = (char*)strchr(path,'/');
00339 if (!slash) {
00340 if (!strcmp(path, "..")) {
00341 result = GetMotherDir();
00342 delete [] path; return result;
00343 }
00344 obj = Get(path);
00345 if (!obj) {
00346 if (printError) Error(funcname,"Unknown directory %s", path);
00347 delete [] path; return 0;
00348 }
00349
00350
00351 if (!obj->InheritsFrom(TDirectory::Class())) {
00352 if (printError) Error(funcname,"Object %s is not a directory", path);
00353 delete [] path; return 0;
00354 }
00355 delete [] path; return (TDirectory*)obj;
00356 }
00357
00358 TString subdir(path);
00359 slash = (char*)strchr(subdir.Data(),'/');
00360 *slash = 0;
00361
00362 if (!strcmp(subdir, "..")) {
00363 TDirectory* mom = GetMotherDir();
00364 if (mom)
00365 result = mom->GetDirectory(slash+1,printError,funcname);
00366 delete [] path; return result;
00367 }
00368 obj = Get(subdir);
00369 if (!obj) {
00370 if (printError) Error(funcname,"Unknown directory %s", subdir.Data());
00371 delete [] path; return 0;
00372 }
00373
00374
00375 if (!obj->InheritsFrom(TDirectory::Class())) {
00376 if (printError) Error(funcname,"Object %s is not a directory", subdir.Data());
00377 delete [] path; return 0;
00378 }
00379 result = ((TDirectory*)obj)->GetDirectory(slash+1,printError,funcname);
00380 delete [] path; return result;
00381 }
00382
00383
00384 Bool_t TDirectory::cd(const char *path)
00385 {
00386
00387
00388
00389
00390
00391
00392
00393 return cd1(path);
00394 }
00395
00396
00397 Bool_t TDirectory::cd1(const char *apath)
00398 {
00399
00400
00401
00402
00403
00404
00405
00406 Int_t nch = 0;
00407 if (apath) nch = strlen(apath);
00408 if (!nch) {
00409 gDirectory = this;
00410 return kTRUE;
00411 }
00412
00413 TDirectory *where = GetDirectory(apath,kTRUE,"cd");
00414 if (where) {
00415 where->cd();
00416 return kTRUE;
00417 }
00418 return kFALSE;
00419 }
00420
00421
00422 Bool_t TDirectory::Cd(const char *path)
00423 {
00424
00425
00426
00427
00428
00429
00430 return Cd1(path);
00431 }
00432
00433
00434 Bool_t TDirectory::Cd1(const char *apath)
00435 {
00436
00437
00438
00439
00440
00441
00442 Int_t nch = 0;
00443 if (apath) nch = strlen(apath);
00444 if (!nch) return kTRUE;
00445
00446 TDirectory *where = gDirectory->GetDirectory(apath,kTRUE,"Cd");
00447 if (where) {
00448 where->cd();
00449 return kTRUE;
00450 }
00451 return kFALSE;
00452 }
00453
00454
00455 void TDirectory::Clear(Option_t *)
00456 {
00457
00458
00459
00460 if (fList) fList->Clear();
00461
00462 }
00463
00464
00465 void TDirectory::Close(Option_t *)
00466 {
00467
00468
00469 if (!fList) {
00470 return;
00471 }
00472
00473
00474 Save();
00475
00476 Bool_t fast = kTRUE;
00477 TObjLink *lnk = fList->FirstLink();
00478 while (lnk) {
00479 if (lnk->GetObject()->IsA() == TDirectory::Class()) {fast = kFALSE;break;}
00480 lnk = lnk->Next();
00481 }
00482
00483
00484
00485
00486
00487 if (fast) fList->Delete();
00488 else fList->Delete("slow");
00489
00490 CleanTargets();
00491 }
00492
00493
00494 void TDirectory::DeleteAll(Option_t *)
00495 {
00496
00497
00498 fList->Delete("slow");
00499 }
00500
00501
00502 void TDirectory::Delete(const char *namecycle)
00503 {
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526 if (gDebug)
00527 Info("Delete","Call for this = %s namecycle = %s",
00528 GetName(), (namecycle ? namecycle : "null"));
00529
00530 TDirectory::TContext ctxt(gDirectory, this);
00531 Short_t cycle;
00532 char name[kMaxLen];
00533 DecodeNameCycle(namecycle, name, cycle);
00534
00535 Int_t deleteall = 0;
00536 Int_t deletetree = 0;
00537 if(strcmp(name,"*") == 0) deleteall = 1;
00538 if(strcmp(name,"*T") == 0){ deleteall = 1; deletetree = 1;}
00539 if(strcmp(name,"T*") == 0){ deleteall = 1; deletetree = 1;}
00540 if(namecycle==0 || strlen(namecycle) == 0){ deleteall = 1; deletetree = 1;}
00541 TRegexp re(name,kTRUE);
00542 TString s;
00543 Int_t deleteOK = 0;
00544
00545
00546
00547 if (cycle >= 9999 ) {
00548 TNamed *idcur;
00549 TIter next(fList);
00550 while ((idcur = (TNamed *) next())) {
00551 deleteOK = 0;
00552 s = idcur->GetName();
00553 if (deleteall || s.Index(re) != kNPOS) {
00554 deleteOK = 1;
00555 if (idcur->IsA() == TDirectory::Class()) {
00556 deleteOK = 2;
00557 if (!deletetree && deleteall) deleteOK = 0;
00558 }
00559 }
00560 if (deleteOK != 0) {
00561 fList->Remove(idcur);
00562 if (deleteOK==2) {
00563
00564 if (deletetree)
00565 ((TDirectory*) idcur)->ReadAll("dirs");
00566 idcur->Delete(deletetree ? "T*;*" : "*");
00567 delete idcur;
00568 } else
00569 idcur->Delete(name);
00570 }
00571 }
00572 }
00573 }
00574
00575
00576 void TDirectory::Draw(Option_t *option)
00577 {
00578
00579
00580
00581
00582
00583 fList->R__FOR_EACH(TObject,Draw)(option);
00584 }
00585
00586
00587 TObject *TDirectory::FindObject(const TObject *obj) const
00588 {
00589
00590
00591 return fList->FindObject(obj);
00592 }
00593
00594
00595 TObject *TDirectory::FindObject(const char *name) const
00596 {
00597
00598
00599 return fList->FindObject(name);
00600 }
00601
00602
00603 TObject *TDirectory::FindObjectAny(const char *aname) const
00604 {
00605
00606
00607
00608
00609
00610
00611
00612 TObject *obj = fList->FindObject(aname);
00613 if (obj) return obj;
00614
00615
00616 TIter next(fList);
00617 while( (obj = next()) ) {
00618 if (obj->IsA()->InheritsFrom(TDirectory::Class())) {
00619 TDirectory* subdir = static_cast<TDirectory*>(obj);
00620 TObject *subobj = subdir->TDirectory::FindObjectAny(aname);
00621 if (subobj) {
00622 return subobj;
00623 }
00624 }
00625 }
00626 return 0;
00627 }
00628
00629
00630 TObject *TDirectory::Get(const char *namecycle)
00631 {
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672 Short_t cycle;
00673 char name[kMaxLen];
00674
00675 DecodeNameCycle(namecycle, name, cycle);
00676 char *namobj = name;
00677 Int_t nch = strlen(name);
00678 for (Int_t i = nch-1; i > 0; i--) {
00679 if (name[i] == '/') {
00680 name[i] = 0;
00681 TDirectory* dirToSearch=GetDirectory(name);
00682 namobj = name + i + 1;
00683 name[i] = '/';
00684 return dirToSearch?dirToSearch->Get(namobj):0;
00685 }
00686 }
00687
00688
00689
00690 TObject *idcur = fList->FindObject(namobj);
00691 if (idcur) {
00692 if (idcur==this && strlen(namobj)!=0) {
00693
00694
00695
00696 idcur = 0;
00697 } else if (cycle == 9999) {
00698 return idcur;
00699 } else {
00700 if (idcur->InheritsFrom(TCollection::Class()))
00701 idcur->Delete();
00702 delete idcur;
00703 idcur = 0;
00704 }
00705 }
00706 return idcur;
00707 }
00708
00709
00710 void *TDirectory::GetObjectUnchecked(const char *namecycle)
00711 {
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724 return GetObjectChecked(namecycle,(TClass*)0);
00725 }
00726
00727
00728 void *TDirectory::GetObjectChecked(const char *namecycle, const char* classname)
00729 {
00730
00731
00732 return GetObjectChecked(namecycle,TClass::GetClass(classname));
00733 }
00734
00735
00736
00737 void *TDirectory::GetObjectChecked(const char *namecycle, const TClass* expectedClass)
00738 {
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757 Short_t cycle;
00758 char name[kMaxLen];
00759
00760 DecodeNameCycle(namecycle, name, cycle);
00761 char *namobj = name;
00762 Int_t nch = strlen(name);
00763 for (Int_t i = nch-1; i > 0; i--) {
00764 if (name[i] == '/') {
00765 name[i] = 0;
00766 TDirectory* dirToSearch=GetDirectory(name);
00767 namobj = name + i + 1;
00768 name[i] = '/';
00769 if (dirToSearch) {
00770 return dirToSearch->GetObjectChecked(namobj, expectedClass);
00771 } else {
00772 return 0;
00773 }
00774 }
00775 }
00776
00777
00778
00779 if (expectedClass==0 || expectedClass->InheritsFrom(TObject::Class())) {
00780 TObject *objcur = fList->FindObject(namobj);
00781 if (objcur) {
00782 if (objcur==this && strlen(namobj)!=0) {
00783
00784
00785
00786 objcur = 0;
00787 } else if (cycle == 9999) {
00788
00789 if (expectedClass && objcur->IsA()->GetBaseClassOffset(expectedClass) == -1) return 0;
00790 else return objcur;
00791 } else {
00792 if (objcur->InheritsFrom(TCollection::Class()))
00793 objcur->Delete();
00794 delete objcur;
00795 objcur = 0;
00796 }
00797 }
00798 }
00799
00800 return 0;
00801 }
00802
00803
00804 const char *TDirectory::GetPathStatic() const
00805 {
00806
00807
00808
00809 static char *path = 0;
00810 const int kMAXDEPTH = 128;
00811 const TDirectory *d[kMAXDEPTH];
00812 const TDirectory *cur = this;
00813 int depth = 0, len = 0;
00814
00815 d[depth++] = cur;
00816 len = strlen(cur->GetName()) + 1;
00817
00818 while (cur->fMother && depth < kMAXDEPTH) {
00819 cur = (TDirectory *)cur->fMother;
00820 d[depth++] = cur;
00821 len += strlen(cur->GetName()) + 1;
00822 }
00823
00824 if (path) delete [] path;
00825 path = new char[len+2];
00826
00827 for (int i = depth-1; i >= 0; i--) {
00828 if (i == depth-1) {
00829 strlcpy(path, d[i]->GetName(),len+2);
00830 strlcat(path, ":",len+2);
00831 if (i == 0) strlcat(path, "/",len+2);
00832 } else {
00833 strlcat(path, "/",len+2);
00834 strlcat(path, d[i]->GetName(),len+2);
00835 }
00836 }
00837
00838 return path;
00839 }
00840
00841
00842 const char *TDirectory::GetPath() const
00843 {
00844
00845
00846
00847
00848 TString* buf = &(const_cast<TDirectory*>(this)->fPathBuffer);
00849
00850 FillFullPath(*buf);
00851 if (GetMotherDir()==0)
00852 buf->Append("/");
00853
00854 return buf->Data();
00855 }
00856
00857
00858 void TDirectory::FillFullPath(TString& buf) const
00859 {
00860
00861
00862 TDirectory* mom = GetMotherDir();
00863 if (mom!=0) {
00864 mom->FillFullPath(buf);
00865 buf += "/";
00866 buf += GetName();
00867 } else {
00868 buf = GetName();
00869 buf +=":";
00870 }
00871 }
00872
00873
00874 TDirectory *TDirectory::mkdir(const char *name, const char *title)
00875 {
00876
00877
00878
00879
00880
00881
00882 if (!name || !title || !strlen(name)) return 0;
00883 if (!strlen(title)) title = name;
00884 TDirectory *newdir = 0;
00885 if (const char *slash = strchr(name,'/')) {
00886 Long_t size = Long_t(slash-name);
00887 char *workname = new char[size+1];
00888 strncpy(workname, name, size);
00889 workname[size] = 0;
00890 TDirectory *tmpdir = mkdir(workname,title);
00891 if (!tmpdir) return 0;
00892 if (!newdir) newdir = tmpdir;
00893 tmpdir->mkdir(slash+1);
00894 delete[] workname;
00895 return newdir;
00896 }
00897
00898 TDirectory::TContext ctxt(this);
00899
00900 newdir = new TDirectory(name, title, "", this);
00901
00902 return newdir;
00903 }
00904
00905
00906 void TDirectory::ls(Option_t *option) const
00907 {
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919 TROOT::IndentLevel();
00920 TROOT::IncreaseDirLevel();
00921
00922 TString opta = option;
00923 TString opt = opta.Strip(TString::kBoth);
00924 Bool_t memobj = kTRUE;
00925 Bool_t diskobj = kTRUE;
00926 TString reg = "*";
00927 if (opt.BeginsWith("-m")) {
00928 diskobj = kFALSE;
00929 if (opt.Length() > 2)
00930 reg = opt(2,opt.Length());
00931 } else if (opt.BeginsWith("-d")) {
00932 memobj = kFALSE;
00933 if (opt.Length() > 2)
00934 reg = opt(2,opt.Length());
00935 } else if (!opt.IsNull())
00936 reg = opt;
00937
00938 TRegexp re(reg, kTRUE);
00939
00940 if (memobj) {
00941 TObject *obj;
00942 TIter nextobj(fList);
00943 while ((obj = (TObject *) nextobj())) {
00944 TString s = obj->GetName();
00945 if (s.Index(re) == kNPOS) continue;
00946 obj->ls(option);
00947 }
00948 }
00949 TROOT::DecreaseDirLevel();
00950 }
00951
00952
00953 void TDirectory::Paint(Option_t *option)
00954 {
00955
00956
00957 fList->R__FOR_EACH(TObject,Paint)(option);
00958 }
00959
00960
00961 void TDirectory::Print(Option_t *option) const
00962 {
00963
00964
00965 fList->R__FOR_EACH(TObject,Print)(option);
00966 }
00967
00968
00969 void TDirectory::pwd() const
00970 {
00971
00972
00973 Printf("%s", GetPath());
00974 }
00975
00976
00977 void TDirectory::RecursiveRemove(TObject *obj)
00978 {
00979
00980
00981 fList->RecursiveRemove(obj);
00982 }
00983
00984
00985 TObject *TDirectory::Remove(TObject* obj)
00986 {
00987
00988
00989 TObject *p = 0;
00990 if (fList) {
00991 p = fList->Remove(obj);
00992 }
00993 return p;
00994 }
00995
00996
00997 void TDirectory::rmdir(const char *name)
00998 {
00999
01000
01001
01002
01003
01004 if ((name==0) || (*name==0)) return;
01005
01006 TString mask(name);
01007 mask+=";*";
01008 Delete(mask);
01009 }
01010
01011
01012 Int_t TDirectory::SaveObjectAs(const TObject *obj, const char *filename, Option_t *option) const
01013 {
01014
01015
01016
01017
01018
01019
01020
01021 if (!obj) return 0;
01022 if (!gDirectory) return 0;
01023 TDirectory *dirsav = gDirectory;
01024 TString fname = filename;
01025 if (!filename || strlen(filename) == 0) {
01026 fname = Form("%s.root",obj->GetName());
01027 }
01028 const char *cmd = Form("TFile::Open(\"%s\",\"recreate\");",fname.Data());
01029 TDirectory *local = (TDirectory*)gROOT->ProcessLine(cmd);
01030 if (!local) return 0;
01031 Int_t nbytes = obj->Write();
01032 delete local;
01033 if (dirsav) dirsav->cd();
01034 TString opt = option;
01035 opt.ToLower();
01036 if (!opt.Contains("q")) {
01037 if (!gSystem->AccessPathName(fname.Data())) obj->Info("SaveAs", "ROOT file %s has been created", fname.Data());
01038 }
01039 return nbytes;
01040 }
01041
01042
01043 void TDirectory::SetName(const char* newname)
01044 {
01045
01046
01047
01048
01049
01050
01051
01052 TNamed::SetName(newname);
01053 }
01054
01055
01056 void TDirectory::EncodeNameCycle(char *buffer, const char *name, Short_t cycle)
01057 {
01058
01059
01060 if (cycle == 9999)
01061 strcpy(buffer, name);
01062 else
01063 sprintf(buffer, "%s;%d", name, cycle);
01064 }
01065
01066
01067 void TDirectory::DecodeNameCycle(const char *buffer, char *name, Short_t &cycle)
01068 {
01069
01070
01071 cycle = 9999;
01072 Int_t nch = buffer ? strlen(buffer) : 0;
01073 for (Int_t i = 0; i < nch; i++) {
01074 if (buffer[i] != ';')
01075 name[i] = buffer[i];
01076 else {
01077 name[i] = 0;
01078 if (i < nch-1 )
01079 if (buffer[i+1] == '*') {
01080 cycle = 10000;
01081 return;
01082 }
01083 sscanf(buffer+i+1, "%hd", &cycle);
01084 return;
01085 }
01086 }
01087 name[nch] = 0;
01088 }
01089
01090
01091 void TDirectory::RegisterContext(TContext *ctxt) {
01092
01093
01094 R__LOCKGUARD2(gROOTMutex);
01095 if (fContext) {
01096 TContext *current = fContext;
01097 while(current->fNext) {
01098 current = current->fNext;
01099 }
01100 current->fNext = ctxt;
01101 ctxt->fPrevious = current;
01102 } else {
01103 fContext = ctxt;
01104 }
01105 }
01106
01107
01108 Int_t TDirectory::WriteTObject(const TObject *obj, const char *name, Option_t * , Int_t )
01109 {
01110
01111
01112 const char *objname = "no name specified";
01113 if (name) objname = name;
01114 else if (obj) objname = obj->GetName();
01115 Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.",GetName(),objname);
01116 return 0;
01117 }
01118
01119
01120 void TDirectory::UnregisterContext(TContext *ctxt) {
01121
01122
01123 R__LOCKGUARD2(gROOTMutex);
01124 if (ctxt==fContext) {
01125 fContext = ctxt->fNext;
01126 if (fContext) fContext->fPrevious = 0;
01127 ctxt->fPrevious = ctxt->fNext = 0;
01128 } else {
01129 TContext *next = ctxt->fNext;
01130 ctxt->fPrevious->fNext = next;
01131 if (next) next->fPrevious = ctxt->fPrevious;
01132 ctxt->fPrevious = ctxt->fNext = 0;
01133 }
01134 }
01135
01136
01137 void TDirectory::TContext::CdNull()
01138 {
01139
01140
01141
01142
01143 gDirectory = 0;
01144 }