Project
Loading...
Searching...
No Matches
DigitPayloadEncoder.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
17#include "Framework/Logger.h"
22#include <cstdint>
23#include <fmt/printf.h>
24#include <functional>
25#include <gsl/span>
26#include <memory>
27#include "Framework/Logger.h"
28
29namespace o2::mch::raw
30{
32{
33 return fmt::format("DetID {:4d} PadId {:10d} ADC {:10d} TFtime {:10d} NofSamples {:5d} {}",
34 d.getDetID(), d.getPadID(), d.getADC(), d.getTime(), d.getNofSamples(),
35 d.isSaturated() ? "(S)" : "");
36}
37
39 PayloadEncoder& encoder)
40 : mDigit2ElecMapper{digit2elec}, mEncoder{encoder}
41{
42}
43
44void DigitPayloadEncoder::encodeDigits(gsl::span<o2::mch::Digit> digits,
45 uint32_t orbit,
46 uint16_t bc,
47 std::vector<std::byte>& buffer)
48{
49 mEncoder.startHeartbeatFrame(orbit, bc);
50 for (auto d : digits) {
51 auto optElecId = mDigit2ElecMapper(d);
52 if (!optElecId.has_value()) {
53 LOGP(warning, "could not get elecId for digit {}", asString(d));
54 continue;
55 }
56 auto elecId = optElecId.value().first;
57 int dualSampaChannelId = optElecId.value().second;
58 // FIXME : what to put as rel time ?
59 uint10_t ts = 0;
61 uint20_t bxCount = sampaBunchCrossingCounter(orbit, bc, firstIR.orbit);
62 auto clusters = {raw::SampaCluster(ts, bxCount, d.getADC(), d.getNofSamples())};
63 mEncoder.addChannelData(elecId, dualSampaChannelId, clusters);
64 }
65 mEncoder.moveToBuffer(buffer);
66}
67} // namespace o2::mch::raw
uint64_t orbit
Definition RawEventData.h:6
uint64_t bc
Definition RawEventData.h:5
MCH digit implementation.
Definition Digit.h:31
int getPadID() const
Definition Digit.h:54
int getDetID() const
Definition Digit.h:52
uint16_t getNofSamples() const
Definition Digit.cxx:39
bool isSaturated() const
Definition Digit.cxx:44
int32_t getTime() const
Definition Digit.h:44
uint32_t getADC() const
Definition Digit.h:57
DigitPayloadEncoder(Digit2ElecMapper digit2elec, PayloadEncoder &encoder)
void encodeDigits(gsl::span< o2::mch::Digit > digits, uint32_t orbit, uint16_t bc, std::vector< std::byte > &buffer)
A PayloadEncoder builds MCH raw data (payload part only)
virtual void startHeartbeatFrame(uint32_t orbit, uint16_t bunchCrossing)=0
virtual void addChannelData(DsElecId dsId, DualSampaChannelId chId, const std::vector< SampaCluster > &data)=0
virtual size_t moveToBuffer(std::vector< std::byte > &buffer)=0
GLuint buffer
Definition glcorearb.h:655
uint16_t uint10_t
Definition DataFormats.h:67
std::function< std::optional< std::pair< DsElecId, int > >(const o2::mch::Digit &digit)> Digit2ElecMapper
uint20_t sampaBunchCrossingCounter(uint32_t orbit, uint16_t bc, uint32_t firstOrbit)
uint32_t uint20_t
Definition DataFormats.h:68
std::string asString(const SampaCluster &sc)
Piece of data for one Sampa channel.
IR getFirstSampledTFIR() const
get TF and HB (abs) for this IR
Definition HBFUtils.h:74
std::vector< Cluster > clusters
std::vector< Digit > digits