AliRoot Core  3dc7879 (3dc7879)
TestIndex.C
Go to the documentation of this file.
1 //____________________________________________________________________
2 //
3 // $Id$
4 //
10 #ifndef __CINT__
11 #include <AliFMDIndex.h>
12 #include <iostream>
13 #include <TFile.h>
14 #endif
15 
23 std::ostream&
24 operator << (std::ostream& o, const AliFMDIndex& i)
25 {
26  return o << i.Name();
27 }
28 
34 bool
35 cmp(const AliFMDIndex& lhs, const AliFMDIndex& rhs)
36 {
37  bool ret = lhs < rhs;
38  std::cout << " (" << lhs << " < " << rhs << "): " << ret << std::endl;
39  return ret;
40 }
41 
51 bool
52 equiv(const AliFMDIndex& lhs, const AliFMDIndex& rhs)
53 {
54  bool ret = !(cmp(lhs,rhs) || cmp(rhs,lhs));
55  std::cout << " (" << lhs << " <> " << rhs << "): " << ret << std::endl;
56  return ret;
57 }
58 
63 bool
64 self(const AliFMDIndex& x)
65 {
66  bool ret = !cmp(x,x);
67  std::cout << " !(" << x << " < " << x << "): " << ret << std::endl;
68  return ret;
69 }
70 
77 bool
78 imply(bool a, bool b, bool c)
79 {
80  bool ret = ((a && b) && c) || (!(a && b));
81  return ret;
82 }
83 
93 bool
94 trans(const AliFMDIndex& x, const AliFMDIndex& y, const AliFMDIndex& z)
95 {
96  bool ret = imply(cmp(x,y), cmp(y,z), cmp(x,z));
97  std::cout << " (" << x << " < " << y << " && " << y << " < " << z
98  << ") => " << x << " < " << z << " "
99  << (ret ? "holds" : "violated") << std::endl;
100  return ret;
101 
102 }
103 
113 bool
114 equiv(const AliFMDIndex& x, const AliFMDIndex& y, const AliFMDIndex& z)
115 {
116  bool ret = imply(equiv(x,y), equiv(y,z), equiv(x,z));
117  std::cout << " (" << x << " <> " << y << " && " << y << " <> " << z
118  << ") => " << x << " <> " << z << " "
119  << (ret ? "holds" : "violated") << std::endl;
120  return ret;
121 }
122 
123 
127 void
129 {
130  AliFMDIndex i1(1, 'I', 5, 63);
131  AliFMDIndex i2(i1);
132  AliFMDIndex i3(i1);
133  AliFMDIndex i4(1, 'I', 5, 127);
134  AliFMDIndex i5(1, 'I', 15, 63);
135  AliFMDIndex i6(2, 'O', 15, 60);
136  std::cout << "Is !(x < x): " << std::endl;
137  self(i1);
138  std::cout << "Does (x < y && y < z) imply x < z: " << std::endl;
139  // true, true
140  trans(i1, i4, i5);
141  // true, false
142  trans(i1, i6, i5);
143  // false, true
144  trans(i4, i1, i5);
145  // false, false
146  trans(i6, i5, i1);
147  std::cout << "Does !(x < y || x > y) && !(y < z || z > y) imply "
148  << "!(x < z || x > z)" << std::endl;
149  // true, true
150  equiv(i1, i2, i3);
151  // true, false
152  equiv(i1, i2, i4);
153  // false, true
154  equiv(i4, i1, i2);
155  // false, false
156  equiv(i1, i4, i5);
157 
158 
159 
160  TFile* file = TFile::Open("index.root", "RECREATE");
161  file->WriteObject(&i1,"i1");
162  file->Write();
163  file->Close();
164 
165  AliFMDIndex* i7 = 0;
166  file = TFile::Open("index.root", "READ");
167  file->GetObject("i1", i7);
168  file->Close();
169  std::cout << *i7 << " == " << i1 << ": " << (*i7 == i1) << std::endl;
170 
171 }
172 
176 void
178 {
179  AliFMDObjIndex i1(1, 'I', 5, 63);
180  AliFMDObjIndex i2(i1);
181  AliFMDObjIndex i3(i1);
182  AliFMDObjIndex i4(1, 'I', 5, 127);
183  AliFMDObjIndex i5(1, 'I', 15, 63);
184  AliFMDObjIndex i6(2, 'O', 15, 60);
185  std::cout << "Is !(x < x): " << std::endl;
186  self(i1);
187  std::cout << "Does (x < y && y < z) imply x < z: " << std::endl;
188  // true, true
189  trans(i1, i4, i5);
190  // true, false
191  trans(i1, i6, i5);
192  // false, true
193  trans(i4, i1, i5);
194  // false, false
195  trans(i6, i5, i1);
196  std::cout << "Does !(x < y || x > y) && !(y < z || z > y) imply "
197  << "!(x < z || x > z)" << std::endl;
198  // true, true
199  equiv(i1, i2, i3);
200  // true, false
201  equiv(i1, i2, i4);
202  // false, true
203  equiv(i4, i1, i2);
204  // false, false
205  equiv(i1, i4, i5);
206 
207 
208 
209  TFile* file = TFile::Open("index.root", "RECREATE");
210  i1.Write("i1");
211  file->Write();
212  file->Close();
213 
214  file = TFile::Open("index.root", "READ");
215  AliFMDObjIndex* i7 = (AliFMDObjIndex*)(file->Get("i1"));
216  file->Close();
217  std::cout << *i7 << " == " << i1 << ": " << (*i7 == i1) << std::endl;
218 
219 }
220 
224 void
226 {
227  TList l;
228  for (size_t i = 0; i < 30; i++) {
229  UShort_t det = gRandom->Integer(3)+1;
230  Char_t ring = (gRandom->Uniform() > .5 ? 'O' : 'I');
231  UShort_t sec = gRandom->Integer(ring == 'I' ? 20 : 40);
232  UShort_t str = gRandom->Integer(ring == 'I' ? 512 : 256);
233  l.AddAt(new AliFMDObjIndex(det, ring, sec, str), i);
234  }
235  std::cout << "Before sort" << std::endl;
236  l.ls();
237  l.Sort();
238  std::cout << "After sort" << std::endl;
239  l.ls();
240 }
241 
242 
243 //____________________________________________________________________
244 //
245 // EOF
246 //
TBrowser b
Definition: RunAnaESD.C:12
TFile * Open(const char *filename, Long64_t &nevents)
std::ostream & operator<<(std::ostream &o, const AliFMDIndex &i)
Definition: TestIndex.C:24
bool cmp(const AliFMDIndex &lhs, const AliFMDIndex &rhs)
Definition: TestIndex.C:35
void TestIndex()
Definition: TestIndex.C:128
bool trans(const AliFMDIndex &x, const AliFMDIndex &y, const AliFMDIndex &z)
Definition: TestIndex.C:94
void TestObjIndex()
Definition: TestIndex.C:177
FMD detector coordinates.
FMD detector coordinates.
Definition: AliFMDIndex.h:36
bool equiv(const AliFMDIndex &lhs, const AliFMDIndex &rhs)
Definition: TestIndex.C:52
void SortIndex()
Definition: TestIndex.C:225
const char * Name() const
bool imply(bool a, bool b, bool c)
Definition: TestIndex.C:78