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(TPCFastTransform::DEFLUMI), mLumiError(0.f), mLumiScaleFactor(1.0f), mIDC(TPCFastTransform::DEFIDC), mIDCError(0.f), mCTP2IDCFallBackThreshold(30.f)
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 mIDC = obj.mIDC;
64 mIDCError = obj.mIDCError;
65 mCTP2IDCFallBackThreshold = obj.mCTP2IDCFallBackThreshold;
66 mLumiScaleFactor = obj.mLumiScaleFactor;
67 // variable-size data
68
69 char* distBuffer = FlatObject::relocatePointer(oldFlatBufferPtr, mFlatBufferPtr, obj.mCorrection.getFlatBufferPtr());
70 mCorrection.cloneFromObject(obj.mCorrection, distBuffer);
71}
72
73void TPCFastTransform::moveBufferTo(char* newFlatBufferPtr)
74{
76 FlatObject::moveBufferTo(newFlatBufferPtr);
78}
79
80void TPCFastTransform::setActualBufferAddress(char* actualFlatBufferPtr)
81{
83 FlatObject::setActualBufferAddress(actualFlatBufferPtr);
85}
86
87void TPCFastTransform::setFutureBufferAddress(char* futureFlatBufferPtr)
88{
90
91 const char* oldFlatBufferPtr = mFlatBufferPtr;
92
93 char* distBuffer = FlatObject::relocatePointer(oldFlatBufferPtr, futureFlatBufferPtr, mCorrection.getFlatBufferPtr());
94 mCorrection.setFutureBufferAddress(distBuffer);
95 FlatObject::setFutureBufferAddress(futureFlatBufferPtr);
96}
97
99{
101
103
104 assert(correction.isConstructed());
105
106 mTimeStamp = 0;
107 mApplyCorrection = 1;
108 mT0 = 0.f;
109 mVdrift = 0.f;
110 mVdriftCorrY = 0.f;
111 mLdriftCorr = 0.f;
112 mTOFcorr = 0.f;
113 mPrimVtxZ = 0.f;
114 mLumi = DEFLUMI;
115 mLumiError = 0.f;
116 mIDC = DEFIDC;
117 mIDCError = 0.f;
118 mCTP2IDCFallBackThreshold = 30.f;
119 mLumiScaleFactor = 1.f;
120
121 // variable-size data
122
123 mCorrection.cloneFromObject(correction, nullptr);
124}
125
126void TPCFastTransform::setCalibration(int64_t timeStamp, float t0, float vDrift, float vDriftCorrY, float lDriftCorr, float tofCorr, float primVtxZ)
127{
132
133 mTimeStamp = timeStamp;
134 mT0 = t0;
135 mVdrift = vDrift;
136 mVdriftCorrY = vDriftCorrY;
137 mLdriftCorr = lDriftCorr;
138 mTOFcorr = tofCorr;
139 mPrimVtxZ = primVtxZ;
140 mConstructionMask |= ConstructionExtraState::CalibrationIsSet;
141}
142
144{
146
147 assert(mConstructionMask & ConstructionState::InProgress); // construction in process
148 assert(mConstructionMask & ConstructionExtraState::CalibrationIsSet); // all parameters are set
149
151
152 mCorrection.moveBufferTo(mFlatBufferPtr);
153}
154
156{
157#if !defined(GPUCA_GPUCODE)
158 LOG(info) << "TPC Fast Transformation: ";
159 LOG(info) << "mTimeStamp = " << mTimeStamp;
160 LOG(info) << "mApplyCorrection = " << mApplyCorrection;
161 LOG(info) << "mT0 = " << mT0;
162 LOG(info) << "mVdrift = " << mVdrift;
163 LOG(info) << "mVdriftCorrY = " << mVdriftCorrY;
164 LOG(info) << "mLdriftCorr = " << mLdriftCorr;
165 LOG(info) << "mTOFcorr = " << mTOFcorr;
166 LOG(info) << "mPrimVtxZ = " << mPrimVtxZ;
167 LOG(info) << "mLumi = " << mLumi;
168 LOG(info) << "mLumiError = " << mLumiError;
169 LOG(info) << "mIDC = " << mIDC;
170 LOG(info) << "mIDCError = " << mIDCError;
171 LOG(info) << "mCTP2IDCFallBackThreshold = " << mCTP2IDCFallBackThreshold;
172 LOG(info) << "mLumiScaleFactor = " << mLumiScaleFactor;
173 mCorrection.print();
174#endif
175}
176
177#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
178
179int32_t TPCFastTransform::writeToFile(std::string outFName, std::string name)
180{
182 assert(isConstructed());
183
184 if (outFName.empty()) {
185 outFName = "tpcFastTransform.root";
186 }
187 if (name.empty()) {
188 name = "TPCFastTransform";
189 }
190 TFile outf(outFName.data(), "recreate");
191 if (outf.IsZombie()) {
192 LOG(error) << "Failed to open output file " << outFName;
193 return -1;
194 }
195
196 bool isBufferExternal = !isBufferInternal();
197 if (isBufferExternal) {
199 }
200 outf.WriteObjectAny(this, Class(), name.data());
201 outf.Close();
202 if (isBufferExternal) {
204 }
205 return 0;
206}
207
212
213TPCFastTransform* TPCFastTransform::loadFromFile(std::string inpFName, std::string name)
214{
216
217 if (inpFName.empty()) {
218 inpFName = "tpcFastTransform.root";
219 }
220 if (name.empty()) {
221 name = "TPCFastTransform";
222 }
223 TFile inpf(inpFName.data());
224 if (inpf.IsZombie()) {
225 LOG(error) << "Failed to open input file " << inpFName;
226 return nullptr;
227 }
228 TPCFastTransform* transform = reinterpret_cast<TPCFastTransform*>(inpf.GetObjectChecked(name.data(), TPCFastTransform::Class()));
229 if (!transform) {
230 LOG(error) << "Failed to load " << name << " from " << inpFName;
231 return nullptr;
232 }
233 if (transform->mFlatBufferSize > 0 && transform->mFlatBufferContainer == nullptr) {
234 LOG(error) << "Failed to load " << name << " from " << inpFName << ": empty flat buffer container";
235 return nullptr;
236 }
237 transform->rectifyAfterReadingFromFile(); // == transform->setActualBufferAddress(transform->mFlatBufferContainer);
238 return transform;
239}
240
241#endif
242
243#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
248
249void TPCSlowSpaceChargeCorrection::getCorrections(const float gx, const float gy, const float gz, const int32_t slice, float& gdxC, float& gdyC, float& gdzC) const
250{
252 mCorr->getCorrections(gx, gy, gz, side, gdxC, gdyC, gdzC);
253}
254
256{
257 mCorrectionSlow = new TPCSlowSpaceChargeCorrection;
258 mCorrectionSlow->mCorr = new o2::tpc::SpaceCharge<float>();
259 mCorrectionSlow->mCorr->setGlobalCorrectionsFromFile<float>(inpf, o2::tpc::Side::A);
260 mCorrectionSlow->mCorr->setGlobalCorrectionsFromFile<float>(inpf, o2::tpc::Side::C);
261}
262#endif
263
264float TPCFastTransform::getIDC() const
265{
266 auto val = mIDC;
267 if (!isIDCSet()) {
268 if (mLumi < mCTP2IDCFallBackThreshold) {
269#if !defined(GPUCA_GPUCODE)
270 bool static report = true;
271 if (report) {
272 report = false;
273 LOG(warn) << "IDC scaling is requested but map IDC record is empty. Since map Lumi " << mLumi << " is less than fall-back threshold " << mCTP2IDCFallBackThreshold << ", interpret Lumi record as IDC";
274 }
275#endif
276 val = mLumi;
277 } else {
278#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
279 LOG(fatal) << "IDC scaling is requested but map IDC record is empty. The map Lumi " << mLumi << " exceeds Lumi->IDC fall-back threshold " << mCTP2IDCFallBackThreshold;
280#endif
281 }
282 }
283 return val;
284}
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.
static constexpr float DEFLUMI
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.
static constexpr float DEFIDC
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 * val
Definition glcorearb.h:1582
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition glcorearb.h:5034
void report(gsl::span< o2::InteractionTimeRecord > irs, int threshold, bool verbose)
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"