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 // $Id: testdataset.c,v 1.14 2001/02/05 19:08:44 fine Exp $
4 // $Log: testdataset.c,v $
5 // Revision 1.14 2001/02/05 19:08:44 fine
6 // An extra check to test TDataSetIter::FindObject method
7 //
8 // Revision 1.13 2000/09/30 17:51:54 perev
9 // Evolution On/Off SetEvol.C added
10 //
11 // Revision 1.11 1999/12/28 23:32:02 fine
12 // TDataSetIter operator++ removed to avoid a future problem
13 //
14 // Revision 1.10 1999/12/28 22:25:03 fine
15 // new test for operators ++ and * implemented
16 //
17 // Revision 1.9 1999/04/15 19:45:26 fine
18 // testdataset.c has been improved
19 //
20 // Revision 1.8 1999/04/07 15:41:22 fine
21 // Extra test for TDataSetIter::Du() was introduced
22 //
23 {
24  gROOT->Reset();
25  // Determinate the brand of the OS
26  gSystem.Load("libStar");
27 
28  TDataSetIter d;
29  d.Mkdir("v1/v1_1/v1_1_1");
30  cout << "Short list:" << endl;
31  d.Pwd();
32  cout << "Wide list:" << endl;
33  d.Pwd("*");
34  cout << endl;
35  d.Mkdir("/v1/v1_2/v1_2_1");
36  d.Pwd("*");
37  cout << endl;
38  d.Mkdir("v1/v1_3/v1_2_2");
39 
40  TDataSet *last = d.Mkdir("v1/v1/v1_v1_2_2");
41  TDataSet *just = d("v1/v1/v1_v1_2_2");
42 
43  if (last != just)
44  cout << "Error: Mkdir return a wrong addrees";
45  else
46  cout << "Ok! return value of TDataSetIter::Mkdir method has been tested";
47 
48  cout << endl << endl;
49 
50  d.Pwd("*");
51  cout << endl;
52  d.Mkdir("v1/v21/v3211");
53  d.Pwd("*");
54  cout << endl << "------------ 1 ------------ " << endl;
55  cout << endl;
56  d.Mkdir("v1/v21/v3212/v4");
57  cout << "the current path: " << d("v1/v21/v3212/v4")->Path() << endl;
58  d.Pwd("/");
59  d("/")->ls();
60  d.ls("/");
61  cout << "list \"v3212\" the relative path " << endl;
62  d.Pwd("v1/v21/v3212");
63  d("v1/v21/v3212")->ls();
64  d.ls("v1/v21/v3212");
65 
66  cout << endl;
67  cout << "--------------------" << " Testing TDataSetIter::Du() method: " <<
68  "--------------------" << endl;
69  Int_t total = d.Du();
70  cout << "---------------------" << endl;
71  cout << "Total: " << total << " datasets were listed" << endl;
72  cout << "-----------------" << " End of Testing TDataSetIter::Du() method: " <<
73  "----------------" << endl;
74  cout << endl;
75  cout << "We'll try some \"wrong\" path now" << endl;
76  d.Ls("unknown");
77 // d.Pwd()->ls("unknown");
78 // cout << endl << "------------ 2 ------------ " << endl;
79  cout << endl << "-------- 2 test \"FindObject\" ------------ " << endl;
80 
81  const Char_t *v3212 = "v3212";
82  TDataSet *found = d.FindObject(v3212);
83  if (found) {
84  const Char_t *t = found->Path();
85  cout << "Object: " << v3212 << " found. It\'s path is " << t << endl;
86  }
87  else {
88  cout << "Object: " << v3212 << " has not been found." << endl;
89  cout << "Try FindByName" << endl;
90  TDataSet *lost = d.FindByName(v3212);
91  if (lost) {
92  cout << "The wrong implementation of TDataSetIter::FindObject method has been discovered" << endl;
93  lost->ls();
94  }
95  return;
96  }
97 
98  cout << endl << "-------- 2.2 test \"FindByName\" ------------ " << endl;
99  cout << endl << "-------- 2.2 test \"FindByName\" ------------ " << endl;
100 
101  const Char_t *vS3213 = "/v32/13";
102  cout << " === Error message expected " << endl;
103  found = d.FindByName(vS3213);
104  if (found) return;
105 
106  cout << endl << "-------- 2.3 test \"FindByName\" ------------ " << endl;
107  cout << endl << "-------- 2.3 test \"FindByName\" ------------ " << endl;
108 
109  const Char_t *V3212 = "V3212";
110  found = d.FindByName(V3212,0,"-I");
111  if (found) {
112  const Char_t *t2 = found->Path();
113  cout << "Object: " << V3212 << " found. It\'s path is " << t2 << endl;
114  }
115  else {
116  cout << "Object: " << V3212 << " has not been found." << endl;
117  return;
118  }
119 
120  cout << endl << "-------- 2.4 test \"FindByName\" ------------ " << endl;
121  cout << endl << "-------- 2.4 test \"FindByName\" ------------ " << endl;
122 
123  cout << " === Error message expected " << endl;
124  found = d.FindByName(V3212,"v1/v21/v3212/v4","-I");
125  if (found) return;
126  cout << " Object not found" << endl;
127 
128  cout << "recreating directories" << endl;
129 
130  d.Rmdir("v1/v1_1/v1_1_1");
131  d.Pwd()->ls("*");
132  cout << endl << "------------ 3 ------------ " << endl;
133  d.Mkdir("v1/v1_1/v1_1_1");
134  d.Pwd()->ls("*");
135  cout << endl << "------------ 4 ------------ " << endl;
136  d.Rmdir("v1/v1_1/v1_1_1");
137  d.Pwd()->ls("*");
138  cout << endl << "------------ 5 ------------ " << endl;
139  d.Mkdir("v1/v1_1/v1_1_1");
140  d.ls("/v1",3);
141  cout << endl << "------------ 6 ------------ " << endl;
142  cout << "Let's check the operator []" << endl;
143  if (d["v1/v1_1/v1_1_1"])
144  cout << " ** Error **: the path to d[\"" << d("v1/v1_1/v1_1_1")->Path() << "\"]=" << d["v1/v1_1/v1_1_1"] << endl;
145  else
146  cout << " Ok! the path to d[\"" << d("v1/v1_1/v1_1_1")->Path() << "\"]=" << d["v1/v1_1/v1_1_1"] << ";" << endl;
147  cout << endl << "------------ 7 ------------ " << endl;
148  cout << " Check loop with \"TDataSet *operator *() const\"" << endl;
149  TDataSet *ds = 0;
150  do {
151  ds = *d;
152  if (ds) {
153  cout << "\tCurrent ds <" << ds->GetName() << ">;";
154  if (d()) {
155  cout << "\tnext ds will be <" << (*d)->GetName();
156  cout << ">" << endl;
157  } else
158  cout << "\tthere will be no new ds" << endl;
159 
160  }
161  } while (ds);
162  cout << " end of loop " << endl << endl ;
163 
164  cout << endl << "------------ 8 ------------ " << endl;
165  d.Pwd();
166  d.Rmdir("v1/v21");
167  cout << endl << "------------ 9 ------------ " << endl;
168  d.ls("","*");
169  d.Rmdir("v1");
170  d.Rmdir("v1");
171  if (d.Cwd()) {
172  d.ls("","*");
173  cout << "Error the directory should be undefined nowadays " << endl;
174  }
175  else cout << "Ok! The last dataset has NO active directory anymore" << endl;
176  d.Pwd();
177 
178  cout << endl << "------------ 9 ------------ " << endl;
179 
180 }
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