Logo ROOT  
Reference Guide
TGDMLMatrix.cxx
Go to the documentation of this file.
1 // @(#)root/gdml:$Id$
2 // Author: Andrei Gheata 05/12/2018
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TGDMLMatrix
13 \ingroup Geometry_gdml
14  This class is used in the process of reading and writing the GDML "matrix" tag.
15 It represents a matrix with arbitrary number of rows and columns, storing elements
16 in double precision.
17 */
18 
19 #include "TGDMLMatrix.h"
20 
21 #include <cassert>
22 
24 
25 //_____________________________________________________________________________
26 TGDMLMatrix::TGDMLMatrix(const char *name, size_t rows,size_t cols)
27  : TNamed(name, "")
28 {
29 // Constructor
30  if ((rows <= 0) || (cols <= 0))
31  {
32  Fatal("TGDMLMatrix::TGDMLMatrix(rows,cols)", "Wrong number of rows/cols");
33  }
34  fNrows = rows;
35  fNcols = cols;
36  fNelem = rows * cols;
37  fMatrix = new Double_t[fNelem];
38 }
39 
40 //_____________________________________________________________________________
42  : TNamed(rhs), fNelem(rhs.fNelem), fNrows(rhs.fNrows), fNcols(rhs.fNcols), fMatrix(nullptr)
43 {
44 // Copy constructor
45  if (rhs.fMatrix)
46  {
47  fMatrix = new Double_t[fNelem];
48  memcpy(fMatrix, rhs.fMatrix, fNelem * sizeof(Double_t));
49  }
50 }
51 
52 //_____________________________________________________________________________
54 {
55 // Assignment
56  if (this == &rhs) { return *this; }
57  TNamed::operator=(rhs);
58  fNrows = rhs.fNrows;
59  fNcols = rhs.fNcols;
60  fNelem = fNrows * fNcols;
61  if (rhs.fMatrix)
62  {
63  delete [] fMatrix;
64  fMatrix = new Double_t[fNelem];
65  memcpy(fMatrix, rhs.fMatrix, fNelem * sizeof(Double_t));
66  }
67  return *this;
68 }
69 
70 //_____________________________________________________________________________
71 void TGDMLMatrix::Set(size_t r, size_t c, Double_t a)
72 {
73  assert(r < fNrows && c < fNcols);
74  fMatrix[fNcols*r+c] = a;
75 }
76 
77 //_____________________________________________________________________________
78 Double_t TGDMLMatrix::Get(size_t r, size_t c) const
79 {
80  assert(r < fNrows && c < fNcols);
81  return fMatrix[fNcols*r+c];
82 }
83 
84 //_____________________________________________________________________________
86 {
87 // Print info about this matrix
88  printf("*** matrix: %-20s coldim = %zu rows = %zu\n", GetName(), fNcols, fNrows);
89  if (!fTitle.IsNull()) {
90  printf(" %s\n", fTitle.Data());
91  return;
92  }
93  for (size_t row = 0; row < fNrows; ++row) {
94  printf(" ");
95  for (size_t col = 0; col < fNcols; ++col) {
96  printf("%8.3g", Get(row, col));
97  }
98  printf("\n");
99  }
100 }
c
#define c(i)
Definition: RSha256.hxx:119
TString::Data
const char * Data() const
Definition: TString.h:369
TNamed::operator=
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:51
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TGDMLMatrix::Print
void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TGDMLMatrix.cxx:85
TNamed::fTitle
TString fTitle
Definition: TNamed.h:39
TGDMLMatrix::TGDMLMatrix
TGDMLMatrix()
Definition: TGDMLMatrix.h:36
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TGDMLMatrix::fNrows
size_t fNrows
Definition: TGDMLMatrix.h:54
TGDMLMatrix::fNcols
size_t fNcols
Definition: TGDMLMatrix.h:55
a
auto * a
Definition: textangle.C:12
TNamed
Definition: TNamed.h:29
TGDMLMatrix::fMatrix
Double_t * fMatrix
Definition: TGDMLMatrix.h:56
Fatal
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition: TError.cxx:245
TGDMLMatrix::Set
void Set(size_t r, size_t c, Double_t a)
Definition: TGDMLMatrix.cxx:71
TGDMLMatrix
Definition: TGDMLMatrix.h:34
TGDMLMatrix::fNelem
Int_t fNelem
Definition: TGDMLMatrix.h:53
TString::IsNull
Bool_t IsNull() const
Definition: TString.h:407
Double_t
double Double_t
Definition: RtypesCore.h:59
name
char name[80]
Definition: TGX11.cxx:110
TGDMLMatrix.h
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
TGDMLMatrix::operator=
TGDMLMatrix & operator=(const TGDMLMatrix &rhs)
Definition: TGDMLMatrix.cxx:53
TGDMLMatrix::Get
Double_t Get(size_t r, size_t c) const
Definition: TGDMLMatrix.cxx:78