Project
Loading...
Searching...
No Matches
TPCFastTransform.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)
18#include "Rtypes.h"
19#endif
20
21#include "TPCFastTransform.h"
22#include "GPUCommonLogger.h"
23
24#if !defined(GPUCA_GPUCODE)
25#include <iostream>
26#endif
27
28#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
29#include "TFile.h"
30#include "GPUCommonLogger.h"
31#endif
32
33#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
35#endif
36
37using namespace o2::gpu;
38
40 : FlatObject(), mTimeStamp(0), mCorrection(), mApplyCorrection(1), mT0(0.f), mVdrift(0.f), mVdriftCorrY(0.f), mLdriftCorr(0.f), mTOFcorr(0.f), mPrimVtxZ(0.f), mLumi(0.f), mLumiError(0.f), mLumiScaleFactor(1.0f)
41{
42 // Default Constructor: creates an empty uninitialized object
43}
44
45void TPCFastTransform::cloneFromObject(const TPCFastTransform& obj, char* newFlatBufferPtr)
46{
48
49 const char* oldFlatBufferPtr = obj.mFlatBufferPtr;
50
51 FlatObject::cloneFromObject(obj, newFlatBufferPtr);
52
53 mTimeStamp = obj.mTimeStamp;
54 mApplyCorrection = obj.mApplyCorrection;
55 mT0 = obj.mT0;
56 mVdrift = obj.mVdrift;
57 mVdriftCorrY = obj.mVdriftCorrY;
58 mLdriftCorr = obj.mLdriftCorr;
59 mTOFcorr = obj.mTOFcorr;
60 mPrimVtxZ = obj.mPrimVtxZ;
61 mLumi = obj.mLumi;
62 mLumiError = obj.mLumiError;
63 mLumiScaleFactor = obj.mLumiScaleFactor;
64 // variable-size data
65
66 char* distBuffer = FlatObject::relocatePointer(oldFlatBufferPtr, mFlatBufferPtr, obj.mCorrection.getFlatBufferPtr());
67 mCorrection.cloneFromObject(obj.mCorrection, distBuffer);
68}
69
70void TPCFastTransform::moveBufferTo(char* newFlatBufferPtr)
71{
73 FlatObject::moveBufferTo(newFlatBufferPtr);
75}
76
77void TPCFastTransform::setActualBufferAddress(char* actualFlatBufferPtr)
78{
80 FlatObject::setActualBufferAddress(actualFlatBufferPtr);
82}
83
84void TPCFastTransform::setFutureBufferAddress(char* futureFlatBufferPtr)
85{
87
88 const char* oldFlatBufferPtr = mFlatBufferPtr;
89
90 char* distBuffer = FlatObject::relocatePointer(oldFlatBufferPtr, futureFlatBufferPtr, mCorrection.getFlatBufferPtr());
91 mCorrection.setFutureBufferAddress(distBuffer);
92 FlatObject::setFutureBufferAddress(futureFlatBufferPtr);
93}
94
96{
98
100
101 assert(correction.isConstructed());
102
103 mTimeStamp = 0;
104 mApplyCorrection = 1;
105 mT0 = 0.f;
106 mVdrift = 0.f;
107 mVdriftCorrY = 0.f;
108 mLdriftCorr = 0.f;
109 mTOFcorr = 0.f;
110 mPrimVtxZ = 0.f;
111 mLumi = 0.f;
112 mLumiError = 0.f;
113 mLumiScaleFactor = 1.f;
114
115 // variable-size data
116
117 mCorrection.cloneFromObject(correction, nullptr);
118}
119
120void TPCFastTransform::setCalibration(int64_t timeStamp, float t0, float vDrift, float vDriftCorrY, float lDriftCorr, float tofCorr, float primVtxZ)
121{
126
127 mTimeStamp = timeStamp;
128 mT0 = t0;
129 mVdrift = vDrift;
130 mVdriftCorrY = vDriftCorrY;
131 mLdriftCorr = lDriftCorr;
132 mTOFcorr = tofCorr;
133 mPrimVtxZ = primVtxZ;
134 mConstructionMask |= ConstructionExtraState::CalibrationIsSet;
135}
136
138{
140
141 assert(mConstructionMask & ConstructionState::InProgress); // construction in process
142 assert(mConstructionMask & ConstructionExtraState::CalibrationIsSet); // all parameters are set
143
145
146 mCorrection.moveBufferTo(mFlatBufferPtr);
147}
148
150{
151#if !defined(GPUCA_GPUCODE)
152 LOG(info) << "TPC Fast Transformation: ";
153 LOG(info) << "mTimeStamp = " << mTimeStamp;
154 LOG(info) << "mApplyCorrection = " << mApplyCorrection;
155 LOG(info) << "mT0 = " << mT0;
156 LOG(info) << "mVdrift = " << mVdrift;
157 LOG(info) << "mVdriftCorrY = " << mVdriftCorrY;
158 LOG(info) << "mLdriftCorr = " << mLdriftCorr;
159 LOG(info) << "mTOFcorr = " << mTOFcorr;
160 LOG(info) << "mPrimVtxZ = " << mPrimVtxZ;
161 LOG(info) << "mLumi = " << mLumi;
162 LOG(info) << "mLumiError = " << mLumiError;
163 LOG(info) << "mLumiScaleFactor = " << mLumiScaleFactor;
164 mCorrection.print();
165#endif
166}
167
168#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
169
170int32_t TPCFastTransform::writeToFile(std::string outFName, std::string name)
171{
173 assert(isConstructed());
174
175 if (outFName.empty()) {
176 outFName = "tpcFastTransform.root";
177 }
178 if (name.empty()) {
179 name = "TPCFastTransform";
180 }
181 TFile outf(outFName.data(), "recreate");
182 if (outf.IsZombie()) {
183 LOG(error) << "Failed to open output file " << outFName;
184 return -1;
185 }
186
187 bool isBufferExternal = !isBufferInternal();
188 if (isBufferExternal) {
190 }
191 outf.WriteObjectAny(this, Class(), name.data());
192 outf.Close();
193 if (isBufferExternal) {
195 }
196 return 0;
197}
198
203
204TPCFastTransform* TPCFastTransform::loadFromFile(std::string inpFName, std::string name)
205{
207
208 if (inpFName.empty()) {
209 inpFName = "tpcFastTransform.root";
210 }
211 if (name.empty()) {
212 name = "TPCFastTransform";
213 }
214 TFile inpf(inpFName.data());
215 if (inpf.IsZombie()) {
216 LOG(error) << "Failed to open input file " << inpFName;
217 return nullptr;
218 }
219 TPCFastTransform* transform = reinterpret_cast<TPCFastTransform*>(inpf.GetObjectChecked(name.data(), TPCFastTransform::Class()));
220 if (!transform) {
221 LOG(error) << "Failed to load " << name << " from " << inpFName;
222 return nullptr;
223 }
224 if (transform->mFlatBufferSize > 0 && transform->mFlatBufferContainer == nullptr) {
225 LOG(error) << "Failed to load " << name << " from " << inpFName << ": empty flat buffer container";
226 return nullptr;
227 }
228 transform->rectifyAfterReadingFromFile(); // == transform->setActualBufferAddress(transform->mFlatBufferContainer);
229 return transform;
230}
231
232#endif
233
234#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
239
240void TPCSlowSpaceChargeCorrection::getCorrections(const float gx, const float gy, const float gz, const int32_t slice, float& gdxC, float& gdyC, float& gdzC) const
241{
243 mCorr->getCorrections(gx, gy, gz, side, gdxC, gdyC, gdzC);
244}
245
247{
248 mCorrectionSlow = new TPCSlowSpaceChargeCorrection;
249 mCorrectionSlow->mCorr = new o2::tpc::SpaceCharge<float>();
250 mCorrectionSlow->mCorr->setGlobalCorrectionsFromFile<float>(inpf, o2::tpc::Side::A);
251 mCorrectionSlow->mCorr->setGlobalCorrectionsFromFile<float>(inpf, o2::tpc::Side::C);
252}
253#endif
uint32_t side
Definition RawData.h:0
This class contains the algorithms for calculation the distortions and corrections.
Definition of TPCFastTransform class.
GPUCA_GPUCODE.
Definition FlatObject.h:176
void setFutureBufferAddress(char *futureFlatBufferPtr)
Definition FlatObject.h:557
uint32_t mConstructionMask
mask for constructed object members, first two bytes are used by this class
Definition FlatObject.h:323
int32_t mFlatBufferSize
size of the flat buffer
Definition FlatObject.h:322
void adoptInternalBuffer(char *buf)
Definition FlatObject.h:534
char * mFlatBufferContainer
Definition FlatObject.h:324
bool isConstructed() const
Tells if the object is constructed.
Definition FlatObject.h:262
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
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:342
void moveBufferTo(char *newBufferPtr)
Definition FlatObject.h:396
void finishConstruction(int32_t flatBufferSize)
Definition FlatObject.h:358
bool isBufferInternal() const
Tells if the buffer is internal.
Definition FlatObject.h:265
void cloneFromObject(const FlatObject &obj, char *newFlatBufferPtr)
Definition FlatObject.h:373
void clearInternalBufferPtr()
Definition FlatObject.h:541
size_t getFlatBufferSize() const
Gives size of the flat buffer.
Definition FlatObject.h:256
@ InProgress
construction started: temporary memory is reserved
Definition FlatObject.h:319
const char * getFlatBufferPtr() const
Gives pointer to the flat buffer.
Definition FlatObject.h:259
void setFutureBufferAddress(char *futureFlatBufferPtr)
void setActualBufferAddress(char *actualFlatBufferPtr)
Moving the class with its external buffer to another location.
void cloneFromObject(const TPCFastSpaceChargeCorrection &obj, char *newFlatBufferPtr)
Construction interface.
void setActualBufferAddress(char *actualFlatBufferPtr)
Moving the class with its external buffer to another location.
void finishConstruction()
Finishes initialization: puts everything to the flat buffer, releases temporary memory.
void moveBufferTo(char *newBufferPtr)
void cloneFromObject(const TPCFastTransform &obj, char *newFlatBufferPtr)
Construction interface.
void setCalibration(int64_t timeStamp, float t0, float vDrift, float vDriftCorrY, float lDriftCorr, float tofCorr, float primVtxZ)
int32_t writeToFile(std::string outFName="", std::string name="")
void setSlowTPCSCCorrection(TFile &inpf)
setting the reference corrections
TPCFastTransform()
_____________ Constructors / destructors __________________________
static TPCFastTransform * loadFromFile(std::string inpFName="", std::string name="")
void setFutureBufferAddress(char *futureFlatBufferPtr)
void print() const
Print method.
void setGlobalCorrectionsFromFile(std::string_view file, const Side side)
void getCorrections(const DataT x, const DataT y, const DataT z, const Side side, DataT &corrX, DataT &corrY, DataT &corrZ) const
GLuint const GLchar * name
Definition glcorearb.h:781
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition glcorearb.h:5034
constexpr unsigned char SECTORSPERSIDE
Definition Defs.h:40
Side
TPC readout sidE.
Definition Defs.h:35
@ A
Definition Defs.h:35
@ C
Definition Defs.h:36
simple struct to hold the space charge object which can be used for CPU reconstruction only
o2::tpc::SpaceCharge< float > * mCorr
reference space charge corrections
void getCorrections(const float gx, const float gy, const float gz, const int32_t slice, float &gdxC, float &gdyC, float &gdzC) const
getting the corrections for global coordinates
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"