22#if !defined(GPUCA_STANDALONE)
38 if (numberOfKnots < 2) {
42 std::vector<int32_t> knots(numberOfKnots);
43 for (int32_t
i = 0;
i < numberOfKnots;
i++) {
46 recreate(nYdim, numberOfKnots, knots.data());
63 this->mYdim = (nYdim >= 0) ? nYdim : 0;
65 std::vector<int32_t> knotU;
68 std::vector<int32_t> tmp;
69 for (int32_t
i = 0;
i < numberOfKnots;
i++) {
70 tmp.push_back(inputKnots[
i]);
72 std::sort(tmp.begin(), tmp.end());
76 for (uint32_t
i = 1;
i < tmp.size(); ++
i) {
77 int32_t u = tmp[
i] - tmp[0];
78 if (knotU.back() < u) {
82 if (knotU.back() < 1) {
87 this->mNumberOfKnots = knotU.size();
88 this->mUmax = knotU.back();
90 this->mXtoUscale = 1.;
92 const int32_t uToKnotMapOffset = this->mNumberOfKnots *
sizeof(
Knot<DataT>);
93 int32_t parametersOffset = uToKnotMapOffset + (this->mUmax + 1) *
sizeof(int32_t);
94 int32_t bufferSize = parametersOffset;
95 if (this->mYdim > 0) {
96 parametersOffset = this->
alignSize(bufferSize, this->getParameterAlignmentBytes());
97 bufferSize = parametersOffset + this->getSizeOfParameters();
102 this->mUtoKnotMap =
reinterpret_cast<int32_t*
>(this->mFlatBufferPtr + uToKnotMapOffset);
103 this->mParameters =
reinterpret_cast<DataT*
>(this->mFlatBufferPtr + parametersOffset);
105 for (int32_t
i = 0;
i < this->getNumberOfParameters();
i++) {
106 this->mParameters[
i] = 0;
111 for (int32_t
i = 0;
i < this->mNumberOfKnots;
i++) {
115 for (int32_t
i = 0;
i < this->mNumberOfKnots - 1;
i++) {
116 s[
i].Li = 1. / (
s[
i + 1].u -
s[
i].u);
119 s[this->mNumberOfKnots - 1].Li = 0.;
123 int32_t* map = getUtoKnotMap();
125 const int32_t iKnotMax = this->mNumberOfKnots - 2;
133 for (int32_t u = 0, iKnot = 0; u <= this->mUmax; u++) {
134 if ((knotU[iKnot + 1] == u) && (iKnot < iKnotMax)) {
141template <
class DataT>
144 printf(
" Spline 1D: \n");
145 printf(
" mNumberOfKnots = %d \n", this->mNumberOfKnots);
146 printf(
" mUmax = %d\n", this->mUmax);
147 printf(
" mUtoKnotMap = %p \n", (
void*)this->mUtoKnotMap);
149 for (int32_t
i = 0;
i < this->mNumberOfKnots;
i++) {
150 printf(
"%d ", (int32_t)getKnot(
i).u);
155#if !defined(GPUCA_STANDALONE)
157template <
class DataT>
159 double xMin,
double xMax,
160 std::function<
void(
double x,
double f[])> F,
161 int32_t nAxiliaryDataPoints)
168template <
class DataT>
175template <
class DataT>
179 return FlatObject::readFromFile<Spline1DContainer<DataT, FlatObject>>(inpf,
name);
182template <
class DataT>
190template <
class DataT>
194 const char* oldFlatBufferPtr = obj.mFlatBufferPtr;
196 this->mYdim = obj.mYdim;
197 this->mNumberOfKnots = obj.mNumberOfKnots;
198 this->mUmax = obj.mUmax;
199 this->mXmin = obj.mXmin;
200 this->mXtoUscale = obj.mXtoUscale;
205template <
class DataT>
209 char* oldFlatBufferPtr = this->mFlatBufferPtr;
211 char* currFlatBufferPtr = this->mFlatBufferPtr;
212 this->mFlatBufferPtr = oldFlatBufferPtr;
213 setActualBufferAddress(currFlatBufferPtr);
216template <
class DataT>
217template <
class OtherFlatBase>
222 this->mYdim =
src.getYdimensions();
223 this->mNumberOfKnots =
src.getNumberOfKnots();
224 this->mUmax =
src.getUmax();
225 this->mXmin =
src.getXmin();
226 this->mXtoUscale =
src.getXtoUscale();
227 this->mFlatBufferSize =
src.getFlatBufferSize();
228 this->mUtoKnotMap =
nullptr;
229 this->mParameters =
nullptr;
232template <
class DataT>
235 this->mNumberOfKnots = 0;
239 this->mXtoUscale = 1.;
240 this->mUtoKnotMap =
nullptr;
241 this->mParameters =
nullptr;
245template <
class DataT>
251 const int32_t uToKnotMapOffset = this->mNumberOfKnots *
sizeof(
Knot<DataT>);
252 this->mUtoKnotMap =
reinterpret_cast<int32_t*
>(this->mFlatBufferPtr + uToKnotMapOffset);
253 int32_t parametersOffset = uToKnotMapOffset + (this->mUmax + 1) *
sizeof(int32_t);
254 if (this->mYdim > 0) {
255 parametersOffset = this->
alignSize(parametersOffset, this->getParameterAlignmentBytes());
257 mParameters =
reinterpret_cast<DataT*
>(this->mFlatBufferPtr + parametersOffset);
260template <
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 approximateFunction(Spline1DContainer< DataT, FlatObject > &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
size_t alignSize(size_t sizeBytes)
align size to given diven number of bytes
TCanvas * drawDataPoints(TMultiGraph *mg, double min, double max)