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.
15It represents a matrix with arbitrary number of rows and columns, storing elements
16in double precision.
17*/
18
19#include "TGDMLMatrix.h"
20
21#include <cassert>
22
24
25//_____________________________________________________________________________
26TGDMLMatrix::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; }
58 fNrows = rhs.fNrows;
59 fNcols = rhs.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//_____________________________________________________________________________
71void 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//_____________________________________________________________________________
78Double_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}
ROOT::R::TRInterface & r
Definition: Object.C:4
#define c(i)
Definition: RSha256.hxx:101
double Double_t
Definition: RtypesCore.h:57
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
void Fatal(const char *location, const char *msgfmt,...)
char name[80]
Definition: TGX11.cxx:109
This class is used in the process of reading and writing the GDML "matrix" tag.
Definition: TGDMLMatrix.h:34
size_t fNrows
Definition: TGDMLMatrix.h:54
TGDMLMatrix & operator=(const TGDMLMatrix &rhs)
Definition: TGDMLMatrix.cxx:53
Double_t Get(size_t r, size_t c) const
Definition: TGDMLMatrix.cxx:78
void Set(size_t r, size_t c, Double_t a)
Definition: TGDMLMatrix.cxx:71
Int_t fNelem
Definition: TGDMLMatrix.h:53
void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TGDMLMatrix.cxx:85
Double_t * fMatrix
Definition: TGDMLMatrix.h:56
size_t fNcols
Definition: TGDMLMatrix.h:55
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TString fTitle
Definition: TNamed.h:33
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:51
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
const char * Data() const
Definition: TString.h:364
Bool_t IsNull() const
Definition: TString.h:402
auto * a
Definition: textangle.C:12