12 #include "Riostream.h"
14 #include "TDataSetIter.h"
25 # define strcasecmp(arg1,arg2) stricmp(arg1,arg2)
49 TDataSetIter::TDataSetIter(
TDataSet *link, Bool_t dir)
51 fWorkingDataSet= fRootDataSet =link;
52 fMaxDepth = fDepth =1;
53 fDataSet= fgNullDataSet ;
54 fNext = link ?
new TIter(link->GetCollection() ,dir):0;
55 for(UInt_t i = 0; i <
sizeof(fNextSet) /
sizeof(TIter*); ++i) {
56 fNextSet[i] = (TIter*)0;
63 TDataSetIter::TDataSetIter(
TDataSet *link, Int_t depth, Bool_t dir)
65 fRootDataSet = fWorkingDataSet = link;
68 fDataSet = fgNullDataSet;
69 fNext = (link)?
new TIter(link->GetCollection() ,dir):0;
75 for(UInt_t i = 0; i <
sizeof(fNextSet) /
sizeof(TIter*); ++i) {
76 fNextSet[i] = (TIter*)0;
80 if (fMaxDepth > 100) fMaxDepth = 100;
93 for (Int_t i = level;i>=0;i--) {
94 TIter *s = fNextSet[i];
109 return fDataSet == fgNullDataSet ? fWorkingDataSet : fDataSet;
152 Error(
"Add",
"TDataSetIter.has been corrupted ;-!");
156 fNext =
new TIter(s->GetCollection() );
178 if (!dataset)
return 0;
180 if (path && strlen(path)) set =
Find(path);
181 return Add(dataset,set);
202 if (strcmp(dirname,
".."))
205 set = fWorkingDataSet->GetParent();
206 if (set) fWorkingDataSet = set;
231 while ( (nextSet = next()) )
232 if (ds == nextSet) {fWorkingDataSet = ds;
break;}
246 if (dirname) set =
Find(dirname);
255 if (!fWorkingDataSet)
return 0;
259 while((nextset = (count) ? next():fWorkingDataSet)) {
261 if (nextset->IsFolder()) std::cout << std::endl;
262 TString path = nextset->
Path();
263 std::cout << std::setw(2) << next.GetDepth() <<
". ";
264 std::cout << path << std::setw(TMath::Max(Int_t(60-strlen(path.Data())),Int_t(0))) <<
"...";
265 const Char_t *type = nextset->IsFolder() ?
"directory" :
"table" ;
266 std::cout << std::setw(10) << type;
267 std::cout <<
" : " << std::setw(10) << nextset->GetTitle();
268 std::cout << std::endl;
306 if (!name || !name[0])
return 0;
307 if (strchr(name,
'/')) {
308 Error(
"FindDataSet",
"The name of the object <%s> can not contain any \"/\"",name);
312 Bool_t opti = opt ? strcasecmp(opt,
"-i") == 0 : kFALSE;
313 Bool_t optt = opt ? strcasecmp(opt,
"-t") == 0 : kFALSE;
316 if (path && strlen(path)) startset =
Find(path);
317 else startset = fWorkingDataSet;
318 if (!startset)
return 0;
321 if ( !((opti && strcasecmp( optt ? set->GetTitle() : set->GetName(),name) == 0 ) ||
322 (strcmp(optt ? set->GetTitle() : set->GetName(),name) == 0)) )
325 while ((set = next()))
326 if ( (opti && strcasecmp(optt ? set->GetTitle() : set->GetName(),name) == 0 ) ||
327 (strcmp(optt ? set->GetTitle() : set->GetName(),name) == 0) )
break;
347 if (path) startset =
Find(path);
348 else startset = fWorkingDataSet;
349 if (!startset)
return 0;
353 while ( (nextSet = next()) )
354 if (set == nextSet)
break;
390 if (path && path[0]) startset =
Find(path);
391 else startset = fWorkingDataSet;
392 if (!startset)
return 0;
396 while ( (nextSet = next()) )
397 if (set == nextSet)
break;
405 Int_t TDataSetIter::Flag(
const Char_t *path,UInt_t flag,TDataSet::EBitOpt reset)
408 if (set) set->SetBit(flag,reset);
414 Int_t TDataSetIter::Flag(
TDataSet *dataset,UInt_t flag,TDataSet::EBitOpt reset)
416 if (dataset) dataset->SetBit(flag,reset);
434 if (!set && dirname==0) set=Cwd();
435 if (set) set->
ls(opt);
457 if (set) set->
ls(depth);
467 set =
Find(dirname,0,kTRUE);
470 if (!fRootDataSet ) fRootDataSet = set;
471 if (!fWorkingDataSet) fWorkingDataSet = fRootDataSet;
502 if (set == fWorkingDataSet) {
503 fWorkingDataSet = set->GetParent();
505 if (set == fRootDataSet) {
528 if (fMaxDepth==1) fDataSet = fNext ?
NextDataSet(*fNext) :0;
531 if (fDepth==0) fDepth = 1;
532 if (fDataSet && fDataSet != fgNullDataSet &&
533 (fDepth < fMaxDepth || fMaxDepth ==0) && mode == TDataSet::kContinue )
536 TSeqCollection *list = fDataSet->GetCollection();
538 if (list && list->GetSize() ) {
542 ,
" too many (%d) nested levels of your TDataSet has been detected",fDepth);
545 fNextSet[fDepth-1] =
new TIter(list);
550 TIter *next = fNextSet[fDepth-1];
553 if (mode != TDataSet::kUp) fDataSet =
NextDataSet(*next);
558 while (!fDataSet && fDepth > 1) {
561 next = fNextSet[fDepth-1];
586 TIter *next = fNextSet[nDataSet];
595 return Find(path,rootset,mkdir);
620 Bool_t mkdirflag,Bool_t titleFlag)
622 TDataSet *dataset=0,*dsnext=0,*ds=0;
623 Int_t len=0,nextlen=0,yes=0,anywhere=0,rootdir=0;
624 const Char_t *name=0,*nextname=0;
625 TSeqCollection *tl=0;
628 if (!name)
return rootset;
632 dataset = (path[0]==
'/') ? fRootDataSet:fWorkingDataSet;}
634 if (name[0] ==
'/') name++;
636 if (!strncmp(name,
".*/",3)) {anywhere=1998; name +=3;}
638 len = strcspn(name,
" /");
639 if (!len)
return dataset;
641 if (!dataset)
goto NOTFOUND;
646 nextname = titleFlag ? dataset->GetTitle() : dataset->GetName();
647 nextlen = strlen(nextname);
648 if (nextlen==len && !strncmp(name,nextname,len))
649 return Find(name+len,dataset,mkdirflag,titleFlag);
652 tl = dataset->GetCollection();
657 nextname = titleFlag ? dataset->GetTitle() : dsnext->GetName();
658 if (!nextname)
continue;
661 nextlen = strlen(nextname);
662 yes = (len == nextlen);
664 yes = !strncmp(name,nextname,len);
669 if (fDepth == 0) fDepth = 1;
672 ds =
Find(name+len,dsnext,mkdirflag,titleFlag);
678 if (!anywhere)
continue;
679 ds =
Find(name,dsnext,mkdirflag,titleFlag);
686 if (mkdirflag && !titleFlag)
690 char buf[512];buf[0]=0; strncat(buf,name,len);
698 if (!fRootDataSet) fRootDataSet = ds;
699 if (!fWorkingDataSet) fWorkingDataSet = ds;
707 return Find(name,dataset,mkdirflag);
721 fDataSet = fgNullDataSet;
722 if (fMaxDepth != 1) {
724 Int_t level = fDepth;
726 for (
int i = level;i>=0;i--) {
727 TIter *s = fNextSet[i];
739 if (fRootDataSet->GetCollection() )
740 fNext =
new TIter(fRootDataSet->GetCollection() );
743 fWorkingDataSet = fRootDataSet;
746 else if (fRootDataSet && fRootDataSet->GetCollection() )
747 fNext =
new TIter(fRootDataSet->GetCollection() );
750 if (depth) fMaxDepth = depth;
784 Error(
"Shunt",
"TDataSetIter.has been corrupted ;-!");
788 fNext =
new TIter(s->GetCollection() );
811 if (!dataset)
return 0;
813 if (path && strlen(path)) set =
Find(path);
814 return Shunt(dataset,set);
833 if (dataSet && dataSet->HasData())
return dataSet;
virtual Int_t Du() const
summarize dataset usage by Herb Ward proposal
virtual TDataSet * Mkdir(const Char_t *dirname)
to be documented
virtual TDataSet * FindByTitle(const Char_t *title, const Char_t *path="", Option_t *opt="")
to be documented
virtual TDataSet * Instance() const
virtual TDataSet * Cd(const Char_t *dirname)
virtual TDataSet * Next(TDataSet::EDataSetPass mode=TDataSet::kContinue)
virtual TDataSet * FindByPath(const Char_t *path, TDataSet *rootset=0, Bool_t mkdir=kFALSE)
to be documented
virtual TDataSet * Dir(Char_t *dirname)
virtual TDataSet * FindByPointer(TDataSet *set, const Char_t *path=0, Option_t *opt="")
TDataSet * NextDataSet(TIter &next)
to be documented
virtual TDataSet * Ls(const Char_t *dirname="", Option_t *opt="") const
virtual TObject * FindObject(const Char_t *name) const
virtual TDataSet * operator[](const Char_t *path)
virtual void Reset(TDataSet *l=0, Int_t depth=0)
virtual ~TDataSetIter()
to be documented
virtual void ls(Option_t *option="") const
virtual TDataSet * FindByName(const Char_t *name, const Char_t *path="", Option_t *opt="")
to be documented
TDataSet * GetNullSet()
return a fake pointer == -1 casted to (TDataSet *)
virtual TDataSet * Rmdir(TDataSet *dataset, Option_t *option="")
virtual TDataSet * FindDataSet(const Char_t *name, const Char_t *path="", Option_t *opt="")
virtual void Shunt(TDataSet *newParent=0)
virtual TDataSet * Find(const Char_t *path, TDataSet *rootset=0, Bool_t mkdir=kFALSE, Bool_t titleFlag=kFALSE)
virtual TString Path() const
return the full path of this data set
virtual TDataSet * Find(const char *path) const
virtual TDataSet * operator*() const
operator *