1 //____________________________________________________________________
6 @author Christian Holm Christensen <cholm@nbi.dk>
7 @date Thu Mar 30 01:20:02 2006
8 @brief Test AliFMDIndex and AliFMDObjIndex
11 #include <AliFMDIndex.h>
15 /** @defgroup index_test Test of AliFMDIndex and AliFMDObjIndex
18 /** Write an AliFMDIndex object to output stream
24 operator << (std::ostream& o, const AliFMDIndex& i)
29 /** Do the comparision, and print to standard out
31 @param lhs Left hand side
32 @param rhs Right hand side
33 @return @f$ lhs < rhs @f$ */
35 cmp(const AliFMDIndex& lhs, const AliFMDIndex& rhs)
38 std::cout << " (" << lhs << " < " << rhs << "): " << ret << std::endl;
42 /** Test if two index objects are equivilant (are the same).
43 Equivilance is defined as
45 lhs \equiv rhs: \not (lhs < rhs \vee rhs < lhs)
48 @param lhs Left hand side
49 @param rhs Right hand side
50 @return @c true if @a lhs and @a rhs are equivilant */
52 equiv(const AliFMDIndex& lhs, const AliFMDIndex& rhs)
54 bool ret = !(cmp(lhs,rhs) || cmp(rhs,lhs));
55 std::cout << " (" << lhs << " <> " << rhs << "): " << ret << std::endl;
59 /** Check that @f$ \not (x < x)@f$
61 @param x Object to test
62 @return @c true if @a x is not less than itself */
64 self(const AliFMDIndex& x)
67 std::cout << " !(" << x << " < " << x << "): " << ret << std::endl;
71 /** Check if @f$ a \wedge b \Rightarrow c@f$
73 @param a First condition
74 @param b Second condition
76 @return @c true if the implication is valid */
78 imply(bool a, bool b, bool c)
80 bool ret = ((a && b) && c) || (!(a && b));
84 /** Check if the comparison operator is transitive, that is
86 (x < y \wedge y < z) \Rightarrow x < z
90 @param y Second object
92 @return @c true if the implication is met. */
94 trans(const AliFMDIndex& x, const AliFMDIndex& y, const AliFMDIndex& z)
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;
104 /** Check that the comparison operator preserves equivilance, that is
106 (x \equiv y \wedge y \equiv z) \Rightarrow (x \equiv z)
109 @param x First object
110 @param y Second argument
111 @param z Third object
112 @return @c true if the implication holds. */
114 equiv(const AliFMDIndex& x, const AliFMDIndex& y, const AliFMDIndex& z)
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;
124 /** Check if the comparison operator is a @e strictly @e weak @e ordering
130 AliFMDIndex i1(1, 'I', 5, 63);
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;
138 std::cout << "Does (x < y && y < z) imply x < z: " << std::endl;
147 std::cout << "Does !(x < y || x > y) && !(y < z || z > y) imply "
148 << "!(x < z || x > z)" << std::endl;
160 TFile* file = TFile::Open("index.root", "RECREATE");
161 file->WriteObject(&i1,"i1");
166 file = TFile::Open("index.root", "READ");
167 file->GetObject("i1", i7);
169 std::cout << *i7 << " == " << i1 << ": " << (*i7 == i1) << std::endl;
173 /** Check if the comparison operator is a @e strictly @e weak @e ordering
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;
187 std::cout << "Does (x < y && y < z) imply x < z: " << std::endl;
196 std::cout << "Does !(x < y || x > y) && !(y < z || z > y) imply "
197 << "!(x < z || x > z)" << std::endl;
209 TFile* file = TFile::Open("index.root", "RECREATE");
214 file = TFile::Open("index.root", "READ");
215 AliFMDObjIndex* i7 = (AliFMDObjIndex*)(file->Get("i1"));
217 std::cout << *i7 << " == " << i1 << ": " << (*i7 == i1) << std::endl;
221 /** Check that we can sort an array of index objects
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);
235 std::cout << "Before sort" << std::endl;
238 std::cout << "After sort" << std::endl;
243 //____________________________________________________________________