Skip to content

Commit 5da9362

Browse files
authored
MCH: add bpackets output in calibrator (#10653)
* [MCH] added HBPackets output message The addition of HeartBeat packets at the output of the pedestals decoder allows to perform some additional diagnostics on the SAMPA chips synchronization, in particular at the QualityControl level * [MCH] fixed log messages
1 parent febbff0 commit 5da9362

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

Detectors/MUON/MCH/Calibration/src/pedestal-decoding-workflow.cxx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include "MCHBase/DecoderError.h"
4444
#include "MCHCalibration/PedestalDigit.h"
45+
#include "MCHBase/HeartBeatPacket.h"
4546

4647
#include "CommonUtils/ConfigurableParam.h"
4748

@@ -160,6 +161,7 @@ class PedestalsTask
160161
void reset()
161162
{
162163
mDigits.clear();
164+
mHBPackets.clear();
163165
mErrors.clear();
164166
}
165167

@@ -173,11 +175,24 @@ class PedestalsTask
173175

174176
auto tStart = std::chrono::high_resolution_clock::now();
175177

178+
auto heartBeatHandler = [&](DsElecId dsElecId, uint8_t chip, uint32_t bunchCrossing) {
179+
auto ds = dsElecId.elinkId();
180+
auto solar = dsElecId.solarId();
181+
182+
if (mDebug) {
183+
auto s = asString(dsElecId);
184+
LOGP(info, "HeartBeat: {}-CHIP{}", s, chip);
185+
}
186+
187+
mHBPackets.emplace_back(solar, ds, chip, bunchCrossing);
188+
};
189+
176190
auto channelHandler = [&](DsElecId dsElecId, uint8_t channel, o2::mch::raw::SampaCluster sc) {
177191
auto solarId = dsElecId.solarId();
178192
auto dsId = dsElecId.elinkId();
179193
if (mDebug) {
180-
std::cout << "New digit: SOLAR " << (int)solarId << " DS " << (int)dsId << " CH " << (int)channel << std::endl;
194+
auto s = asString(dsElecId);
195+
LOGP(info, "Digit: {}-CH{}", s, (int)channel);
181196
}
182197

183198
mDigits.emplace_back(o2::mch::calibration::PedestalDigit(solarId, dsId, channel, sc.bunchCrossing, 0, sc.samples));
@@ -196,29 +211,30 @@ class PedestalsTask
196211
if (mDebug) {
197212
auto& rdhAny = *reinterpret_cast<RDH*>(const_cast<std::byte*>(&(page[0])));
198213
Nrdhs += 1;
199-
std::cout << Nrdhs << "--\n";
214+
LOGP(info, "{}--", Nrdhs);
200215
o2::raw::RDHUtils::printRDH(rdhAny);
201216
}
202217

203218
if (!mDecoder) {
204219
DecodedDataHandlers handlers;
205220
handlers.sampaChannelHandler = channelHandler;
221+
handlers.sampaHeartBeatHandler = heartBeatHandler;
206222
handlers.sampaErrorHandler = errorHandler;
207223
mDecoder = mFee2Solar ? o2::mch::raw::createPageDecoder(page, handlers, mFee2Solar)
208224
: o2::mch::raw::createPageDecoder(page, handlers);
209225
}
210226
try {
211227
mDecoder(page);
212228
} catch (std::exception& e) {
213-
std::cout << e.what() << '\n';
229+
LOGP(error, "{}", e.what());
214230
}
215231
}
216232

217233
//_________________________________________________________________________________________________
218234
void decodeBuffer(gsl::span<const std::byte> buf)
219235
{
220236
if (mDebug) {
221-
std::cout << "\n\n============================\nStart of new buffer\n";
237+
LOGP(info, "\n\n============================\nStart of new buffer");
222238
}
223239
size_t bufSize = buf.size();
224240
size_t pageStart = 0;
@@ -306,7 +322,7 @@ class PedestalsTask
306322
loggerEnd = std::chrono::high_resolution_clock::now();
307323
std::chrono::duration<double, std::milli> loggerElapsed = loggerEnd - loggerStart;
308324
if (loggerElapsed.count() > mLoggingInterval) {
309-
LOG(info) << "Processed " << nDigits << " digits in " << nTF << " time frames";
325+
LOGP(info, "Processed {} digits in {} time frames", nDigits, nTF);
310326
nDigits = 0;
311327
nTF = 0;
312328
loggerStart = std::chrono::high_resolution_clock::now();
@@ -346,12 +362,16 @@ class PedestalsTask
346362
size_t digitsSize;
347363
char* digitsBuffer = createBuffer(mDigits, digitsSize);
348364

365+
size_t hbSize;
366+
char* hbBuffer = createBuffer(mHBPackets, hbSize);
367+
349368
size_t errorsSize;
350369
char* errorsBuffer = createBuffer(mErrors, errorsSize);
351370

352371
// create the output message
353372
auto freefct = [](void* data, void*) { free(data); };
354373
pc.outputs().adoptChunk(Output{header::gDataOriginMCH, "PDIGITS", 0}, digitsBuffer, digitsSize, freefct, nullptr);
374+
pc.outputs().adoptChunk(Output{header::gDataOriginMCH, "HBPACKETS", 0}, hbBuffer, hbSize, freefct, nullptr);
355375
pc.outputs().adoptChunk(Output{header::gDataOriginMCH, "ERRORS", 0}, errorsBuffer, errorsSize, freefct, nullptr);
356376

357377
logStats();
@@ -361,6 +381,7 @@ class PedestalsTask
361381
o2::mch::raw::PageDecoder mDecoder;
362382
SampaChannelHandler mChannelHandler;
363383
std::vector<o2::mch::calibration::PedestalDigit> mDigits;
384+
std::vector<o2::mch::HeartBeatPacket> mHBPackets;
364385
std::vector<o2::mch::DecoderError> mErrors;
365386

366387
Elec2DetMapper mElec2Det{nullptr};
@@ -400,11 +421,11 @@ using namespace o2::framework;
400421
//_________________________________________________________________________________________________
401422
o2::framework::DataProcessorSpec getMCHPedestalDecodingSpec(const char* specName, std::string inputSpec)
402423
{
403-
// o2::mch::raw::PedestalsTask task();
404424
return DataProcessorSpec{
405425
specName,
406426
o2::framework::select(inputSpec.c_str()),
407427
Outputs{OutputSpec{header::gDataOriginMCH, "PDIGITS", 0, Lifetime::Timeframe},
428+
OutputSpec{header::gDataOriginMCH, "HBPACKETS", 0, Lifetime::Timeframe},
408429
OutputSpec{header::gDataOriginMCH, "ERRORS", 0, Lifetime::Timeframe}},
409430
AlgorithmSpec{adaptFromTask<o2::mch::raw::PedestalsTask>(inputSpec)},
410431
Options{{"mch-debug", VariantType::Bool, false, {"enable verbose output"}},

0 commit comments

Comments
 (0)