ATLAS Offline Software
Loading...
Searching...
No Matches
Trk::AlSymMat Class Reference

contains the implementation for handling symmetric matrices in triangular representation More...

#include <AlSymMat.h>

Inheritance diagram for Trk::AlSymMat:
Collaboration diagram for Trk::AlSymMat:

Public Member Functions

 AlSymMat (long int)
 AlSymMat ()
 AlSymMat (const AlSymMat &)
 AlSymMat (const AlSpaMat &)
AlSymMatoperator= (const AlSpaMat &)
 ~AlSymMat ()
virtual AlSymMatoperator= (const double &)
virtual AlSymMatoperator= (const AlSymMat &)
virtual AlSymMatoperator= (const AlMat &)
virtual AlSymMat operator+ (const AlSymMat &) const
virtual AlSymMatoperator+= (const AlSymMat &)
virtual AlSymMat operator- (const AlSymMat &) const
virtual AlSymMatoperator-= (const AlSymMat &)
virtual AlMat operator* (const AlSymMat &) const
virtual AlVec operator* (const AlVec &) const
virtual AlMat operator* (const AlMat &) const
virtual AlSymMat operator* (const double &) const
virtual AlSymMatoperator*= (const double &)
virtual void reSize (long int Nnew) override final
virtual double & elemr (long int, long int) override final
virtual double elemc (long int, long int) const override final
virtual int invert () override final
virtual void RemoveModule (int) override final
virtual void RemoveAlignPar (int, int) override final
virtual int RemoveCollsRows (std::vector< int >) override final
virtual void SetPathBin (const std::string &) override final
virtual void SetPathTxt (const std::string &) override final
virtual StatusCode Write (const std::string &, bool, bool, double, float) override final
virtual StatusCode CheckMatVersion (const std::string &, bool &) override final
virtual StatusCode Read (const std::string &, int &, bool &, float &) override final
virtual StatusCode ReadProjected (const std::string &, int &, bool &, float &) override final
virtual int diagonalize (char jobz, AlVec &w, AlMat &z) override final
virtual double determinant () override final
const double * ptrData () const
double * ptrData ()
const std::string & pathBin () const
const std::string & pathTxt () const
virtual TMatrixDSparsemakeTMatrix () override final
AlSymMatBase_row operator[] (long int)
AlSymMatBase_row_const operator[] (long int) const
long int nrow () const
long int ncol () const
long int size () const
int matrix_type () const
const datamapptrMap () const

Protected Member Functions

long int elem (long int, long int) const
void copy (const AlSymMat &m)
void copy (const AlSpaMat &m)
void copy (const AlMat &m)

Protected Attributes

double * m_ptr_data = nullptr
std::string m_pathbin
std::string m_pathtxt
int m_matrix_type = 0
datamap m_ptr_map
long int m_size = 0
long int m_nele = 0

Detailed Description

contains the implementation for handling symmetric matrices in triangular representation

Definition at line 26 of file AlSymMat.h.

Constructor & Destructor Documentation

◆ AlSymMat() [1/4]

Trk::AlSymMat::AlSymMat ( long int N)

Definition at line 56 of file AlSymMat.cxx.

57 : AlSymMatBase(N)
58 , m_ptr_data(new double[m_nele])
59 , m_pathbin("./")
60 , m_pathtxt("./")
61{
62 m_matrix_type = 1;
63
64 double* p = m_ptr_data + m_nele;
65 while (p > m_ptr_data) *(--p) = 0.;
66
67}
double * m_ptr_data
Definition AlSymMat.h:87
std::string m_pathbin
Definition AlSymMat.h:89
std::string m_pathtxt
Definition AlSymMat.h:90

◆ AlSymMat() [2/4]

Trk::AlSymMat::AlSymMat ( )

Definition at line 46 of file AlSymMat.cxx.

47 : m_ptr_data(nullptr)
48 , m_pathbin("./")
49 , m_pathtxt("./")
50{
51 m_matrix_type = 1;
52}

◆ AlSymMat() [3/4]

Trk::AlSymMat::AlSymMat ( const AlSymMat & m)

Definition at line 70 of file AlSymMat.cxx.

71 : AlSymMatBase(m)
72 , m_ptr_data(new double[m_nele])
73 , m_pathbin(m.m_pathbin)
74 , m_pathtxt(m.m_pathtxt)
75{
76 m_matrix_type = 1;
77 m_size = m.size();
78 m_nele = m.m_nele;
79
80 copy(m);
81}
void copy(const AlSymMat &m)
Definition AlSymMat.cxx:115

◆ AlSymMat() [4/4]

Trk::AlSymMat::AlSymMat ( const AlSpaMat & m)

