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
23
24//_____________________________________________________________________________
25TGDMLMatrix::TGDMLMatrix(const char *name, size_t rows, size_t cols) : TNamed(name, "")
26{
27 // Constructor
28 if ((rows <= 0) || (cols <= 0)) {
29 Fatal("TGDMLMatrix::TGDMLMatrix(rows,cols)", "Wrong number of rows/cols");
30 }
31 fNrows = rows;
32 fNcols = cols;
33 fNelem = rows * cols;
34 fMatrix = new Double_t[fNelem];
35}
36
37//_____________________________________________________________________________
39 : TNamed(rhs), fNelem(rhs.fNelem), fNrows(rhs.fNrows), fNcols(rhs.fNcols), fMatrix(nullptr)
40{
41 // Copy constructor
42 if (rhs.fMatrix) {
43 fMatrix = new Double_t[fNelem];
44 memcpy(fMatrix, rhs.fMatrix, fNelem * sizeof(Double_t));
45 }
46}
47
48//_____________________________________________________________________________
50{
51 // Assignment
52 if (this == &rhs) {
53 return *this;
54 }
56 fNrows = rhs.fNrows;
57 fNcols = rhs.fNcols;
59 if (rhs.fMatrix) {
60 delete[] fMatrix;
61 fMatrix = new Double_t[fNelem];
62 memcpy(fMatrix, rhs.fMatrix, fNelem * sizeof(Double_t));
63 }
64 return *this;
65}
66
67//_____________________________________________________________________________
68void TGDMLMatrix::Set(size_t r, size_t c, Double_t a)
69{
70 assert(r < fNrows && c < fNcols);
71 fMatrix[fNcols * r + c] = a;
72}
73
74//_____________________________________________________________________________
75Double_t TGDMLMatrix::Get(size_t r, size_t c) const
76{
77 assert(r < fNrows && c < fNcols);
78 return fMatrix[fNcols * r + c];
79}
80
81//_____________________________________________________________________________
83{
84 // Print info about this matrix
85 printf("*** matrix: %-20s coldim = %zu rows = %zu\n", GetName(), fNcols, fNrows);
86 if (!fTitle.IsNull()) {
87 printf(" %s\n", fTitle.Data());
88 return;
89 }
90 for (size_t row = 0; row < fNrows; ++row) {
91 printf(" ");
92 for (size_t col = 0; col < fNcols; ++col) {
93 printf("%8.3g", Get(row, col));
94 }
95 printf("\n");
96 }
97}
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:49
TString fTitle
Definition TNamed.h:33
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition TNamed.cxx:50
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1099
const char * Data() const
Definition TString.h:384
Bool_t IsNull() const
Definition TString.h:422