Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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) : TNamed(name, "")
27{
28 // Constructor
29 if ((rows <= 0) || (cols <= 0)) {
30 Fatal("TGDMLMatrix::TGDMLMatrix(rows,cols)", "Wrong number of rows/cols");
31 }
32 fNrows = rows;
33 fNcols = cols;
34 fNelem = rows * cols;
35 fMatrix = new Double_t[fNelem];
36}
37
38//_____________________________________________________________________________
40 : TNamed(rhs), fNelem(rhs.fNelem), fNrows(rhs.fNrows), fNcols(rhs.fNcols), fMatrix(nullptr)
41{
42 // Copy constructor
43 if (rhs.fMatrix) {
44 fMatrix = new Double_t[fNelem];
45 memcpy(fMatrix, rhs.fMatrix, fNelem * sizeof(Double_t));
46 }
47}
48
49//_____________________________________________________________________________
51{
52 // Assignment
53 if (this == &rhs) {
54 return *this;
55 }
57 fNrows = rhs.fNrows;
58 fNcols = rhs.fNcols;
60 if (rhs.fMatrix) {
61 delete[] fMatrix;
62 fMatrix = new Double_t[fNelem];
63 memcpy(fMatrix, rhs.fMatrix, fNelem * sizeof(Double_t));
64 }
65 return *this;
66}
67
68//_____________________________________________________________________________
69void TGDMLMatrix::Set(size_t r, size_t c, Double_t a)
70{
71 assert(r < fNrows && c < fNcols);
72 fMatrix[fNcols * r + c] = a;
73}
74
75//_____________________________________________________________________________
76Double_t TGDMLMatrix::Get(size_t r, size_t c) const
77{
78 assert(r < fNrows && c < fNcols);
79 return fMatrix[fNcols * r + c];
80}
81
82//_____________________________________________________________________________
84{
85 // Print info about this matrix
86 printf("*** matrix: %-20s coldim = %zu rows = %zu\n", GetName(), fNcols, fNrows);
87 if (!fTitle.IsNull()) {
88 printf(" %s\n", fTitle.Data());
89 return;
90 }
91 for (size_t row = 0; row < fNrows; ++row) {
92 printf(" ");
93 for (size_t col = 0; col < fNcols; ++col) {
94 printf("%8.3g", Get(row, col));
95 }
96 printf("\n");
97 }
98}
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
char name[80]
Definition TGX11.cxx:110
This class is used in the process of reading and writing the GDML "matrix" tag.
Definition TGDMLMatrix.h:33
size_t fNrows
Definition TGDMLMatrix.h:52
TGDMLMatrix & operator=(const TGDMLMatrix &rhs)
void Print(Option_t *option="") const override
This method must be overridden when a class wants to print itself.
Double_t Get(size_t r, size_t c) const
void Set(size_t r, size_t c, Double_t a)
Double_t * fMatrix
Definition TGDMLMatrix.h:54
size_t fNcols
Definition TGDMLMatrix.h:53
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
TString fTitle
Definition TNamed.h:33
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition TNamed.cxx:51
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1033
const char * Data() const
Definition TString.h:376
Bool_t IsNull() const
Definition TString.h:414