Definition at line 84 of file AlSymMat.cxx.

85 : AlSymMatBase (m.size()),
86 m_ptr_data (new double[m_nele]),
87 m_pathbin (m.pathBin()),
88 m_pathtxt (m.pathTxt())
89{
91}

◆ ~AlSymMat()

Trk::AlSymMat::~AlSymMat ( )

Definition at line 108 of file AlSymMat.cxx.

109{
110 if( m_ptr_data != nullptr ) delete [] m_ptr_data;
111 //ptr_map.clear();
112}

Member Function Documentation

◆ CheckMatVersion()

StatusCode Trk::AlSymMat::CheckMatVersion ( const std::string & filename,
bool & StdUnits )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 654 of file AlSymMat.cxx.

655{
656 std::ifstream inmat((filename).c_str(), std::ios::binary);
657 if(inmat.fail())
658 return StatusCode::FAILURE;
659
660 int32_t msiz=0;
661 inmat.read(charAddress(msiz), sizeof (msiz));
662
663 float version=0.0;
664 inmat.read(charAddress(version), sizeof (version));
665
666 StdUnits = version>=2.0;
667
668 inmat.close();
669
670 // std::cout << "AlSymMat::StdUnits: " << StdUnits << std::endl;
671
672 return StatusCode::SUCCESS;
673}

◆ copy() [1/3]

void Trk::AlSymMat::copy ( const AlMat & m)
protected

Definition at line 146 of file AlSymMat.cxx.

147{
148 // copy the lower triangle only!
149 int si = size();
150 if( si != m.nrow() || si != m.ncol() ) {
151 throw std::range_error("AlSymMat::copy: sizes do not match!" );
152 }
153
154 for( int i=0; i<si; i++ )
155 for( int j=0; j<=i; j++ )
156 elemr(i, j) = m.elemc(i, j);
157}
long int size() const
virtual double & elemr(long int, long int) override final
Definition AlSymMat.cxx:790

◆ copy() [2/3]

void Trk::AlSymMat::copy ( const AlSpaMat & m)
protected

Definition at line 128 of file AlSymMat.cxx.

129{
130 //
131 if( size() != m.size()) {
132 throw std::range_error( "AlSymMat::copy: size do not match!" );
133 }
134
135 (*this) = 0.;
136 //Convert Storage System
137 long int i, j;
138 for (const datamap::value_type& p : *m.ptrMap()) {
139 m.elem(p.first, i, j);
140 AlSymMat::elemr(i,j) = p.second;
141 }
142
143 }

◆ copy() [3/3]

void Trk::AlSymMat::copy ( const AlSymMat & m)
protected

Definition at line 115 of file AlSymMat.cxx.

116{
117 // this one implements the fast copy alg.
118 if( size() != m.size()) {
119 throw std::range_error( "AlSymMat::copy: size do not match!" );
120 }
121
122 double * p = m_ptr_data + m_nele;
123 double* r = m.m_ptr_data + m_nele;
124 while (p > m_ptr_data) *(--p) = *(--r);
125}
int r
Definition globals.cxx:22

◆ determinant()

double Trk::AlSymMat::determinant ( )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 392 of file AlSymMat.cxx.

393{
394 double deter = 1.;
395
396 // get determinant using LU decomposition + Crout algorithm
397 AlMat A(size(),size());
398 A = (*this);
399
400 double AMAX,DUM,SUM;
401 //int CODE;
402 double TINY = 1.E-20;
403 double D;
404 int N=size();
405
406 D=1.; //CODE=0;
407
408 for(int I=0;I<N;I++) {
409 AMAX=0.;
410 for(int J=0;J<N;J++)
411 if (fabs(A[I][J])>AMAX)
412 AMAX=fabs(A[I][J]);
413 if(AMAX<TINY) {
414// CODE = 1; // matrix is singular
415 return 0;
416 }
417 }
418
419 for(int J=0;J<N;J++) {
420 for(int I=0;I<N;I++) {
421 SUM = A[I][J];
422 int KMAX = (I<J)?I:J;
423 for(int K=0;K<KMAX;K++)
424 SUM = SUM - A[I][K]*A[K][J];
425 A[I][J]=SUM;
426 }
427
428 // find pivot and exchange if necessary
429 int IMAX=J;
430 for (int I=J+1;I<N;I++) {
431 if(fabs(A[I][J])>fabs(A[IMAX][J])) IMAX=I;
432 }
433
434 if(IMAX!=J) {
435 for(int K=0;K<N;K++) {
436 DUM=A[IMAX][K];
437 A[IMAX][K]=A[J][K];
438 A[J][K]=DUM;
439 }
440 D=-D;
441 }
442
443 if(J<N && (fabs(A[J][J])>TINY)) {
444 DUM = 1./ A[J][J];
445 for(int I=J+1;I<N;I++) A[I][J] = A[I][J]*DUM;
446 }
447 }
448
449 deter=deter*D;
450 for(int I=0;I<N;I++)
451 deter = deter*A[I][I];
452
453 return deter;
454}
#define I(x, y, z)
Definition MD5.cxx:116

