19#if !defined(GPUCA_GPUCODE)
24#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
35#if !defined(GPUCA_GPUCODE)
43 if (numberOfKnots < 2) {
47 std::vector<int32_t> knots(numberOfKnots);
48 for (int32_t
i = 0;
i < numberOfKnots;
i++) {
51 recreate(nYdim, numberOfKnots, knots.data());
69 mYdim = (nYdim >= 0) ? nYdim : 0;
71 std::vector<int32_t> knotU;
74 std::vector<int32_t> tmp;
75 for (int32_t
i = 0;
i < numberOfKnots;
i++) {
76 tmp.push_back(inputKnots[
i]);
78 std::sort(tmp.begin(), tmp.end());
82 for (uint32_t
i = 1;
i < tmp.size(); ++
i) {
83 int32_t u = tmp[
i] - tmp[0];
84 if (knotU.back() < u) {
88 if (knotU.back() < 1) {
93 mNumberOfKnots = knotU.size();
98 const int32_t uToKnotMapOffset = mNumberOfKnots *
sizeof(
Knot);
99 int32_t parametersOffset = uToKnotMapOffset + (mUmax + 1) *
sizeof(int32_t);
100 int32_t bufferSize = parametersOffset;
102 parametersOffset = alignSize(bufferSize, getParameterAlignmentBytes());
103 bufferSize = parametersOffset + getSizeOfParameters();
108 mUtoKnotMap =
reinterpret_cast<int32_t*
>(mFlatBufferPtr + uToKnotMapOffset);
109 mParameters =
reinterpret_cast<DataT*
>(mFlatBufferPtr + parametersOffset);
111 for (int32_t
i = 0;
i < getNumberOfParameters();
i++) {
115 Knot* s = getKnots();
117 for (int32_t
i = 0;
i < mNumberOfKnots;
i++) {
121 for (int32_t
i = 0;
i < mNumberOfKnots - 1;
i++) {
122 s[
i].Li = 1. / (s[
i + 1].u - s[
i].u);
125 s[mNumberOfKnots - 1].Li = 0.;
129 int32_t* map = getUtoKnotMap();
131 const int32_t iKnotMax = mNumberOfKnots - 2;
139 for (int32_t u = 0, iKnot = 0; u <= mUmax; u++) {
140 if ((knotU[iKnot + 1] == u) && (iKnot < iKnotMax)) {
149template <
class DataT>
152 printf(
" Spline 1D: \n");
153 printf(
" mNumberOfKnots = %d \n", mNumberOfKnots);
154 printf(
" mUmax = %d\n", mUmax);
155 printf(
" mUtoKnotMap = %p \n", (
void*)mUtoKnotMap);
157 for (int32_t
i = 0;
i < mNumberOfKnots;
i++) {
158 printf(
"%d ", (int32_t)getKnot(
i).u);
163#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
165template <
class DataT>
167 double xMin,
double xMax,
168 std::function<
void(
double x,
double f[])> F,
169 int32_t nAxiliaryDataPoints)
176template <
class DataT>
183template <
class DataT>
185 TFile& inpf,
const char*
name)
188 return FlatObject::readFromFile<Spline1DContainer<DataT>>(inpf,
name);
193#if !defined(GPUCA_GPUCODE)
195template <
class DataT>
211template <
class DataT>
215 char* oldFlatBufferPtr = mFlatBufferPtr;
217 char* currFlatBufferPtr = mFlatBufferPtr;
218 mFlatBufferPtr = oldFlatBufferPtr;
219 setActualBufferAddress(currFlatBufferPtr);
223template <
class DataT>
232 mUtoKnotMap =
nullptr;
233 mParameters =
nullptr;
237template <
class DataT>
244 const int32_t uToKnotMapOffset = mNumberOfKnots *
sizeof(
Knot);
245 mUtoKnotMap =
reinterpret_cast<int32_t*
>(mFlatBufferPtr + uToKnotMapOffset);
246 int32_t parametersOffset = uToKnotMapOffset + (mUmax + 1) *
sizeof(int32_t);
248 parametersOffset = alignSize(parametersOffset, getParameterAlignmentBytes());
250 mParameters =
reinterpret_cast<DataT*
>(mFlatBufferPtr + parametersOffset);
253template <
class DataT>
258 mParameters = relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, mParameters);
262#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
263template <
class DataT>
Definition of Spline1DHelper class.
templateClassImp(o2::gpu::Spline1DContainer)
Definition of Spline1DSpec class.
void setFutureBufferAddress(char *futureFlatBufferPtr)
void destroy()
_______________ Utilities _______________________________________________
static T * relocatePointer(const char *oldBase, char *newBase, const T *ptr)
Relocates a pointer inside a buffer to the new buffer address.
void setActualBufferAddress(char *actualFlatBufferPtr)
_____________ Methods for moving the class with its external buffer to another location _____________...
static int32_t writeToFile(T &obj, TFile &outf, const char *name)
write a child class object to the file
void startConstruction()
_____________ Construction _________
void moveBufferTo(char *newBufferPtr)
void finishConstruction(int32_t flatBufferSize)
void cloneFromObject(const FlatObject &obj, char *newFlatBufferPtr)
void cloneFromObject(const Spline1DContainer &obj, char *newFlatBufferPtr)
void setFutureBufferAddress(char *futureFlatBufferPtr)
int32_t mUmax
U of the last knot.
int32_t mYdim
_____________ Data members ____________
void setActualBufferAddress(char *actualFlatBufferPtr)
void approximateFunction(double xMin, double xMax, std::function< void(double x, double f[])> F, int32_t nAuxiliaryDataPoints=4)
_______________ Construction interface ________________________
DataT mXtoUscale
a scaling factor to convert X to U
void print() const
Print method.
DataT * mParameters
(transient!!) pointer to (integer U -> knot index) map inside the mFlatBufferPtr array
void recreate(int32_t nYdim, int32_t numberOfKnots)
Constructor for a regular spline.
DataT mXmin
X of the first knot.
static int32_t test(const bool draw=0, const bool drawDataPoints=1)
_______________ Test tools _______________
void moveBufferTo(char *newBufferPtr)
int32_t writeToFile(TFile &outf, const char *name)
_______________ IO ________________________
int32_t mNumberOfKnots
n knots on the grid
static Spline1DContainer * readFromFile(TFile &inpf, const char *name)
read a class object from the file
void approximateFunction(Spline1DContainer< DataT > &spline, double xMin, double xMax, std::function< void(double x, double f[])> F, int32_t nAuxiliaryDataPoints=4)
Create best-fit spline parameters for a function F.
static int32_t test(const bool draw=0, const bool drawDataPoints=1)
Test the Spline1D class functionality.
GLuint const GLchar * name
Defining DataPointCompositeObject explicitly as copiable.