]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/scripts/TestMapAccess.C
o add track alpha to tree
[u/mrichter/AliRoot.git] / FMD / scripts / TestMapAccess.C
1 #include <TRandom.h>
2 #include <TStopwatch.h>
3 #include <AliFMDFloatMap.h>
4
5 Float_t 
6 TestValue(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t v)
7 {
8   return d * 1000000 + ((r=='I')+1) * 100000 + s * 1000 + t + v;
9 }
10   
11 struct TestOne : public AliFMDMap::ForOne
12 {
13   Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t v)
14   {
15     // Caculate a simple number from d, r, s, t, v 
16     Float_t x = TestValue(d, r, s, t, v);
17     return x > -1000000000; // Always true
18   }
19   Bool_t operator()(UShort_t,Char_t,UShort_t,UShort_t,Int_t) {return true;}
20   Bool_t operator()(UShort_t,Char_t,UShort_t,UShort_t,Bool_t) {return true;}
21   Bool_t operator()(UShort_t,Char_t,UShort_t,UShort_t,UShort_t) {return true;}
22 };
23
24 void 
25 AccessOneByOne(AliFMDFloatMap& m)
26 {
27   TestOne p;
28   m.ForEach(p);
29 }
30
31 void
32 AccessByCoords(AliFMDFloatMap& m)
33 {
34   for (UShort_t d = 1; d <= 3; d++) { 
35     UShort_t nr = (d == 1 ? 1 : 2);
36     for (UShort_t q = 0; q < nr; q++) { 
37       Char_t    r = (q == 0 ? 'I' : 'O');
38       UShort_t ns = (q == 0 ?  20 :  40);
39       UShort_t nt = (q == 0 ? 512 : 256);
40       for (UShort_t s = 0; s < ns; s++) {
41         for (UShort_t t = 0; t < nt; t++) { 
42           Float_t x = TestValue(d, r, s, t, m(d,r,s,t));
43           if (x < -1000000000) break;
44         }
45       }
46     }
47   }
48 }
49         
50 void
51 FillRandom(AliFMDFloatMap& m) 
52 {
53   Float_t* data = m.Data();
54   UInt_t   max  = 51200; // m.MaxIndex();
55
56   for (UInt_t i = 0; i < max; i++) 
57     data[i] = gRandom->Uniform(1);
58 }
59       
60 void
61 TestMapAccess(Int_t n=1000)
62 {
63  
64   AliFMDFloatMap m(0);
65   TStopwatch s;
66
67   s.Reset();
68   for (Int_t i = 0; i < n; i++) { 
69     FillRandom(m);
70     s.Start(kFALSE);
71     AccessOneByOne(m);
72     s.Stop();
73   }
74   s.Print();
75
76   s.Reset();
77   for (Int_t i = 0; i < n; i++) { 
78     FillRandom(m);
79     s.Start(kFALSE);
80     AccessByCoords(m);
81     s.Stop();
82   }
83   s.Print();
84 }
85
86 #ifndef __CINT__
87 #include <sstream>
88
89 int
90 main(int argc, char** argv)
91 {
92   int n  = 1000;
93   if (argc > 1) { 
94     std::stringstream s(argv[1]);
95     s >> n;
96   }
97   TestMapAccess(n);
98   return 0;
99 }
100 #endif