◆ diagonalize()

int Trk::AlSymMat::diagonalize ( char jobz,
AlVec & w,
AlMat & z )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 457 of file AlSymMat.cxx.

458{
459 int info = 0;
460 char uplo = 'U';
461 int N = size();
462 double * work = new double[3*N];
463
464 double * ap = m_ptr_data;
465
466 dspev_(&jobz, &uplo, &N, ap, w.ptrData(), z.ptrData(), &N, work, &info);
467
468 delete [] work;
469
470 return info;
471}
void dspev_(char *, char *, const int *, double *, double *, double *, const int *, double *, int *)
@ z
global position (cartesian)
Definition ParamDefs.h:57

◆ elem()

long int Trk::AlSymMat::elem ( long int i,
long int j ) const
inlineprotected

Definition at line 96 of file AlSymMat.h.

96 {
97#ifdef _DEBUG
98 if( i<0 ) { throw std::out_of_range( "AlSymMat::elem: Index 1 < zero! " ); };
99 if( i>=size() ) { throw std::out_of_range( "AlSymMat::elem: Index 1 too large! " ); };
100 if( j<0 ) { throw std::out_of_range( "AlSymMat::elem: Index 2 < zero! " ); };
101 if( j>=size() ) { throw std::out_of_range( "AlSymMat::elem: Index 2 too large! " ); };
102#endif
103 if( j<=i ) {
104 return ((i+1)*i/2+j);
105 }
106 else {
107 return ((j+1)*j/2+i);
108 };
109}

◆ elemc()

double Trk::AlSymMat::elemc ( long int i,
long int j ) const
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 813 of file AlSymMat.cxx.

814{
815#ifdef _DEBUG
816 if( i<0 ) {
817 throw std::underflow_error( "AlSymMat::elemc: Index 1 < zero!" );
818 }
819 if( i>=size() ) {
820 throw std::overflow_error( "AlSymMat::elemc: Index 1 too large!" );
821 }
822 if( j<0 ) {
823 throw std::underflow_error( "AlSymMat::elemc: Index 2 < zero!" );
824 }
825 if( j>=size() ) {
826 throw std::overflow_error( "AlSymMat::elemc: Index 2 too large!" );
827 }
828#endif
829 if( j<=i )
830 return *(m_ptr_data+(i+1)*i/2+j);
831
832 return *(m_ptr_data+(j+1)*j/2+i);
833}

◆ elemr()

double & Trk::AlSymMat::elemr ( long int i,
long int j )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 790 of file AlSymMat.cxx.

791{
792#ifdef _DEBUG
793 if( i<0 ) {
794 throw std::underflow_error( "AlSymMat::elemr: Index 1 < zero!" );
795 }
796 if( i>=size() ) {
797 throw std::overflow_error( "AlSymMat::elemr: Index 1 too large!" );
798 }
799 if( j<0 ) {
800 throw std::underflow_error( "AlSymMat::elemr: Index 2 < zero!" );
801 }
802 if( j>=size() ) {
803 throw std::overflow_error( "AlSymMat::elemr: Index 2 too large!" );
804 }
805#endif
806 if( j<=i )
807 return *(m_ptr_data+(i+1)*i/2+j);
808
809 return *(m_ptr_data+(j+1)*j/2+i);
810}

◆ invert()

int Trk::AlSymMat::invert ( )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 363 of file AlSymMat.cxx.

364{
365 // add a protection to detect singular matrices:
366 // double det = (*this).determinant();
367 // double detcut = 1.E-20;
368
369 // if (fabs(det)>detcut) {
370
371 int ierr = 0;
372 char uplo = 'U';
373 int N = size();
374 int * ipiv = new int[N];
375 double * work = new double[N];
376 double * mx = m_ptr_data;
377
378 dsptrf_(&uplo, &N, mx, ipiv, &ierr);
379
380 dsptri_(&uplo, &N, mx, ipiv, work, &ierr);
381
382 delete [] ipiv;
383 delete [] work;
384
385 // } else {
386 // ierr=999;
387 // }
388 return ierr;
389}
void dsptrf_(char *, const int *, double *, int *, int *)
void dsptri_(char *, const int *, double *, int *, double *, int *)

