Project
Loading...
Searching...
No Matches
Spline2DSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // code invisible on GPU and in the standalone compilation
18#include "Rtypes.h"
19#endif
20
21#include "Spline2DSpec.h"
22
23#if !defined(GPUCA_GPUCODE)
24#include <iostream>
25#endif
26
27#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // code invisible on GPU and in the standalone compilation
28#include "TRandom.h"
29#include "Riostream.h"
30#include "TMath.h"
31#include "Spline2DHelper.h"
32#include "TCanvas.h"
33#include "TNtuple.h"
34#include "TFile.h"
35#include "GPUCommonMath.h"
36
39
40#endif
41
42using namespace std;
43using namespace o2::gpu;
44
45template <typename DataT>
47{
49 mGridX1.destroy();
50 mGridX2.destroy();
51 mYdim = 0;
52 mParameters = nullptr;
54}
55
56template <typename DataT>
58{
60
61 FlatObject::setActualBufferAddress(actualFlatBufferPtr);
62
63 const size_t u2Offset = alignSize(mGridX1.getFlatBufferSize(), mGridX2.getBufferAlignmentBytes());
64 int32_t parametersOffset = u2Offset;
65 // int32_t bufferSize = parametersOffset;
66 mParameters = nullptr;
67
68 parametersOffset = alignSize(u2Offset + mGridX2.getFlatBufferSize(), getParameterAlignmentBytes());
69 // bufferSize = parametersOffset + getSizeOfParameters();
70 mParameters = reinterpret_cast<DataT*>(mFlatBufferPtr + parametersOffset);
71
72 mGridX1.setActualBufferAddress(mFlatBufferPtr);
73 mGridX2.setActualBufferAddress(mFlatBufferPtr + u2Offset);
74}
75
76template <typename DataT>
78{
80 char* bufferU = relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, mGridX1.getFlatBufferPtr());
81 char* bufferV = relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, mGridX2.getFlatBufferPtr());
82 mGridX1.setFutureBufferAddress(bufferU);
83 mGridX2.setFutureBufferAddress(bufferV);
84 mParameters = relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, mParameters);
85 FlatObject::setFutureBufferAddress(futureFlatBufferPtr);
86}
87
88template <typename DataT>
90{
91 printf(" Irregular Spline 2D: \n");
92 printf(" grid U1: \n");
93 mGridX1.print();
94 printf(" grid U2: \n");
95 mGridX2.print();
96}
97
98#if !defined(GPUCA_GPUCODE)
99
100template <typename DataT>
102{
104
105 const char* oldFlatBufferPtr = obj.mFlatBufferPtr;
106
107 FlatObject::cloneFromObject(obj, newFlatBufferPtr);
108
109 mYdim = obj.mYdim;
110 char* bufferU = FlatObject::relocatePointer(oldFlatBufferPtr, mFlatBufferPtr, obj.mGridX1.getFlatBufferPtr());
111 char* bufferV = FlatObject::relocatePointer(oldFlatBufferPtr, mFlatBufferPtr, obj.mGridX2.getFlatBufferPtr());
112
113 mGridX1.cloneFromObject(obj.mGridX1, bufferU);
114 mGridX2.cloneFromObject(obj.mGridX2, bufferV);
115 mParameters = FlatObject::relocatePointer(oldFlatBufferPtr, mFlatBufferPtr, obj.mParameters);
116}
117
118template <typename DataT>
119void Spline2DContainer<DataT>::moveBufferTo(char* newFlatBufferPtr)
120{
122 char* oldFlatBufferPtr = mFlatBufferPtr;
123 FlatObject::moveBufferTo(newFlatBufferPtr);
124 char* currFlatBufferPtr = mFlatBufferPtr;
125 mFlatBufferPtr = oldFlatBufferPtr;
126 setActualBufferAddress(currFlatBufferPtr);
127}
128
129template <typename DataT>
131 int32_t nYdim,
132 int32_t numberOfKnotsU1, const int32_t knotsU1[], int32_t numberOfKnotsU2, const int32_t knotsU2[])
133{
135
136 mYdim = nYdim;
138
139 mGridX1.recreate(0, numberOfKnotsU1, knotsU1);
140 mGridX2.recreate(0, numberOfKnotsU2, knotsU2);
141
142 const size_t u2Offset = alignSize(mGridX1.getFlatBufferSize(), mGridX2.getBufferAlignmentBytes());
143 int32_t parametersOffset = u2Offset + mGridX2.getFlatBufferSize();
144 int32_t bufferSize = parametersOffset;
145 mParameters = nullptr;
146
147 parametersOffset = alignSize(bufferSize, getParameterAlignmentBytes());
148 bufferSize = parametersOffset + getSizeOfParameters();
149
151
152 mGridX1.moveBufferTo(mFlatBufferPtr);
153 mGridX2.moveBufferTo(mFlatBufferPtr + u2Offset);
154
155 mParameters = reinterpret_cast<DataT*>(mFlatBufferPtr + parametersOffset);
156 for (int32_t i = 0; i < getNumberOfParameters(); i++) {
157 mParameters[i] = 0;
158 }
159}
160
161template <typename DataT>
163 int32_t numberOfKnotsU1, int32_t numberOfKnotsU2)
164{
166
167 mYdim = nYdim;
169
170 mGridX1.recreate(0, numberOfKnotsU1);
171 mGridX2.recreate(0, numberOfKnotsU2);
172
173 const size_t u2Offset = alignSize(mGridX1.getFlatBufferSize(), mGridX2.getBufferAlignmentBytes());
174 int32_t parametersOffset = u2Offset + mGridX2.getFlatBufferSize();
175 int32_t bufferSize = parametersOffset;
176 mParameters = nullptr;
177
178 parametersOffset = alignSize(bufferSize, getParameterAlignmentBytes());
179 bufferSize = parametersOffset + getSizeOfParameters();
180
182
183 mGridX1.moveBufferTo(mFlatBufferPtr);
184 mGridX2.moveBufferTo(mFlatBufferPtr + u2Offset);
185
186 mParameters = reinterpret_cast<DataT*>(mFlatBufferPtr + parametersOffset);
187 for (int32_t i = 0; i < getNumberOfParameters(); i++) {
188 mParameters[i] = 0;
189 }
190}
191
192#endif // GPUCA_GPUCODE
193
194#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // code invisible on GPU and in the standalone compilation
195
196template <typename DataT>
198 double x1Min, double x1Max, double x2Min, double x2Max,
199 std::function<void(double x1, double x2, double f[])> F,
200 int32_t nAuxiliaryDataPointsX1, int32_t nAuxiliaryDataPointsX2)
201{
204 helper.approximateFunction(*reinterpret_cast<Spline2D<DataT>*>(this), x1Min, x1Max, x2Min, x2Max, F, nAuxiliaryDataPointsX1, nAuxiliaryDataPointsX2);
205}
206
207template <typename DataT>
209 double x1Min, double x1Max, double x2Min, double x2Max,
210 std::function<void(double x1, double x2, double f[])> F,
211 int32_t nAuxiliaryDataPointsX1, int32_t nAuxiliaryDataPointsX2)
212{
215 helper.approximateFunctionViaDataPoints(*reinterpret_cast<Spline2D<DataT>*>(this), x1Min, x1Max, x2Min, x2Max, F, nAuxiliaryDataPointsX1, nAuxiliaryDataPointsX2);
216}
217
218template <typename DataT>
219int32_t Spline2DContainer<DataT>::writeToFile(TFile& outf, const char* name)
220{
222 return FlatObject::writeToFile(*this, outf, name);
223}
224
225template <typename DataT>
227 TFile& inpf, const char* name)
228{
230 return FlatObject::readFromFile<Spline2DContainer<DataT>>(inpf, name);
231}
232
233template <typename DataT>
234int32_t Spline2DContainer<DataT>::test(const bool draw, const bool drawDataPoints)
235{
237}
238
239#endif // GPUCA_GPUCODE && !GPUCA_STANDALONE
240
int32_t i
Definition of Spline2DHelper class.
templateClassImp(o2::gpu::Spline2DContainer)
Definition of Spline2DSpec class.
void setFutureBufferAddress(char *futureFlatBufferPtr)
Definition FlatObject.h:557
void destroy()
_______________ Utilities _______________________________________________
Definition FlatObject.h:349
static T * relocatePointer(const char *oldBase, char *newBase, const T *ptr)
Relocates a pointer inside a buffer to the new buffer address.
Definition FlatObject.h:285
void setActualBufferAddress(char *actualFlatBufferPtr)
_____________ Methods for moving the class with its external buffer to another location _____________...
Definition FlatObject.h:547
static int32_t writeToFile(T &obj, TFile &outf, const char *name)
write a child class object to the file
Definition FlatObject.h:480
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:342
void moveBufferTo(char *newBufferPtr)
Definition FlatObject.h:396
void finishConstruction(int32_t flatBufferSize)
Definition FlatObject.h:358
void cloneFromObject(const FlatObject &obj, char *newFlatBufferPtr)
Definition FlatObject.h:373
void cloneFromObject(const Spline2DContainer &obj, char *newFlatBufferPtr)
void approximateFunction(double x1Min, double x1Max, double x2Min, double x2Max, std::function< void(double x1, double x2, double f[])> F, int32_t nAuxiliaryDataPointsU1=4, int32_t nAuxiliaryDataPointsU2=4)
_______________ Construction interface ________________________
void recreate(int32_t nYdim, int32_t nKnotsX1, int32_t nKnotsX2)
Constructor for a regular spline.
void setActualBufferAddress(char *actualFlatBufferPtr)
void print() const
Print method.
Spline1D< DataT > mGridX2
grid for V axis
int32_t mYdim
_____________ Data members ____________
void moveBufferTo(char *newBufferPtr)
int32_t writeToFile(TFile &outf, const char *name)
_______________ IO ________________________
static Spline2DContainer * readFromFile(TFile &inpf, const char *name)
read a class object from the file
static int32_t test(const bool draw=0, const bool drawDataPoints=1)
_______________ Test tools _______________
Spline1D< DataT > mGridX1
grid for U axis
void setFutureBufferAddress(char *futureFlatBufferPtr)
void approximateFunctionViaDataPoints(double x1Min, double x1Max, double x2Min, double x2Max, std::function< void(double x1, double x2, double f[])> F, int32_t nAuxiliaryDataPointsX1, int32_t nAuxiliaryDataPointsX2)
void approximateFunction(Spline2DContainer< DataT > &spline, double x1Min, double x1Max, double x2Min, double x2Max, std::function< void(double x1, double x2, double f[])> F, int32_t nAuxiliaryDataPointsU1=4, int32_t nAuxiliaryDataPointsU2=4)
_______________ Main functionality ________________________
void approximateFunctionViaDataPoints(Spline2DContainer< DataT > &spline, double x1Min, double x1Max, double x2Min, double x2Max, std::function< void(double x1, double x2, double f[])> F, int32_t nAuxiliaryDataPointsU1=4, int32_t nAuxiliaryDataPointsU2=4)
static int32_t test(const bool draw=0, const bool drawDataPoints=1)
Test the Spline2D class functionality.
GLuint GLfloat GLfloat GLfloat x1
Definition glcorearb.h:5034
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
Defining DataPointCompositeObject explicitly as copiable.
TCanvas * drawDataPoints(TMultiGraph *mg, double min, double max)