A lot of changes after detector review:
[u/mrichter/AliRoot.git] / FMD / scripts / TestIndex.C
CommitLineData
55f0ce5b 1//____________________________________________________________________
2//
3// $Id$
4//
5/** @file TestIndex.C
6 @author Christian Holm Christensen <cholm@nbi.dk>
7 @date Thu Mar 30 01:20:02 2006
8 @brief Test AliFMDIndex and AliFMDObjIndex
9*/
10#ifndef __CINT__
11#include <AliFMDIndex.h>
12#include <iostream>
13#include <TFile.h>
14#endif
15/** @defgroup index_test Test of AliFMDIndex and AliFMDObjIndex
16 @ingroup FMD_script
17*/
18/** Write an AliFMDIndex object to output stream
19 @ingroup index_test
20 @param o Stream
21 @param i Index object
22 @return @a o */
23std::ostream&
24operator << (std::ostream& o, const AliFMDIndex& i)
25{
26 return o << i.Name();
27}
28
29/** Do the comparision, and print to standard out
30 @ingroup index_test
31 @param lhs Left hand side
32 @param rhs Right hand side
33 @return @f$ lhs < rhs @f$ */
34bool
35cmp(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
42/** Test if two index objects are equivilant (are the same).
43 Equivilance is defined as
44 @f[
45 lhs \equiv rhs: \not (lhs < rhs \vee rhs < lhs)
46 @f]
47 @ingroup index_test
48 @param lhs Left hand side
49 @param rhs Right hand side
50 @return @c true if @a lhs and @a rhs are equivilant */
51bool
52equiv(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
59/** Check that @f$ \not (x < x)@f$
60 @ingroup index_test
61 @param x Object to test
62 @return @c true if @a x is not less than itself */
63bool
64self(const AliFMDIndex& x)
65{
66 bool ret = !cmp(x,x);
67 std::cout << " !(" << x << " < " << x << "): " << ret << std::endl;
68 return ret;
69}
70
71/** Check if @f$ a \wedge b \Rightarrow c@f$
72 @ingroup index_test
73 @param a First condition
74 @param b Second condition
75 @param c Implication
76 @return @c true if the implication is valid */
77bool
78imply(bool a, bool b, bool c)
79{
80 bool ret = ((a && b) && c) || (!(a && b));
81 return ret;
82}
83
84/** Check if the comparison operator is transitive, that is
85 @f[
86 (x < y \wedge y < z) \Rightarrow x < z
87 @f]
88 @ingroup index_test
89 @param x First object
90 @param y Second object
91 @param z Third object
92 @return @c true if the implication is met. */
93bool
94trans(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
104/** Check that the comparison operator preserves equivilance, that is
105 @f[
106 (x \equiv y \wedge y \equiv z) \Rightarrow (x \equiv z)
107 @f]
108 @ingroup index_test
109 @param x First object
110 @param y Second argument
111 @param z Third object
112 @return @c true if the implication holds. */
113bool
114equiv(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
124/** Check if the comparison operator is a @e strictly @e weak @e ordering
125 @ingroup index_test
126 */
127void
128TestIndex()
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
173/** Check if the comparison operator is a @e strictly @e weak @e ordering
174 @ingroup index_test
175 */
176void
177TestObjIndex()
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
221/** Check that we can sort an array of index objects
222 @ingroup index_test
223 */
224void
225SortIndex()
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//