◆ makeTMatrix()

TMatrixDSparse * Trk::AlSymMat::makeTMatrix ( )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 836 of file AlSymMat.cxx.

836 {
837
838 int si = size();
839
840 int nnz(0);
841
842 for( int i=0; i<si; i++ )
843 for( int j=0; j<=i; j++ )
844 if( *(m_ptr_data+(i+1)*i/2+j) != 0 )
845 ++nnz;
846
847
848 int *irow = new int[nnz];
849 int *icol = new int[nnz];
850 double *val = new double[nnz];
851 int n(0);
852
853 for (int i=0;i<si;i++) {
854 for (int j=0;j<=i;j++) {
855 if ( *(m_ptr_data+(i+1)*i/2+j) != 0.) {
856 irow[n] = i;
857 icol[n] = j;
858 val[n] = *(m_ptr_data+(i+1)*i/2+j);
859 ++n;
860 }
861 }
862 }
863
864
865 TMatrixDSparse* myTMatrix = new TMatrixDSparse(0,si-1,0,si-1);
866 myTMatrix->SetMatrixArray(nnz,irow,icol,val);
867
868 delete [] irow;
869 delete [] icol;
870 delete [] val;
871
872
873 return myTMatrix;
874
875}
class TMatrixTSparse< double > TMatrixDSparse
Definition AlSpaMat.h:14

◆ matrix_type()

int Trk::AlSymMatBase::matrix_type ( ) const
inlineinherited

Definition at line 148 of file AlSymMatBase.h.

148{ return m_matrix_type; }

◆ ncol()

long int Trk::AlSymMatBase::ncol ( ) const
inlineinherited

Definition at line 147 of file AlSymMatBase.h.

147{ return m_size; }

◆ nrow()

long int Trk::AlSymMatBase::nrow ( ) const
inlineinherited

Definition at line 146 of file AlSymMatBase.h.

146{ return m_size; }

◆ operator*() [1/4]

AlMat Trk::AlSymMat::operator* ( const AlMat & m) const
virtual

Definition at line 293 of file AlSymMat.cxx.

294{
295 if( size() != m.nrow() ) {
296 throw std::range_error("AlSymMat::operator*: size do not match!" );
297 }
298
299 AlMat b( size(), m.ncol());
300
301 double x;
302 long int k, ii;
303 long int siz(size()), nco(m.ncol());
304
305 // optimised version of matrix product:
306 for( long int i=0; i<siz; i++ )
307 for( long int j=0; j<nco; j++ ) {
308 x = 0.;
309 ii = (i+1)*i/2;
310 for( k=0; k<i; k++)
311 x += (*(m_ptr_data+ii+k))*m.elemc(k,j);
312 for( k=i; k<siz; k++)
313 x += (*(m_ptr_data+(k+1)*k/2+i))*m.elemc(k,j);
314 b.elemr(i,j) = x;
315 }
316
317 return b;
318}
@ x
Definition ParamDefs.h:55

◆ operator*() [2/4]

AlMat Trk::AlSymMat::operator* ( const AlSymMat & m) const
virtual

Definition at line 255 of file AlSymMat.cxx.

256{
257 if( size() != m.size() ) {
258 throw std::range_error( "AlSymMat::operator*: size do not match!" );
259 }
260
261 AlMat b( size(), size());
262 double x;
263 long int k, l, n, ii, jj;
264 long int siz(size());
265
266 // optimised version of symmetric matrix product:
267 for( long int i=0; i<siz; i++ )
268 for( long int j=0; j<siz; j++ ) {
269 x = 0.;
270 l = i < j ? i : j;
271 n = i < j ? j : i;
272 ii = (i+1)*i/2;
273 jj = (j+1)*j/2;
274 for( k=0; k<l; k++)
275 x += (*(m_ptr_data+ii+k))*(*(m.m_ptr_data+jj+k));
276 if( i<j ) {
277 for( k=l; k<n; k++)
278 x += (*(m_ptr_data+(k+1)*k/2+i))*(*(m.m_ptr_data+jj+k));
279 }
280 else {
281 for( k=l; k<n; k++)
282 x += (*(m_ptr_data+ii+k))*(*(m.m_ptr_data+(k+1)*k/2+j));
283 }
284 for( k=n; k<siz; k++)
285 x += (*(m_ptr_data+(k+1)*k/2+i))*(*(m.m_ptr_data+(k+1)*k/2+j));
286 b.elemr(i,j) = x;
287 }
288
289 return b;
290}
l
Printing final latex table to .tex output file.

◆ operator*() [3/4]

AlVec Trk::AlSymMat::operator* ( const AlVec & v) const
virtual

