BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/RootEventData/include/RootEventData/SimMatr.h
Go to the documentation of this file.
1#ifndef SimMatr_h
2#define SimMatr_h
3
4namespace SimMat {
5
6 // packing of symmetric matrices 'sm' in one-dimensional array 'pac_sm'
7 // 'pac_sm' MUST be large enough to receive n*(n+1)/2 elements
8 template <class T> inline void pack2d( int n, const T* sm, T* pac_sm ) {
9 for ( int i = 0; i < n; i++ )
10 {
11 for ( int j = 0; j <= i; j++ )
12 {
13 int k = i * ( i + 1 ) / 2 + j;
14 pac_sm[k] = sm[i * n + j];
15 }
16 }
17 }
18
19 // for a given i and j in 'sm' returns the index in 'pac_sm'
20 inline int get_idx( int i, int j ) {
21 return ( i > j ) ? i * ( i + 1 ) / 2 + j : j * ( j + 1 ) / 2 + i;
22 }
23
24 // for a given i and j return 'sm[i][j]'
25 template <class T> inline T get_element( const T* pac_sm, int i, int j ) {
26 return pac_sm[get_idx( i, j )];
27 }
28
29 // unpacks the 'pac_sm' in the symmetric matrix 'sm'
30 // 'sm' MUST be large enough to receive n*n elements
31 template <class T> inline void unpack2d( int n, T* sm, const T* pac_sm ) {
32 for ( int i = 0; i < n; i++ )
33 {
34 for ( int j = 0; j <= i; j++ )
35 {
36 int k = i * ( i + 1 ) / 2 + j;
37 sm[i * n + j] = sm[i + j * n] = pac_sm[k];
38 }
39 }
40 }
41
42} // namespace SimMat
43#endif
const Int_t n
T get_element(const T *pac_sm, int i, int j)
void pack2d(int n, const T *sm, T *pac_sm)
void unpack2d(int n, T *sm, const T *pac_sm)