StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestDataSet.C
1 //*CMZ : 12/07/98 18.27.27 by Valery Fine(fine@bnl.gov)
2 //*-- Author : Valery Fine(fine@bnl.gov) 07/04/99
3 //
4 // This macro tests the various methods of TDataSet class
5 //
6 // Copyright(c) 2001 [BNL] Brookhaven National Laboratory, Valeri Fine (fine@bnl.gov). All right reserved",
7 //
8 // Permission to use, copy, modify and distribute this software and its
9 // documentation for any purpose is hereby granted without fee,
10 // provided that the above copyright notice appear in all copies and
11 // that both that copyright notice and this permission notice appear
12 // in supporting documentation. The author makes no
13 // representations about the suitability of this software for any
14 // purpose. It is provided "as is" without express or implied warranty.
16 {
17 
18  gROOT->Reset();
19  #include "iostream.h"
20  gSystem.Load("libTable");
21 
22  TDataSetIter d;
23  d.Mkdir("v1/v1_1/v1_1_1");
24  cout << "Short list:" << endl;
25  d.Pwd();
26  cout << "Wide list:" << endl;
27  d.Pwd("*");
28  cout << endl;
29  d.Mkdir("/v1/v1_2/v1_2_1");
30  d.Pwd("*");
31  cout << endl;
32  d.Mkdir("v1/v1_3/v1_2_2");
33 
34  TDataSet *last = d.Mkdir("v1/v1/v1_v1_2_2");
35  TDataSet *just = d("v1/v1/v1_v1_2_2");
36 
37  if (last != just)
38  cout << "Error: Mkdir return a wrong addrees";
39  else
40  cout << "Ok! return value of TDataSetIter::Mkdir method has been tested";
41 
42  cout << endl << endl;
43 
44  d.Pwd("*");
45  cout << endl;
46  d.Mkdir("v1/v21/v3211");
47  d.Pwd("*");
48  cout << endl << "------------ 1 ------------ " << endl;
49  cout << endl;
50  d.Mkdir("v1/v21/v3212/v4");
51  cout << "the current path: " << d("v1/v21/v3212/v4")->Path() << endl;
52  d.Pwd("/");
53  d("/")->ls();
54  d.ls("/");
55  cout << "list \"v3212\" the relative path " << endl;
56  d.Pwd("v1/v21/v3212");
57  d("v1/v21/v3212")->ls();
58  d.ls("v1/v21/v3212");
59 
60  cout << endl;
61  cout << "--------------------" << " Testing TDataSetIter::Du() method: " <<
62  "--------------------" << endl;
63  Int_t total = d.Du();
64  cout << "---------------------" << endl;
65  cout << "Total: " << total << " datasets were listed" << endl;
66  cout << "-----------------" << " End of Testing TDataSetIter::Du() method: " <<
67  "----------------" << endl;
68  cout << endl;
69  cout << "We'll try some \"wrong\" path now" << endl;
70  d.Ls("unknown");
71 // d.Pwd()->ls("unknown");
72 // cout << endl << "------------ 2 ------------ " << endl;
73  cout << endl << "-------- 2 test \"FindObject\" ------------ " << endl;
74 
75  const Char_t *v3212 = "v3212";
76  TDataSet *found = d.FindObject(v3212);
77  if (found) {
78  const Char_t *t = found->Path();
79  cout << "Object: " << v3212 << " found. It\'s path is " << t << endl;
80  }
81  else {
82  cout << "Object: " << v3212 << " has not been found." << endl;
83  cout << "Try FindByName" << endl;
84  TDataSet *lost = d.FindByName(v3212);
85  if (lost) {
86  cout << "The wrong implementation of TDataSetIter::FindObject method has been discovered" << endl;
87  lost->ls();
88  }
89  return;
90  }
91 
92  cout << endl << "-------- 2.2 test \"FindByName\" ------------ " << endl;
93  cout << endl << "-------- 2.2 test \"FindByName\" ------------ " << endl;
94 
95  const Char_t *vS3213 = "/v32/13";
96  cout << " === Error message expected " << endl;
97  found = d.FindByName(vS3213);
98  if (found) return;
99 
100  cout << endl << "-------- 2.3 test \"FindByName\" ------------ " << endl;
101  cout << endl << "-------- 2.3 test \"FindByName\" ------------ " << endl;
102 
103  const Char_t *V3212 = "V3212";
104  found = d.FindByName(V3212,0,"-I");
105  if (found) {
106  const Char_t *t2 = found->Path();
107  cout << "Object: " << V3212 << " found. It\'s path is " << t2 << endl;
108  }
109  else {
110  cout << "Object: " << V3212 << " has not been found." << endl;
111  return;
112  }
113 
114  cout << endl << "-------- 2.4 test \"FindByName\" ------------ " << endl;
115  cout << endl << "-------- 2.4 test \"FindByName\" ------------ " << endl;
116 
117  cout << " === Error message expected " << endl;
118  found = d.FindByName(V3212,"v1/v21/v3212/v4","-I");
119  if (found) return;
120  cout << " Object not found" << endl;
121 
122  cout << "recreating directories" << endl;
123 
124  d.Rmdir("v1/v1_1/v1_1_1");
125  d.Pwd()->ls("*");
126  cout << endl << "------------ 3 ------------ " << endl;
127  d.Mkdir("v1/v1_1/v1_1_1");
128  d.Pwd()->ls("*");
129  cout << endl << "------------ 4 ------------ " << endl;
130  d.Rmdir("v1/v1_1/v1_1_1");
131  d.Pwd()->ls("*");
132  cout << endl << "------------ 5 ------------ " << endl;
133  d.Mkdir("v1/v1_1/v1_1_1");
134  d.ls("/v1",3);
135  cout << endl << "------------ 6 ------------ " << endl;
136  cout << "Let's check the operator []" << endl;
137  if (d["v1/v1_1/v1_1_1"])
138  cout << " ** Error **: the path to d[\"" << d("v1/v1_1/v1_1_1")->Path() << "\"]=" << d["v1/v1_1/v1_1_1"] << endl;
139  else
140  cout << " Ok! the path to d[\"" << d("v1/v1_1/v1_1_1")->Path() << "\"]=" << d["v1/v1_1/v1_1_1"] << ";" << endl;
141  cout << endl << "------------ 7 ------------ " << endl;
142  cout << " Check loop with \"TDataSet *operator *() const\"" << endl;
143  TDataSet *ds = 0;
144  do {
145  ds = *d;
146  if (ds) {
147  cout << "\tCurrent ds <" << ds->GetName() << ">;";
148  if (d()) {
149  cout << "\tnext ds will be <" << (*d)->GetName();
150  cout << ">" << endl;
151  } else
152  cout << "\tthere will be no new ds" << endl;
153 
154  }
155  } while (ds);
156  cout << " end of loop " << endl << endl ;
157 
158  cout << endl << "------------ 8 ------------ " << endl;
159  d.Pwd();
160  d.Rmdir("v1/v21");
161  cout << endl << "------------ 9 ------------ " << endl;
162  d.ls("","*");
163  d.Rmdir("v1");
164  d.Rmdir("v1");
165  if (d.Cwd()) {
166  d.ls("","*");
167  cout << "Error the directory should be undefined nowadays " << endl;
168  }
169  else cout << "Ok! The last dataset has NO active directory anymore" << endl;
170  d.Pwd();
171 
172  cout << endl << "------------ 9 ------------ " << endl;
173 
174 }
virtual Int_t Du() const
summarize dataset usage by Herb Ward proposal
virtual TDataSet * Mkdir(const Char_t *dirname)
to be documented
virtual TDataSet * Ls(const Char_t *dirname="", Option_t *opt="") const
virtual TObject * FindObject(const Char_t *name) const
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
virtual TDataSet * FindByName(const Char_t *name, const Char_t *path="", Option_t *opt="")
to be documented
virtual TDataSet * Rmdir(TDataSet *dataset, Option_t *option="")
virtual TString Path() const
return the full path of this data set
Definition: TDataSet.cxx:626