Definition at line 321 of file AlSymMat.cxx.

322{
323 if( size() != v.size() ) {
324 throw std::range_error( "AlSymMat::operator*: size do not match! " );
325 }
326
327 AlVec b(size());
328
329 long int ii;
330
331 for( long int i=0; i<size(); i++ ) {
332 ii = (i+1)*i/2;
333 for( long int j=0; j<i; j++ )
334 b[i] += (*(m_ptr_data+ii+j))*v[j];
335 for( long int j=i; j<size(); j++ )
336 b[i] += (*(m_ptr_data+(j+1)*j/2+i))*v[j];
337 }
338
339 return b;
340}
@ v
Definition ParamDefs.h:78

◆ operator*() [4/4]

AlSymMat Trk::AlSymMat::operator* ( const double & d) const
virtual

Definition at line 352 of file AlSymMat.cxx.

353{
354 AlSymMat a(size());
355 double * p = m_ptr_data + m_nele;
356 double * q = a.m_ptr_data + m_nele;
357 while (p > m_ptr_data) *(--q) = (*(--p))*d;
358
359 return a;
360}
static Double_t a
AlSymMat(long int)
Definition AlSymMat.cxx:56

◆ operator*=()

AlSymMat & Trk::AlSymMat::operator*= ( const double & d)
virtual

Definition at line 343 of file AlSymMat.cxx.

344{
345 double * p = m_ptr_data + m_nele;
346 while (p > m_ptr_data) *(--p) *= d;
347
348 return *this;
349}

◆ operator+()

AlSymMat Trk::AlSymMat::operator+ ( const AlSymMat & m) const
virtual

Definition at line 195 of file AlSymMat.cxx.

196{
197 if( size() != m.size()) {
198 throw std::range_error( "AlSymMat::operator+: size do not match!" );
199 }
200
201 AlSymMat b(size());
202 double * p = m_ptr_data + m_nele;
203 double * q = m.m_ptr_data + m_nele;
204 double * r = b.m_ptr_data + m_nele;
205 while (p > m_ptr_data) *(--r) = (*(--p))+(*(--q));
206
207 return b;
208}

◆ operator+=()

AlSymMat & Trk::AlSymMat::operator+= ( const AlSymMat & m)
virtual

Definition at line 211 of file AlSymMat.cxx.

212{
213 if( size() != m.size()){
214 throw std::range_error( "AlSymMat::operator+=: size do not match!" );
215 }
216
217 double * p = m_ptr_data + m_nele;
218 double * q = m.m_ptr_data + m_nele;
219 while (p > m_ptr_data) *(--p) += *(--q);
220
221 return *this;
222}

◆ operator-()

AlSymMat Trk::AlSymMat::operator- ( const AlSymMat & m) const
virtual

Definition at line 225 of file AlSymMat.cxx.

226{
227 if( size() != m.size()) {
228 throw std::range_error( "AlSymMat::operator-: size do not match!" );
229 }
230
231 AlSymMat b(size());
232 double * p = m_ptr_data + m_nele;
233 double * q = m.m_ptr_data + m_nele;
234 double * r = b.m_ptr_data + m_nele;
235 while (p > m_ptr_data) *(--r) = (*(--p))-(*(--q));
236
237 return b;
238}

◆ operator-=()

AlSymMat & Trk::AlSymMat::operator-= ( const AlSymMat & m)
virtual

Definition at line 241 of file AlSymMat.cxx.

242{
243 if( size() != m.size()) {
244 throw std::range_error( "AlSymMat::operator-=: size do not match!" );
245 }
246
247 double * p = m_ptr_data + m_nele;
248 double * q = m.m_ptr_data + m_nele;
249 while (p > m_ptr_data) *(--p) -= *(--q);
250
251 return *this;
252}

◆ operator=() [1/4]

AlSymMat & Trk::AlSymMat::operator= ( const AlMat & m)
virtual

Definition at line 173 of file AlSymMat.cxx.

174{
175 if( m.nrow() != m.ncol() ) {
176 throw std::range_error( "AlSymMat::operator=: a squared matrix is required!" );
177 }
178
179 reSize(m.nrow());
180 copy(m);
181
182 return *this;
183}
virtual void reSize(long int Nnew) override final
Definition AlSymMat.cxx:769

◆ operator=() [2/4]

AlSymMat & Trk::AlSymMat::operator= ( const AlSpaMat & m)

Definition at line 94 of file AlSymMat.cxx.

95{
96 m_matrix_type = 1;
97 m_size = m.size();
98 m_nele = m_size*(m_size+1)/2;
99 m_pathbin = m.pathBin();
100 m_pathtxt = m.pathTxt();
101
102 m_ptr_data = new double[m_nele];
103 copy(m);
104 return *this;
105}

