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 fMatrix = new Double_t[fNelem];
64 memcpy(fMatrix, rhs.fMatrix, fNelem * sizeof(Double_t));
65 }
66 return *this;
67}
68
69//_____________________________________________________________________________
70void TGDMLMatrix::Set(size_t r, size_t c, Double_t a)
71{
72 assert(r < fNrows && c < fNcols);
73 fMatrix[fNcols*r+c] = a;
74}
75
76//_____________________________________________________________________________
77Double_t TGDMLMatrix::Get(size_t r, size_t c) const
78{
79 assert(r < fNrows && c < fNcols);
80 return fMatrix[fNcols*r+c];
81}
82
83//_____________________________________________________________________________
85{
86// Print info about this matrix
87 printf("*** matrix: %-20s coldim = %zu rows = %zu\n", GetName(), fNcols, fNrows);
88 if (!fTitle.IsNull()) {
89 printf(" %s\n", fTitle.Data());
90 return;
91 }
92 for (size_t row = 0; row < fNrows; ++row) {
93 printf(" ");
94 for (size_t col = 0; col < fNcols; ++col) {
95 printf("%8.3g", Get(row, col));
96 }
97 printf("\n");
98 }
99}
ROOT::R::TRInterface & r
Definition: Object.C:4
#define c(i)
Definition: RSha256.hxx:101
double Double_t
Definition: RtypesCore.h:55
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:365
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:77
void Set(size_t r, size_t c, Double_t a)
Definition: TGDMLMatrix.cxx:70
Int_t fNelem
Definition: TGDMLMatrix.h:53
void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TGDMLMatrix.cxx:84
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