16#ifndef O2_ZDC_CTFCODER_H
17#define O2_ZDC_CTFCODER_H
42 template <typename VEC>
46 template <typename VTRG, typename VCHAN, typename VPED>
47 o2::ctf::CTFIOSize
decode(const
CTF::base& ec, VTRG& trigVec, VCHAN& chanVec, VPED& pedVec);
55 template <
typename VEC>
56 o2::ctf::CTFIOSize encode_impl(VEC& buff,
const gsl::span<const BCData>& trgData,
const gsl::span<const ChannelData>& chanData,
const gsl::span<const OrbitData>& pedData);
57 void appendToTree(TTree&
tree,
CTF& ec);
58 void readFromTree(TTree&
tree,
int entry, std::vector<BCData>& trigVec, std::vector<ChannelData>& chanVec, std::vector<OrbitData>& pedVec);
59 std::vector<BCData> mTrgDataFilt;
60 std::vector<ChannelData> mChanDataFilt;
61 std::vector<OrbitData> mPedDataFilt;
62 int64_t mBCShiftOrbits = 0;
66template <
typename VEC>
70 std::unordered_map<uint32_t, int> orbitSaved;
72 mChanDataFilt.clear();
74 for (
const auto& trig : trigData) {
76 mTrgDataFilt.push_back(trig);
77 auto chanIt = chanData.begin() + trig.ref.getFirstEntry();
78 auto& trigC = mTrgDataFilt.back();
79 trigC.ref.set((
int)mChanDataFilt.size(), trig.ref.getEntries());
80 std::copy(chanIt, chanIt + trig.ref.getEntries(), std::back_inserter(mChanDataFilt));
81 orbitSaved[trig.ir.orbit]++;
85 for (
const auto& ped : pedData) {
86 if (orbitSaved.find(ped.ir.orbit) != orbitSaved.end()) {
87 mPedDataFilt.push_back(ped);
90 return encode_impl(buff, mTrgDataFilt, mChanDataFilt, mPedDataFilt);
92 return encode_impl(buff, trigData, chanData, pedData);
95template <
typename VEC>
96o2::ctf::CTFIOSize CTFCoder::encode_impl(VEC& buff,
const gsl::span<const BCData>& trigData,
const gsl::span<const ChannelData>& chanData,
const gsl::span<const OrbitData>& pedData)
117 CTFHelper helper(trigData, chanData, pedData);
120 auto szIni =
sizeof(CTFHeader) + helper.getSize() * 2. / 3;
126 ec->setHeader(helper.createHeader());
131#define ENCODEZDC(beg, end, slot, bits) CTF::get(buff.data())->encode(beg, end, int(slot), bits, optField[int(slot)], &buff, mCoders[int(slot)], getMemMarginFactor());
150 finaliseCTFOutput<CTF>(buff);
151 iosize.
rawIn =
sizeof(BCData) * trigData.size() +
sizeof(ChannelData) * chanData.size() +
sizeof(OrbitData) * pedData.size();
156template <
typename VTRG,
typename VCHAN,
typename VPED>
162 std::vector<int16_t> bcIncTrig, scalerInc;
163 std::vector<int32_t> orbitIncTrig, orbitIncEOD;
164 std::vector<uint16_t> moduleTrig, nchanTrig, chanData, pedData, triggersHL, channelsHL;
165 std::vector<uint8_t> extTriggers, chanID;
168#define DECODEZDC(part, slot) ec.decode(part, int(slot), mCoders[int(slot)])
189 trigVec.reserve(header.nTriggers);
190 chanVec.reserve(header.nChannels);
191 pedVec.reserve(header.nEOData);
194 uint32_t firstEntry = 0;
196 auto chanDataIt = chanData.begin();
197 auto chanIdIt = chanID.begin();
198 auto modTrigIt = moduleTrig.begin();
199 auto pedValIt = pedData.begin();
200 auto sclIncIt = scalerInc.begin();
201 auto channelsHLIt = channelsHL.begin();
202 auto triggersHLIt = triggersHL.begin();
203 auto scalers = header.firstScaler;
205 for (uint32_t itrig = 0; itrig < header.nTriggers; itrig++) {
207 if (orbitIncTrig[itrig]) {
208 ir.
bc = bcIncTrig[itrig];
209 ir.
orbit += orbitIncTrig[itrig];
211 ir.
bc += bcIncTrig[itrig];
221 chanIdIt += nchanTrig[itrig];
226 auto firstChanEntry = chanVec.size();
227 for (uint16_t ic = 0; ic < nchanTrig[itrig]; ic++) {
228 auto& chan = chanVec.emplace_back();
229 chan.id = *chanIdIt++;
233 uint32_t chHL = (uint32_t(*channelsHLIt++) << 16) + *channelsHLIt++;
234 uint32_t trHL = (uint32_t(*triggersHLIt++) << 16) + *triggersHLIt++;
236 auto& bcTrig = trigVec.emplace_back(firstChanEntry, chanVec.size() - firstChanEntry,
ir - bcshift, chHL, trHL, extTriggers[itrig]);
237 std::copy_n(modTrigIt,
NModules, bcTrig.moduleTriggers.begin());
243 for (uint32_t ip = 0; ip < header.nEOData; ip++) {
256 for (uint32_t ic = 0; ic <
NChannels; ic++) {
257 scalers[ic] += *sclIncIt++;
259 auto& ped = pedVec.emplace_back(
OrbitData{
ir - bcshift, {}, scalers});
260 std::copy_n(pedValIt,
NChannels, ped.data.begin());
264 assert(chanDataIt == chanData.end());
265 assert(chanIdIt == chanID.end());
266 assert(modTrigIt == moduleTrig.end());
267 assert(pedValIt == pedData.end());
268 assert(channelsHLIt == channelsHL.end());
269 assert(triggersHLIt == triggersHL.end());
270 assert(sclIncIt == scalerInc.end());
Declarations for CTFCoderBase class (support of external dictionaries)
#define ENCODEZDC(beg, end, slot, bits)
#define DECODEZDC(part, slot)
Helper for ZDC CTF creation.
void checkDictVersion(const CTFDictHeader &h) const
ctf::ANSHeader mANSVersion
std::string getPrefix() const
o2::utils::IRFrameSelector mIRFrameSelector
virtual void assignDictVersion(CTFDictHeader &h) const
bool canApplyBCShift(const o2::InteractionRecord &ir, long shift) const
<<======================== Auxiliary classes =======================<<
static auto get(void *head)
cast arbitrary buffer head to container class. Head is supposed to respect the alignment
const H & getHeader() const
void print(const std::string &prefix="", int verbosity=1) const
print itself
static constexpr int getNBlocks()
EncodedBlocks< CTFHeader, N, uint32_t > base
static auto create(void *head, size_t sz)
create container from arbitrary buffer of predefined size (in bytes!!!). Head is supposed to respect ...
Static class with identifiers, bitmasks and names for ALICE detectors.
long check(o2::dataformats::IRFrame fr, size_t bwd=0, size_t fwd=0)
CTFCoder(o2::ctf::CTFCoderBase::OpType op)
~CTFCoder() final=default
void setBCShiftOrbits(long v)
o2::ctf::CTFIOSize decode(const CTF::base &ec, VTRG &trigVec, VCHAN &chanVec, VPED &pedVec)
entropy decode data from buffer with CTF
void createCoders(const std::vector< char > &bufVec, o2::ctf::CTFCoderBase::OpType op) final
o2::ctf::CTFIOSize encode(VEC &buff, const gsl::span< const BCData > &trgData, const gsl::span< const ChannelData > &chanData, const gsl::span< const OrbitData > &pedData)
entropy-encode data to buffer with CTF
auto getBCShiftOrbits() const
constexpr int LHCMaxBunches
struct o2::upgrades_utils::@463 zdc
structure to keep FT0 information
constexpr int NTimeBinsPerBC
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
uint16_t bc
bunch crossing ID of interaction
wrapper for the Entropy-encoded triggers and cells of the TF
o2::InteractionRecord ir(0, 0)
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))