◆ operator=() [3/4]

AlSymMat & Trk::AlSymMat::operator= ( const AlSymMat & m)
virtual

Definition at line 160 of file AlSymMat.cxx.

161{
162 if (this==&m)
163 return *this;
164
165 if ( m_ptr_data != m.m_ptr_data ) {
166 reSize(m.size());
167 copy(m);
168 }
169 return *this;
170}

◆ operator=() [4/4]

AlSymMat & Trk::AlSymMat::operator= ( const double & d)
virtual

Definition at line 186 of file AlSymMat.cxx.

187{
188 double * p = m_ptr_data + m_nele;
189 while (p > m_ptr_data) *(--p) = d;
190
191 return *this;
192}

◆ operator[]() [1/2]

AlSymMatBase::AlSymMatBase_row Trk::AlSymMatBase::operator[] ( long int r)
inlineinherited

Definition at line 109 of file AlSymMatBase.h.

109 {
110 AlSymMatBase_row b(*this,r);
111 return b;
112}

◆ operator[]() [2/2]

AlSymMatBase::AlSymMatBase_row_const Trk::AlSymMatBase::operator[] ( long int r) const
inlineinherited

Definition at line 114 of file AlSymMatBase.h.

114 {
115 const AlSymMatBase_row_const b(*this,r);
116 return b;
117}

◆ pathBin()

const std::string & Trk::AlSymMat::pathBin ( ) const
inline

Definition at line 119 of file AlSymMat.h.

119 {
120 return m_pathbin;
121}

◆ pathTxt()

const std::string & Trk::AlSymMat::pathTxt ( ) const
inline

Definition at line 123 of file AlSymMat.h.

123 {
124 return m_pathtxt;
125}

◆ ptrData() [1/2]

double * Trk::AlSymMat::ptrData ( )
inline

Definition at line 115 of file AlSymMat.h.

115 {
116 return m_ptr_data;
117}

◆ ptrData() [2/2]

const double * Trk::AlSymMat::ptrData ( ) const
inline

Definition at line 111 of file AlSymMat.h.

111 {
112 return m_ptr_data;
113}

◆ ptrMap()

const datamap * Trk::AlSymMatBase::ptrMap ( ) const
inlineinherited

Definition at line 149 of file AlSymMatBase.h.

149{ return &m_ptr_map; }

◆ Read()

StatusCode Trk::AlSymMat::Read ( const std::string & filename,
int & dofs,
bool & triang,
float & version )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 676 of file AlSymMat.cxx.

678{
679 bool stdUnits = true;
680 if (StatusCode::SUCCESS != CheckMatVersion(m_pathbin+filename, stdUnits))
681 return StatusCode::FAILURE;
682
683 // std::cout << "AlSymMat::StdUnits: " << stdUnits << std::endl;
684
685 std::ifstream inmat((m_pathbin+filename).c_str(), std::ios::binary);
686 if(inmat.fail())
687 return StatusCode::FAILURE;
688
689 int32_t msiz=0;
690 inmat.read(charAddress(msiz), sizeof (msiz));
691 dofs = abs(msiz);
692 m_size = abs(msiz);
693
694 if (stdUnits)
695 inmat.read(charAddress(version), sizeof (version));
696
697 double melem=0;
698
699 if(msiz>0) { // square format
700 triang=false;
701 for(int i=0; i<msiz; i++) {
702 for(int j=0; j<msiz; j++) {
703 inmat.read(charAddress(melem), sizeof (melem));
704 if( i>=j )
705 *(m_ptr_data+(i+1)*i/2+j) = melem;
706 }
707 }
708 }
709 else { // triangular format
710 triang=true;
711 msiz = (-1)*msiz;
712 // std::cout << "msiz=" << msiz << std::endl;
713 for( int i=0; i<msiz; i++) {
714 for( int j=0; j<=i; j++) {
715 inmat.read(charAddress(melem), sizeof (melem));
716 *(m_ptr_data+(i+1)*i/2+j) = melem;
717 }
718 }
719 }
720
721 inmat.close();
722 return StatusCode::SUCCESS;
723}
virtual StatusCode CheckMatVersion(const std::string &, bool &) override final
Definition AlSymMat.cxx:654

◆ ReadProjected()

StatusCode Trk::AlSymMat::ReadProjected ( const std::string & filename,
int & dofs,
bool & triang,
float & version )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 726 of file AlSymMat.cxx.

