Project
Loading...
Searching...
No Matches
IntegratedClusterCalibrator.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
19
20namespace o2
21{
22namespace calibration
23{
24
25template <typename DataT>
26void IntegratedClusters<DataT>::dumpToFile(const char* outFileName, const char* outName) const
27{
28 TFile fOut(outFileName, "RECREATE");
29 fOut.WriteObject(this, outName);
30 fOut.Close();
31}
32
33template <typename DataT>
34void IntegratedClusters<DataT>::fill(const o2::calibration::TFType tfID, const DataT& currentsContainer)
35{
36 // check if size is same
37 if (!currentsContainer.areSameSize()) {
38 LOGP(warning, "Received data with different size. Returning");
39 return;
40 }
41
42 if (currentsContainer.isEmpty()) {
43 LOGP(info, "Empty data received. Returning");
44 return;
45 }
46
47 // initialize when first data is received
48 const unsigned int entries = currentsContainer.getEntries();
49 if (mInitialize) {
50 initData(entries);
51 }
52
53 // check if all data is already received (this should never happen)
54 if (mRemainingData == 0) {
55 LOGP(warning, "All packages already received. Returning");
56 return;
57 }
58
59 if (entries != mNValuesPerTF) {
60 LOGP(info, "Received data with size {} expected size {} (expected size can be ignored if merging was performed)", entries, mNValuesPerTF);
61 }
62
63 const unsigned int posIndex = (tfID - mTFFirst) * mNValuesPerTF;
64 if (posIndex + entries > mCurrents.getEntries()) {
65 LOGP(warning, "Index for TF {} is larger {} than expected max index {} with {} values per package", tfID, posIndex, mCurrents.getEntries(), mNValuesPerTF);
66 return;
67 }
68
69 // copy data to buffer
70 mCurrents.fill(posIndex, currentsContainer);
71
72 mRemainingData -= entries;
73 LOGP(debug, "Processed TF {} at index {} with first TF {} and {} expected currents per TF. Remaining data {}", tfID, posIndex, mTFFirst, mNValuesPerTF, mRemainingData);
74}
75
76template <typename DataT>
78{
79 LOGP(info, "Printing last object...");
80 prev->print();
81 LOGP(info, "Printing current object...");
82 print();
83
84 const auto tfMin = std::min(mTFFirst, prev->mTFFirst);
85 const auto tfMax = std::max(mTFLast, prev->mTFLast);
86
87 if (prev->mInitialize) {
88 // if last object was not initialized adjust tf range
89 mTFFirst = tfMin;
90 mTFLast = tfMax;
91 if (!mInitialize) {
92 // current buffer is already initialized just add empty values in front of buffer
93 LOGP(info, "Adding dummy data to front");
94 const unsigned int nDummyValues = mNValuesPerTF * ((prev->mTFLast - prev->mTFFirst) + 1);
95 mCurrents.insert(nDummyValues);
96 }
97 LOGP(info, "Do not merge last object since it was not initialized. Adjusting TF range:");
98 print();
99 return;
100 }
101
102 // check if current object needs to be initialized
103 if (mInitialize) {
104 // init with dummy vector
105 initData(prev->mNValuesPerTF);
106 }
107
108 // creating new temporary object with the range of current and last object
109 const unsigned int totalTFs = (tfMax - tfMin) + 1; // add 1 since first<= t <=last
110 const unsigned int nTotal = mNValuesPerTF * totalTFs;
111 IntegratedClusters dataTmp(tfMin, tfMax);
112 dataTmp.mInitialize = false; // do no initialization as it is done manually
113 dataTmp.mNValuesPerTF = mNValuesPerTF;
114 dataTmp.mRemainingData = -1;
115 dataTmp.mCurrents.resize(nTotal);
116
117 // fill buffered values to tmp objects
118 dataTmp.fill(mTFFirst, mCurrents);
119 dataTmp.fill(prev->mTFFirst, prev->mCurrents);
120
121 dataTmp.mRemainingData = mRemainingData;
122 *this = std::move(dataTmp);
123 LOGP(info, "Merging done", totalTFs);
124 print();
125}
126
127template <typename DataT>
128void IntegratedClusters<DataT>::initData(const unsigned int valuesPerTF)
129{
130 mInitialize = false;
131 const unsigned int totalTFs = (mTFLast - mTFFirst) + 1; // add 1 since first<= t <=last
132 mNValuesPerTF = valuesPerTF;
133 const unsigned int nTotal = mNValuesPerTF * totalTFs;
134 mCurrents.resize(nTotal);
135 mRemainingData = nTotal;
136 LOGP(info, "Init: Expecting {} packages with {} values per package with {} total values", mRemainingData, mNValuesPerTF, nTotal);
137}
138
139template <typename DataT>
140void IntegratedClusters<DataT>::dumpToTree(const char* outFileName)
141{
142 o2::utils::TreeStreamRedirector pcstream(outFileName, "RECREATE");
143 pcstream << "tree"
144 << "currents=" << mCurrents
145 << "firstTF=" << mTFFirst
146 << "lastTF=" << mTFLast
147 << "remainingData=" << mRemainingData
148 << "valuesPerTF=" << mNValuesPerTF
149 << "\n";
150}
151
152template <typename DataT>
154{
155 mIntervals.clear();
156 mCalibs.clear();
157 mTimeIntervals.clear();
158}
159
160template <typename DataT>
162{
163 const TFType startTF = slot.getTFStart();
164 const TFType endTF = slot.getTFEnd();
165 LOGP(info, "Finalizing slot {} <= TF <= {}", startTF, endTF);
166
167 auto& integratedClusters = *slot.getContainer();
168 integratedClusters.setStartTime(slot.getStartTimeMS());
169 if (mDebug) {
170 integratedClusters.dumpToFile(fmt::format("IntegratedClusters_TF_{}_{}_TS_{}_{}.root", startTF, endTF, slot.getStartTimeMS(), slot.getEndTimeMS()).data());
171 }
172 mCalibs.emplace_back(std::move(integratedClusters).getCurrents());
173
174 mIntervals.emplace_back(startTF, endTF);
175 mTimeIntervals.emplace_back(slot.getStartTimeMS(), slot.getEndTimeMS());
176}
177
179template <typename DataT>
181{
182 auto& cont = this->getSlots();
183 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
184 slot.setContainer(std::make_unique<IntegratedClusters<DataT>>(tstart, tend));
185 return slot;
186}
187
190
193
196
199
202
203} // end namespace calibration
204
205} // end namespace o2
void print() const
calibrator class for accumulating integrated clusters
std::ostringstream debug
void initOutput() final
clearing all calibration objects in the output buffer
Slot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
Creates new time slot.
void finalizeSlot(Slot &slot) final
storing the integrated currents for given slot
class for accumulating integrated currents
void dumpToTree(const char *outFileName="ICTree.root")
void merge(const IntegratedClusters *prev)
merging TOF currents with previous interval
void print() const
print summary informations
void fill(const o2::calibration::TFType tfID, const DataT &currentsContainer)
void dumpToFile(const char *outFileName="IntegratedClusters.root", const char *outName="IC") const
uint32_t TFType
Definition TimeSlot.h:29
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...