| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

TestFastClusterContainer.cpp

Go to the documentation of this file.
00001 // $Id: TestFastClusterContainer.cpp,v 1.2 2007/08/29 09:35:34 jonrob Exp $
00002 
00003 #include "Kernel/FastClusterContainer.h"
00004 
00005 namespace ContTests
00006 {
00007 
00008   static int s_cnt[2] = {0,0};
00009   struct Cluster  {
00010     unsigned m_chanID     : 24;
00011     unsigned m_size       :  1;
00012     unsigned m_threshold  :  1;
00013     unsigned m_center     :  3;
00014     unsigned m_pad        :  3;
00015     Cluster() {
00016       *(int*)this = 0;
00017       s_cnt[0]++;
00018     }
00019     ~Cluster() {        // Note: non virtual !
00020       s_cnt[1]++;
00021     }
00022     int chanID() const    { return m_chanID;    }
00023     int size() const      { return m_size;      }
00024     int threshold() const { return m_threshold; }
00025     unsigned center() const    { return m_center;    }
00026     void set(int i)  {
00027       m_chanID = i&0x00FFFFFF;
00028       m_size = i%2;
00029       m_threshold = (i+1)%2;
00030       m_center = i%8;
00031     }
00032   };
00033 
00034   static void __set(int* p, int i)  {
00035     // fast filling:
00036     // channel ID          size         threshold         cluster center
00037     //*p = (i&0x00FFFFFF) + ((i%2)<<24) + (((i+1)%2)<<25) + ((i%8)<<26);
00038     // _or_ with identical assembly code:
00039     *p = (i&0x00FFFFFF) + ((i%2)*0x01000000) + (((i+1)%2)*0x02000000) +
00040       ((i%8)*0x04000000);
00041   }
00042 
00043   void testCont()  {
00044     s_cnt[0] = s_cnt[1] = 0;
00045     {
00046       typedef FastClusterContainer<Cluster,int > ClusterCont;
00047       ClusterCont cnt;
00048       cnt.resize(128);
00049       int i, n;
00050       int* p = (int*)&(*cnt.begin());
00051       ClusterCont::iterator j;
00052       for(i=0, n=cnt.size(), j=cnt.begin(); i < n; ++i, ++p, ++j)  {
00053         ClusterCont::value_type& v = *j;
00054         v.set(i);
00055         __set(p, i);
00056         printf(" [%08X, %d %d %d] Channel ID:  %08X   size:%d threshold:%d  center:%d  \n",
00057                *p, (i%2), (i+1)%2, (i%8), v.chanID(), v.size(), v.threshold(),
00058                v.center());
00059       }
00060       {
00061         for(i=0, n=cnt.size(), j=cnt.begin(); i < n; ++i, ++p, ++j)  {
00062           ClusterCont::value_type& v = *j;
00063           printf("Channel ID:  %08X   size:%d   threshold:%d  center:%d \n",
00064                  v.chanID(), v.size(), v.threshold(), v.center());
00065         }
00066       }
00067     }
00068     printf("Clusters constructed:%d destructed:%d diff:%d\n",s_cnt[0],s_cnt[1],s_cnt[0]-s_cnt[1]);
00069   }
00070 
00071 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:03:13 2011 for LHCbKernel by doxygen 1.4.7