728{
729 std::ifstream inmat((m_pathbin+filename).c_str(), std::ios::binary);
730 if(inmat.fail())
731 return StatusCode::FAILURE;
732
733 int32_t msiz=0;
734 inmat.read(charAddress(msiz), sizeof (msiz));
735 dofs = abs(msiz);
736 m_size = abs(msiz);
737
738 inmat.read(charAddress(version), sizeof (version));
739
740 double melem=0;
741
742 if(msiz>0) { // square format
743 triang=false;
744 for(int i=0; i<msiz; i++) {
745 for(int j=0; j<msiz; j++) {
746 inmat.read(charAddress(melem), sizeof (melem));
747 if( i>=j )
748 *(m_ptr_data+(i+1)*i/2+j) = melem;
749 }
750 }
751 }
752 else { // triangular format
753 triang=true;
754 msiz = (-1)*msiz;
755 // std::cout << "msiz=" << msiz << std::endl;
756 for( int i=0; i<msiz; i++) {
757 for( int j=0; j<=i; j++) {
758 inmat.read(charAddress(melem), sizeof (melem));
759 *(m_ptr_data+(i+1)*i/2+j) = melem;
760 }
761 }
762 }
763
764 inmat.close();
765 return StatusCode::SUCCESS;
766}

◆ RemoveAlignPar()

void Trk::AlSymMat::RemoveAlignPar ( int index,
int control )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 539 of file AlSymMat.cxx.

540{
541 // Dynamic shiftRow
542 int shiftRow = 1;
543 int counterRow = 0;
544
545 // Dynamic shiftCol
546 int shiftCol;
547 int counterCol = 0;
548
549 index = index-control;
550
551 for(int row=index; row<(size()-shiftRow); row++) {
552
553 shiftCol = 0;
554 counterCol = 0;
555
556 for(int col=0; col<row+1; col++) {
557
558 if (col==index) {
559 shiftCol = 1;
560 counterCol=0;
561 }
562
563 *(m_ptr_data+elem(row,col))=*(m_ptr_data+elem(row+shiftRow,col+shiftCol));
564
565 counterCol++;
566 if (counterCol==5-control) {
567 counterCol=0;
568 shiftCol++;
569 }
570 }
571
572 counterRow++;
573 if (counterRow==5-control) {
574 counterRow=0;
575 shiftRow++;
576 }
577 }
578}
long int elem(long int, long int) const
Definition AlSymMat.h:96
str index
Definition DeMoScan.py:362
row
Appending html table to final .html summary file.

◆ RemoveCollsRows()

int Trk::AlSymMat::RemoveCollsRows ( std::vector< int > indices)
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 497 of file AlSymMat.cxx.

498{
499 int n = indices.size();
500 if (n==0) {
501 return m_size;
502 }
503 if (n>m_size) {
504 throw std::range_error("Vector of indices larger than matrix size.");
505 }
506
507 // first sort the list of indices descending
508 // maybe not the fastest way to do that but it works
509 for (int i=0;i<n-1;i++)
510 for (int j=i+1; j<n; j++)
511 if (indices[j] > indices[i]) {
512 int itmp = indices[i];
513 indices[i] = indices[j];
514 indices[j] = itmp;
515 }
516
517 // remove rows and columns starting from largest indices
518 for (int i=0;i<n;i++) {
519 int index = indices[i];
520 if (index > m_size-1) {
521 throw std::out_of_range("AlSymMat::RemoveCollsRows: Index goes beyond matrix.");
522 }
523
524 for (int j=index; j<m_size-1; j++)
525 for (int col=0; col<=j; col++)
526 if(col<index)
527 *(m_ptr_data+elem(j,col)) = *(m_ptr_data+elem(j+1,col));
528 else
529 *(m_ptr_data+elem(j,col)) = *(m_ptr_data+elem(j+1,col+1));
530
531 m_size--;
532 }
533
534 return m_size;
535}
std::pair< long int, long int > indices

◆ RemoveModule()

void Trk::AlSymMat::RemoveModule ( int index)
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 475 of file AlSymMat.cxx.

476{
477 const int shift=6;
478
479 if((shift*index)<size() && index>=0) {
480 for(int row=(shift*index); row<(size()-shift); row+=shift) {
481 for(int k=0; k<shift; k++) {
482 for(int col=0; col<row+k+1; col++) {
483 // cout << "(" << row+k << "," << col << ") -> " << *(m_ptr_data+elem(row+k,col)) << endl;
484
485 if(col<shift*index)
486 *(m_ptr_data+elem(row+k,col))=*(m_ptr_data+elem(row+k+shift,col));
487 else
488 *(m_ptr_data+elem(row+k,col))=*(m_ptr_data+elem(row+k+shift,col+shift));
489 }
490 }
491 }
492 }
493}

