Project
Loading...
Searching...
No Matches
TOFCalibCollector.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
13#include "Framework/Logger.h"
14#include <cassert>
15#include <iostream>
16#include <sstream>
17#include <numeric>
18#include <TStopwatch.h>
19
20namespace o2
21{
22namespace tof
23{
24
26
27//_____________________________________________
28void TOFCalibInfoSlot::fill(const gsl::span<const o2::dataformats::CalibInfoTOF> data)
29{
30 // fill container
31 // we do not apply any calibration at this stage, it will be applied when we
32 // process the data before filling the CCDB in the separate process
33
34 // we first order the data that arrived, to improve speed when filling
35 int nd = data.size();
36 LOG(info) << "entries in incoming data = " << nd;
37 for (int i = 0; i < nd; i++) {
38 auto flags = data[i].getFlags();
39 if (flags & o2::dataformats::CalibInfoTOF::kMultiHit) { // skip multi-hit clusters
40 continue;
41 }
42 if (flags & o2::dataformats::CalibInfoTOF::kNoBC) { // skip events far from Int BC
43 continue;
44 }
45
46 mTOFCollectedCalibInfoSlot.emplace_back(data[i].getTOFChIndex(), data[i].getTimestamp(), data[i].getDeltaTimePi() - mLHCphase, data[i].getTot(), data[i].getFlags());
47 mEntriesSlot[data[i].getTOFChIndex()]++;
48 }
49}
50//_____________________________________________
51void TOFCalibInfoSlot::fill(const gsl::span<const o2::tof::CalibInfoCluster> data)
52{
53 // fill container
54 // we do not apply any calibration at this stage, it will be applied when we
55 // process the data before filling the CCDB in the separate process
56
57 // we first order the data that arrived, to improve speed when filling
58 int nd = data.size();
59 LOG(debug) << "entries in incoming data = " << nd;
60 std::vector<int> ord(nd);
61 std::iota(ord.begin(), ord.end(), 0);
62 std::sort(ord.begin(), ord.end(), [&data](int i, int j) { return data[i].getCH() < data[j].getCH(); });
63 int chPrev = 0, offsPrev = 0;
64 for (int i = 0; i < nd; i++) {
65 const auto& dti = data[ord[i]];
66 auto ch = dti.getCH();
67 auto dch = dti.getDCH();
68 auto dt = dti.getDT();
69 auto tot1 = dti.getTOT1();
70 auto tot2 = dti.getTOT2();
71
72 // we order them so that the channel number of the first cluster is smaller than
73 // the one of the second cluster
74 if (dch < 0) {
75 ch += dch;
76 dt = -dt;
77 dch = -dch;
78 float inv = tot1;
79 tot1 = tot2;
80 tot2 = inv;
81 }
82
83 auto offset = offsPrev;
84 if (ch > chPrev) {
85 offset += std::accumulate(mEntriesSlot.begin() + chPrev, mEntriesSlot.begin() + ch, 0);
86 }
87 offsPrev = offset;
88 chPrev = ch;
89
90 // TO be adjusted
91 //mTOFCollectedCalibInfoSlot.emplace(mTOFCollectedCalibInfoSlot.begin() + offset, data[ord[i]].getTimestamp(), data[ord[i]].getDeltaTimePi(), data[ord[i]].getTot(), data[ord[i]].getFlags());
92 //mEntriesSlot[ch]++;
93 }
94}
95//_____________________________________________
97{
98 // merge data of 2 slots
99
100 LOG(debug) << "Merging two slots with entries: current slot -> " << mTOFCollectedCalibInfoSlot.size() << " , previous slot -> " << prev->mTOFCollectedCalibInfoSlot.size();
101
102 int offset = 0, offsetPrev = 0;
103 std::vector<o2::dataformats::CalibInfoTOF> tmpVector;
104 for (int ch = 0; ch < Geo::NCHANNELS; ch++) {
105 if (mEntriesSlot[ch] != 0) {
106 for (int i = offset; i < offset + mEntriesSlot[ch]; i++) {
107 tmpVector.emplace_back(mTOFCollectedCalibInfoSlot[i]);
108 }
109 offset += mEntriesSlot[ch];
110 }
111 if (prev->mEntriesSlot[ch] != 0) {
112 for (int i = offsetPrev; i < offsetPrev + prev->mEntriesSlot[ch]; i++) {
113 tmpVector.emplace_back(prev->mTOFCollectedCalibInfoSlot[i]);
114 }
115 offsetPrev += prev->mEntriesSlot[ch];
116 mEntriesSlot[ch] += prev->mEntriesSlot[ch];
117 }
118 }
119 mTOFCollectedCalibInfoSlot.swap(tmpVector);
120 LOG(debug) << "After merging the size is " << mTOFCollectedCalibInfoSlot.size();
121 return;
122}
123//_____________________________________________
125{
126 // to print number of entries in the tree and the channel with the max number of entries
127
128 LOG(info) << "Total number of entries " << mTOFCollectedCalibInfoSlot.size();
129 auto maxElementIndex = std::max_element(mEntriesSlot.begin(), mEntriesSlot.end());
130 auto channelIndex = std::distance(mEntriesSlot.begin(), maxElementIndex);
131 LOG(info) << "The maximum number of entries per channel in the current mTOFCollectedCalibInfo is " << *maxElementIndex << " for channel " << channelIndex;
132 return;
133}
134
135//_____________________________________________
137{
138 // to print number of entries in the tree and per channel
139
140 LOG(info) << "Total number of entries " << mTOFCollectedCalibInfoSlot.size();
141 for (int i = 0; i < mEntriesSlot.size(); ++i) {
142 if (mEntriesSlot[i] != 0) {
143 LOG(info) << "channel " << i << " has " << mEntriesSlot[i] << " entries";
144 }
145 }
146 return;
147}
148
149//===================================================================
150
151//_____________________________________________
153{
154 // emptying the vectors
155
156 mTOFCollectedCalibInfo.clear();
157 for (int ch = 0; ch < Geo::NCHANNELS; ch++) {
158 mEntries[ch] = 0;
159 }
160
161 return;
162}
163
164//_____________________________________________
166{
167
168 // We define that we have enough data if the tree is big enough.
169 // each CalibInfoTOFShort is composed of one int, two floats, one unsigned char --> 13 bytes
170 // E.g. supposing that we have 256 entries per channel (which is an upper limit ) --> ~523 MB
171 // we can check if we have at least 1 GB of data --> 500*o2::tof::Geo::NCHANNELS entries in the vector
172 // (see header file for the fact that mMaxNumOfHits = 500)
173 // The case in which mScaleMaxNumOfHits = false allows for a fast check
174
175 if (mTest) {
176 return true;
177 }
179 LOG(info) << "we have " << c->getCollectedCalibInfoSlot().size() << " entries";
180 int maxNumberOfHits = mAbsMaxNumOfHits ? mMaxNumOfHits : mMaxNumOfHits * o2::tof::Geo::NCHANNELS;
181 if (mTFsendingPolicy || c->getCollectedCalibInfoSlot().size() > maxNumberOfHits) {
182 return true;
183 }
184 return false;
185}
186
187//_____________________________________________
189{
190 // here we fill the tree with the remaining stuff that was not filled before
191
193 mTOFCollectedCalibInfo = c->getCollectedCalibInfoSlot();
194 // let's sort before to write
195 std::sort(mTOFCollectedCalibInfo.begin(), mTOFCollectedCalibInfo.end(), [](const o2::dataformats::CalibInfoTOF& a, const o2::dataformats::CalibInfoTOF& b) { return a.getTOFChIndex() < b.getTOFChIndex(); });
196 LOG(debug) << "vector of CalibTOFInfoShort received with size = " << mTOFCollectedCalibInfo.size();
197 mEntries = c->getEntriesPerChannel();
198 return;
199}
200
201//_____________________________________________
202Slot& TOFCalibCollector::emplaceNewSlot(bool front, TFType tstart, TFType tend)
203{
204
205 auto& cont = getSlots();
206 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
207 slot.setContainer(std::make_unique<TOFCalibInfoSlot>(mLHCphase));
208 return slot;
209}
210
211} // end namespace tof
212} // end namespace o2
int32_t i
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
std::ostringstream debug
const Container * getContainer() const
Definition TimeSlot.h:53
static constexpr int NCHANNELS
Definition Geo.h:124
Slot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
void finalizeSlot(Slot &slot) final
bool hasEnoughData(const Slot &slot) const final
void merge(const TOFCalibInfoSlot *prev)
void fill(const gsl::span< const o2::dataformats::CalibInfoTOF > data)
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
GLbitfield flags
Definition glcorearb.h:1570
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"