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_STANDALONE)
18#include "Rtypes.h"
19#endif
20
21#include "TPCFastTransform.h"
22#include "GPUCommonLogger.h"
23
24#include <iostream>
25
26#if !defined(GPUCA_STANDALONE)
27#include "TFile.h"
28#include "GPUCommonLogger.h"
29#endif
30
31#if !defined(GPUCA_STANDALONE)
33#endif
34
35using namespace o2::gpu;
36
38 : FlatObject(), mTimeStamp(0), mCorrection(), mApplyCorrection(1), mT0(0.f), mVdrift(0.f), mLumi(TPCFastTransform::DEFLUMI), mLumiError(0.f), mLumiScaleFactor(1.0f), mIDC(TPCFastTransform::DEFIDC), mIDCError(0.f), mCTP2IDCFallBackThreshold(30.f)
39{
40 // Default Constructor: creates an empty uninitialized object
41}
42
43void TPCFastTransform::cloneFromObject(const TPCFastTransform& obj, char* newFlatBufferPtr)
44{
46
47 const char* oldFlatBufferPtr = obj.mFlatBufferPtr;
48
49 FlatObject::cloneFromObject(obj, newFlatBufferPtr);
50
51 mTimeStamp = obj.mTimeStamp;
52 mApplyCorrection = obj.mApplyCorrection;
53 mT0 = obj.mT0;
54 mVdrift = obj.mVdrift;
55 mLumi = obj.mLumi;
56 mLumiError = obj.mLumiError;
57 mIDC = obj.mIDC;
58 mIDCError = obj.mIDCError;
59 mCTP2IDCFallBackThreshold = obj.mCTP2IDCFallBackThreshold;
60 mLumiScaleFactor = obj.mLumiScaleFactor;
61 // variable-size data
62
63 char* distBuffer = FlatObject::relocatePointer(oldFlatBufferPtr, mFlatBufferPtr, obj.mCorrection.getFlatBufferPtr());
64 mCorrection.cloneFromObject(obj.mCorrection, distBuffer);
65}
66
67void TPCFastTransform::moveBufferTo(char* newFlatBufferPtr)
68{
70 FlatObject::moveBufferTo(newFlatBufferPtr);
72}
73
74void TPCFastTransform::setActualBufferAddress(char* actualFlatBufferPtr)
75{
77 FlatObject::setActualBufferAddress(actualFlatBufferPtr);
79}
80
81void TPCFastTransform::setFutureBufferAddress(char* futureFlatBufferPtr)
82{
84
85 const char* oldFlatBufferPtr = mFlatBufferPtr;
86
87 char* distBuffer = FlatObject::relocatePointer(oldFlatBufferPtr, futureFlatBufferPtr, mCorrection.getFlatBufferPtr());
88 mCorrection.setFutureBufferAddress(distBuffer);
89 FlatObject::setFutureBufferAddress(futureFlatBufferPtr);
90}
91
93{
95
97
98 assert(correction.isConstructed());
99
100 mTimeStamp = 0;
101 mApplyCorrection = 1;
102 mT0 = 0.f;
103 mVdrift = 0.f;
104 mLumi = DEFLUMI;
105 mLumiError = 0.f;
106 mIDC = DEFIDC;
107 mIDCError = 0.f;
108 mCTP2IDCFallBackThreshold = 30.f;
109 mLumiScaleFactor = 1.f;
110
111 // variable-size data
112
113 mCorrection.cloneFromObject(correction, nullptr);
114}
115
116void TPCFastTransform::setCalibration(int64_t timeStamp, float t0, float vDrift)
117{
122
123 mTimeStamp = timeStamp;
124 mT0 = t0;
125 mVdrift = vDrift;
126 mConstructionMask |= ConstructionExtraState::CalibrationIsSet;
127}
128
130{
132
133 assert(mConstructionMask & ConstructionState::InProgress); // construction in process
134 assert(mConstructionMask & ConstructionExtraState::CalibrationIsSet); // all parameters are set
135
136 FlatObject::finishConstruction(mCorrection.getFlatBufferSize());
137
138 mCorrection.moveBufferTo(mFlatBufferPtr);
139}
140
142{
143 LOG(info) << "TPC Fast Transformation: ";
144 LOG(info) << "mTimeStamp = " << mTimeStamp;
145 LOG(info) << "mApplyCorrection = " << mApplyCorrection;
146 LOG(info) << "mT0 = " << mT0;
147 LOG(info) << "mVdrift = " << mVdrift;
148 LOG(info) << "mLumi = " << mLumi;
149 LOG(info) << "mLumiError = " << mLumiError;
150 LOG(info) << "mIDC = " << mIDC;
151 LOG(info) << "mIDCError = " << mIDCError;
152 LOG(info) << "mCTP2IDCFallBackThreshold = " << mCTP2IDCFallBackThreshold;
153 LOG(info) << "mLumiScaleFactor = " << mLumiScaleFactor;
154 mCorrection.print();
155}
156
157#if !defined(GPUCA_STANDALONE)
158
159int32_t TPCFastTransform::writeToFile(std::string outFName, std::string name)
160{
162 assert(isConstructed());
163
164 if (outFName.empty()) {
165 outFName = "tpcFastTransform.root";
166 }
167 if (name.empty()) {
168 name = "TPCFastTransform";
169 }
170 TFile outf(outFName.data(), "recreate");
171 if (outf.IsZombie()) {
172 LOG(error) << "Failed to open output file " << outFName;
173 return -1;
174 }
175
176 bool isBufferExternal = !isBufferInternal();
177 if (isBufferExternal) {
179 }
180 outf.WriteObjectAny(this, Class(), name.data());
181 outf.Close();
182 if (isBufferExternal) {
184 }
185 return 0;
186}
187
192
193TPCFastTransform* TPCFastTransform::loadFromFile(std::string inpFName, std::string name)
194{
196
197 if (inpFName.empty()) {
198 inpFName = "tpcFastTransform.root";
199 }
200 if (name.empty()) {
201 name = "TPCFastTransform";
202 }
203 TFile inpf(inpFName.data());
204 if (inpf.IsZombie()) {
205 LOG(error) << "Failed to open input file " << inpFName;
206 return nullptr;
207 }
208 TPCFastTransform* transform = reinterpret_cast<TPCFastTransform*>(inpf.GetObjectChecked(name.data(), TPCFastTransform::Class()));
209 if (!transform) {
210 LOG(error) << "Failed to load " << name << " from " << inpFName;
211 return nullptr;
212 }
213 if (transform->mFlatBufferSize > 0 && transform->mFlatBufferContainer == nullptr) {
214 LOG(error) << "Failed to load " << name << " from " << inpFName << ": empty flat buffer container";
215 return nullptr;
216 }
217 transform->rectifyAfterReadingFromFile(); // == transform->setActualBufferAddress(transform->mFlatBufferContainer);
218 return transform;
219}
220
221#endif
222
223#if !defined(GPUCA_STANDALONE)
228
229void TPCSlowSpaceChargeCorrection::getCorrections(const float gx, const float gy, const float gz, const int32_t slice, float& gdxC, float& gdyC, float& gdzC) const
230{
232 mCorr->getCorrections(gx, gy, gz, side, gdxC, gdyC, gdzC);
233}
234
236{
237 mCorrectionSlow = new TPCSlowSpaceChargeCorrection;
238 mCorrectionSlow->mCorr = new o2::tpc::SpaceCharge<float>();
239 mCorrectionSlow->mCorr->setGlobalCorrectionsFromFile<float>(inpf, o2::tpc::Side::A);
240 mCorrectionSlow->mCorr->setGlobalCorrectionsFromFile<float>(inpf, o2::tpc::Side::C);
241}
242#endif
243
244float TPCFastTransform::getIDC() const
245{
246 auto val = mIDC;
247 if (!isIDCSet()) {
248 if (mLumi < mCTP2IDCFallBackThreshold) {
249 bool static report = true;
250 if (report) {
251 report = false;
252 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";
253 }
254 val = mLumi;
255 } else {
256#if !defined(GPUCA_STANDALONE)
257 LOG(fatal) << "IDC scaling is requested but map IDC record is empty. The map Lumi " << mLumi << " exceeds Lumi->IDC fall-back threshold " << mCTP2IDCFallBackThreshold;
258#endif
259 }
260 }
261 return val;
262}
uint32_t side
Definition RawData.h:0
This class contains the algorithms for calculation the distortions and corrections.
Definition of TPCFastTransform class.
void setFutureBufferAddress(char *futureFlatBufferPtr)
Definition FlatObject.h:569
uint32_t mConstructionMask
mask for constructed object members, first two bytes are used by this class
Definition FlatObject.h:321
int32_t mFlatBufferSize
size of the flat buffer
Definition FlatObject.h:320
void adoptInternalBuffer(char *buf)
Definition FlatObject.h:546
char * mFlatBufferContainer
Definition FlatObject.h:322
bool isConstructed() const
Tells if the object is constructed.
Definition FlatObject.h:260
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:283
void setActualBufferAddress(char *actualFlatBufferPtr)
_____________ Methods for moving the class with its external buffer to another location _____________...
Definition FlatObject.h:559
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:354
void moveBufferTo(char *newBufferPtr)
Definition FlatObject.h:408
void finishConstruction(int32_t flatBufferSize)
Definition FlatObject.h:370
bool isBufferInternal() const
Tells if the buffer is internal.
Definition FlatObject.h:263
void cloneFromObject(const FlatObject &obj, char *newFlatBufferPtr)
Definition FlatObject.h:385
void clearInternalBufferPtr()
Definition FlatObject.h:553
@ InProgress
construction started: temporary memory is reserved
Definition FlatObject.h:317
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
int32_t writeToFile(std::string outFName="", std::string name="")
void setSlowTPCSCCorrection(TFile &inpf)
setting the reference corrections
void setCalibration(int64_t timeStamp, float t0, float vDrift)
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
void getCorrections(const float gx, const float gy, const float gz, const int32_t sector, float &gdxC, float &gdyC, float &gdzC) const
getting the corrections for global coordinates
o2::tpc::SpaceCharge< float > * mCorr
reference space charge corrections
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"