CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/RootEventData/bak_RootEventData-00-05-12/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
8template <class T>
9inline void pack2d(int n, const T* sm, T* pac_sm)
10{
11 for(int i = 0; i < n; i++) {
12 for(int j = 0; j <= i; j++) {
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'
20inline int get_idx(int i,int j)
21{
22 return (i>j) ? i*(i+1)/2 + j : j*(j+1)/2 + i;
23}
24
25// for a given i and j return 'sm[i][j]'
26template <class T>
27inline T get_element(const T* pac_sm,int i,int j)
28{
29 return pac_sm[ get_idx(i,j) ];
30}
31
32// unpacks the 'pac_sm' in the symmetric matrix 'sm'
33// 'sm' MUST be large enough to receive n*n elements
34template <class T>
35inline void unpack2d(int n, T* sm, const T* pac_sm)
36{
37 for(int i = 0; i < n; i++) {
38 for(int j = 0; j <= i; j++) {
39 int k = i*(i+1)/2 + j;
40 sm[i*n+j] = sm[i+j*n] = pac_sm[k];
41 }
42 }
43}
44
45}
46#endif
const Int_t n