72void PedestalData::fill(gsl::span<const PedestalDigit>
digits)
75 static std::mutex pedestalMutex;
76 static std::set<uint16_t> solarIds = o2::mch::raw::getSolarUIDs<o2::mch::raw::ElectronicMapperGenerated>();
82 LOGP(info,
"processing {} digits with {} threads", (
int)
digits.size(), mNThreads);
85 std::queue<uint16_t> solarQueue;
86 for (
auto solarId : solarIds) {
87 solarQueue.push(solarId);
90 auto processSolarDigits = [&]() {
92 int targetSolarId = -1;
93 PedestalsMap::iterator iPedestal;
94 bool pedestalsAreInitialized;
98 std::lock_guard<std::mutex> lock(pedestalMutex);
101 if (solarQueue.empty()) {
106 targetSolarId = solarQueue.front();
110 iPedestal = mPedestals.find(targetSolarId);
111 if (iPedestal == mPedestals.end()) {
112 pedestalsAreInitialized =
false;
114 pedestalsAreInitialized =
true;
120 uint16_t solarId = d.getSolarId();
121 if (solarId != targetSolarId) {
126 if (!pedestalsAreInitialized) {
127 std::lock_guard<std::mutex> lock(pedestalMutex);
130 iPedestal = mPedestals.emplace(std::make_pair(targetSolarId, initPedestalMatrix(targetSolarId))).first;
132 if (iPedestal == mPedestals.end()) {
133 LOGP(fatal,
"failed to insert new element in padestals map");
136 pedestalsAreInitialized =
true;
139 uint8_t dsId = d.getDsId();
140 uint8_t channel = d.getChannel();
142 auto& ped = iPedestal->second[dsId][channel];
144 for (uint16_t
i = 0;
i < d.nofSamples();
i++) {
145 auto s = d.getSample(
i);
148 uint64_t N = ped.mEntries;
150 double p0 = ped.mPedestal;
151 double p = p0 + (s - p0) / N;
154 double M0 = ped.mVariance;
155 double M = M0 + (s - p0) * (s - p);
160 LOGP(info,
"solarId {} dsId {} ch {} nsamples {} entries{} mean {} variance {}",
161 (
int)solarId, (
int)dsId, (
int)channel, d.nofSamples(), ped.mEntries, ped.mPedestal, ped.mVariance);
168 std::vector<std::thread> threads;
169 for (
int ti = 0; ti < mNThreads; ti++) {
170 threads.emplace_back(processSolarDigits);
174 for (
auto& thread : threads) {