◆ reSize()

void Trk::AlSymMat::reSize ( long int Nnew)
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 769 of file AlSymMat.cxx.

770{
771 if ( Nnew != size() ) {
772 double * p = m_ptr_data;
773 long int ii;
774
775 m_nele = Nnew*(Nnew+1)/2;
776 m_ptr_data = new double[m_nele];
777 long int Size_old = size();
778 m_size = Nnew;
779 long int k = size() <= Size_old ? size() : Size_old;
780 for( long int i=0; i<k; i++ ) {
781 ii = (i+1)*i/2;
782 for( long int j=0; j<=i; j++ )
783 *(m_ptr_data+ii+j) = *(p+ii+j);
784 }
785 delete [] p;
786 }
787}

◆ SetPathBin()

void Trk::AlSymMat::SetPathBin ( const std::string & path)
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 581 of file AlSymMat.cxx.

582{
583 m_pathbin.assign(path);
584}

◆ SetPathTxt()

void Trk::AlSymMat::SetPathTxt ( const std::string & path)
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 587 of file AlSymMat.cxx.

588{
589 m_pathtxt.assign(path);
590}

◆ size()

long int Trk::AlSymMatBase::size ( ) const
inlineinherited

Definition at line 145 of file AlSymMatBase.h.

145{ return m_size; }

◆ Write()

StatusCode Trk::AlSymMat::Write ( const std::string & filename,
bool binary,
bool square,
double ,
float version )
finaloverridevirtual

Implements Trk::AlSymMatBase.

Definition at line 593 of file AlSymMat.cxx.

595{
596 std::ofstream outmat;
597
598 int32_t msizz = square ? size() : (-1)*size();
599
600 if(binary) {
601 outmat.open((m_pathbin+filename).c_str(), std::ios::binary);
602 if(outmat.fail())
603 return StatusCode::FAILURE;
604 // if triangular, change size sign to distinguish
605 // from square format
606 outmat.write(charAddress(msizz), sizeof (msizz));
607 outmat.write(charAddress(version), sizeof (version));
608 }
609 else {
610 outmat.open((m_pathtxt+filename).c_str());
611 if(outmat.fail())
612 return StatusCode::FAILURE;
613 outmat.setf(std::ios::fixed);
614 outmat.setf(std::ios::showpoint);
615 outmat.precision(3);
616 outmat << "msizz: " << std::setw(6) << msizz << std::endl;
617 outmat << "AlSymMat version: " << std::setw(6) << version << std::endl;
618 }
619
620 double melem=0;
621
622 if (!square) {
623 for( int i=0; i<size(); i++) {
624 for( int j=0; j<=i; j++) {
625 melem = *(m_ptr_data+(i+1)*i/2+j);
626 if(binary)
627 outmat.write(charAddress((melem)), sizeof (melem));
628 else
629 outmat << std::setw(14) << melem;
630 }
631 if(!binary)
632 outmat << std::endl;
633 }
634 }
635 else {
636 for( int i=0; i<size(); i++) {
637 for( int j=0; j<size(); j++) {
638 if(i>=j) melem = *(m_ptr_data+(i+1)*i/2+j);
639 else melem = *(m_ptr_data+(j+1)*j/2+i);
640 if(binary)
641 outmat.write(charAddress((melem)), sizeof (melem));
642 else
643 outmat << std::setw(14) << melem;
644 }
645 if(!binary)
646 outmat << std::endl;
647 }
648 }
649 outmat.close();
650 return StatusCode::SUCCESS;
651}

Member Data Documentation

◆ m_matrix_type

int Trk::AlSymMatBase::m_matrix_type = 0
protectedinherited

Definition at line 100 of file AlSymMatBase.h.

◆ m_nele

long int Trk::AlSymMatBase::m_nele = 0
protectedinherited

Definition at line 104 of file AlSymMatBase.h.

◆ m_pathbin

std::string Trk::AlSymMat::m_pathbin
protected

Definition at line 89 of file AlSymMat.h.

◆ m_pathtxt

std::string Trk::AlSymMat::m_pathtxt
protected

Definition at line 90 of file AlSymMat.h.

◆ m_ptr_data

double* Trk::AlSymMat::m_ptr_data = nullptr
protected

Definition at line 87 of file AlSymMat.h.

◆ m_ptr_map

datamap Trk::AlSymMatBase::m_ptr_map
protectedinherited

Definition at line 101 of file AlSymMatBase.h.

◆ m_size

long int Trk::AlSymMatBase::m_size = 0
protectedinherited

Definition at line 103 of file AlSymMatBase.h.


The documentation for this class was generated from the following files: