/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RootEventData/RootEventData-00-03-80/RootEventData/SimMatr.h

Go to the documentation of this file.
00001 #ifndef SimMatr_h
00002 #define SimMatr_h
00003 
00004 namespace SimMat {
00005 
00006 // packing of symmetric matrices 'sm' in one-dimensional array 'pac_sm'
00007 // 'pac_sm' MUST be large enough to receive n*(n+1)/2 elements
00008 template <class T>
00009 inline void pack2d(int n, const T* sm, T* pac_sm)
00010 {
00011   for(int i = 0; i < n; i++) {
00012      for(int j = 0; j <= i; j++) {
00013         int k = i*(i+1)/2 + j;
00014         pac_sm[k] = sm[i*n+j];
00015      }
00016   }
00017 }
00018 
00019 // for a given i and j in 'sm' returns the index in 'pac_sm' 
00020 inline int get_idx(int i,int j)
00021 {
00022   return (i>j) ? i*(i+1)/2 + j : j*(j+1)/2 + i;
00023 }
00024 
00025 // for a given i and j return 'sm[i][j]'
00026 template <class T>
00027 inline T get_element(const T* pac_sm,int i,int j)
00028 {
00029   return pac_sm[ get_idx(i,j) ];
00030 }
00031 
00032 // unpacks the 'pac_sm' in the symmetric matrix 'sm'
00033 // 'sm' MUST be large enough to receive n*n elements
00034 template <class T>
00035 inline void unpack2d(int n, T* sm, const T* pac_sm)
00036 {
00037   for(int i = 0; i < n; i++) {
00038      for(int j = 0; j <= i; j++) {
00039         int k = i*(i+1)/2 + j;
00040         sm[i*n+j] = sm[i+j*n] = pac_sm[k];
00041      }
00042   }
00043 }
00044 
00045 }
00046 #endif

Generated on Tue Nov 29 23:11:39 2016 for BOSS_7.0.2 by  doxygen 1.4.7