Project
Loading...
Searching...
No Matches
HBFUtils.h
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
12// @brief Class to sample HBFrames for simulated interaction records + RDH utils
13// @author ruben.shahoyan@cern.ch
14
15#ifndef ALICEO2_HBFUTILS_H
16#define ALICEO2_HBFUTILS_H
17
18#include <Rtypes.h>
25
26namespace o2
27{
28namespace raw
29{
30/*
31 In the MC->Raw conversion we have to make sure that
32 1) The HB and TF starts are in sync for all detectors regardless on time (0/orbit)
33 distribution of its signal.
34 2) All HBF and TF (RAWDataHeaders with corresponding HB and TF trigger flags) are present
35 in the emulated raw data, even if some of them had no data in particular detector.
36
37 The HBFUtils class provides tools for interaction record -> HBF conversion and sampling
38 of IRs for which the HBF RDH should be added to the raw data from the CRU.
39
40 See testHBFUtils.cxx for the outline of generating HBF frames for simulated data.
41 */
42
43//_____________________________________________________________________
46
47 IR getFirstIR() const { return {0, orbitFirst}; }
48
49 int getNOrbitsPerTF() const { return nHBFPerTF; }
50
52 IR getIRHBF(uint32_t hbf) const { return getFirstIR() + int64_t(hbf) * o2::constants::lhc::LHCMaxBunches; }
53
55 IR getIRTF(uint32_t tf) const { return getIRHBF(tf * nHBFPerTF); }
56
58 uint32_t getHBF(const IR& rec) const;
59
61 uint32_t getTF(const IR& rec) const { return getHBF(rec) / nHBFPerTF; }
62
64 std::pair<int, int> getTFandHBinTF(const IR& rec) const
65 {
66 auto hbf = getHBF(rec);
67 return std::pair<int, int>(hbf / nHBFPerTF, hbf % nHBFPerTF);
68 }
69
71 IR getFirstIRofTF(const IR& rec) const { return getIRTF(getTF(rec)); }
72
75
77 std::pair<int, int> getTFandHB(const IR& rec) const
78 {
79 auto hbf = getHBF(rec);
80 return std::pair<int, int>(hbf / nHBFPerTF, hbf);
81 }
82
84 uint64_t getTFTimeStamp(const IR& rec) const
85 {
87 }
88
90 template <typename H>
91 H createRDH(const IR& rec, bool setHBTF = true) const;
92
94 template <typename H>
95 void updateRDH(H& rdh, const IR& rec, bool setHBTF = true) const;
96
97 /*//-------------------------------------------------------------------------------------
98 Fill provided vector (cleaned) by interaction records (bc/orbit) for HBFs, considering
99 BCs between interaction records "fromIR" and "toIR" (inclusive).
100 This method provides the IRs for RDHs to add obligatory for the MC->raw conversion,
101 in order to avoid missing HBFs (or even TFs)
102 Typical use case: assume we are converting to RAW data the digits corresponding to triggers
103 for Int.records ir[0], ir[1], ... ir[N]
104 The pseudo-code:
105
106 HBFUtils sampler;
107 uint8_t packetCounter = 0;
108 std::vector<o2::InteractionRecord> HBIRVec;
109 auto irFrom = sampler.getFirstIR();
110 for (int i=0;i<N;i++) {
111 int nHBF = sampler.fillHBIRvector(HBIRVec, irFrom, ir[i]);
112 irFrom = ir[i]+1;
113 // nHBF-1 HBframes don't have data, we need to create empty HBFs for them
114 for (int j=0;j<nHBF-1;j++) {
115 auto rdh = sampler.createRDH<RAWDataHeader>( HBIRVec[j] );
116 // dress rdh with cruID/FEE/Link ID
117 RDHUtils::setPacketCounter(rdh, packetCounter++);
118 RDHUtils::setMemorySize(rdh, sizeof(rdh));
119 RDHUtils::setOffsetToNext(rdh, sizeof(rdh));
120 FLUSH_TO_SINK(&rdh, sizeof(rdh)); // open empty HBF
121 RDHUtils::setStop(rdh, 0x1);
122 RDHUtils::setPageCounter(rdh, RDHUtils::getPageCounter()+1 );
123 FLUSH_TO_SINK(&rdh, sizeof(rdh)); // close empty HBF
124 }
125 // write RDH for the HBF with data
126 auto rdh = HBIRVec.back();
127 // dress rdh with cruID/FEE/Link ID, estimate size, offset etc. and flush
128 // flush raw data payload
129 }
130 // see tstHBFUtils for more details
131 //-------------------------------------------------------------------------------------*/
132 int fillHBIRvector(std::vector<IR>& dst, const IR& fromIR, const IR& toIR) const;
133
134 void print() const { printKeyValues(true); }
135
136 void checkConsistency() const;
137
138 int nHBFPerTF = 128;
139 bool obligatorySOR = false;
140 uint32_t orbitFirst = 0;
141 uint32_t runNumber = 0;
142 uint32_t orbitFirstSampled = 0;
143 uint32_t maxNOrbits = 0xffffffff;
144 uint64_t startTime = 0;
145
146 O2ParamDef(HBFUtils, "HBFUtils");
147};
148
149//_________________________________________________
150template <typename H>
151void HBFUtils::updateRDH(H& rdh, const IR& rec, bool setHBTF) const
152{
153 RDHUtils::setTriggerBC(rdh, rec.bc); // for RDH>4 the trigger and HB IR is the same!
154 RDHUtils::setTriggerOrbit(rdh, rec.orbit);
155
156 if (setHBTF) { // need to set the HBF IR and HB / TF trigger flags
157 auto tfhb = getTFandHBinTF(rec);
158 RDHUtils::setHeartBeatBC(rdh, 0);
160
161 if (rec.bc == 0) { // if we are starting new HB, set the HB trigger flag
162 auto trg = RDHUtils::getTriggerType(rdh) | (o2::trigger::ORBIT | o2::trigger::HB);
163 if (tfhb.second == 0) { // if we are starting new TF, set the TF trigger flag
164 trg |= o2::trigger::TF;
165 }
166 RDHUtils::setTriggerType(rdh, trg);
167 }
168 }
169}
170
171//_________________________________________________
172template <typename H>
173inline H HBFUtils::createRDH(const o2::InteractionRecord& rec, bool setHBTF) const
174{
175 H rdh;
176 updateRDH(rdh, rec, setHBTF);
177 return rdh;
178}
179
180} // namespace raw
181} // namespace o2
182
183#endif
Definition of the 32 Central Trigger System (CTS) Trigger Types defined in https://twiki....
Header to collect LHC related constants.
void printKeyValues(bool showProv=true, bool useLogger=false) const final
GLenum GLenum dst
Definition glcorearb.h:1767
constexpr int LHCMaxBunches
constexpr double LHCOrbitMUS
constexpr uint32_t TF
Definition Triggers.h:37
constexpr uint32_t ORBIT
Definition Triggers.h:26
constexpr uint32_t HB
Definition Triggers.h:27
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::unique_ptr< GPUReconstructionTimeframe > tf
GPUReconstruction * rec
uint32_t orbit
LHC orbit.
IR getFirstIRofTF(const IR &rec) const
get 1st IR of TF corresponding to the 1st sampled orbit (in MC)
Definition HBFUtils.h:71
bool obligatorySOR
in mc->raw always start from run 1st TF to set the SOR
Definition HBFUtils.h:139
std::pair< int, int > getTFandHBinTF(const IR &rec) const
get 1st IR of the TF corresponding to provided interaction record
Definition HBFUtils.h:64
uint64_t startTime
absolute time in ms corresponding to the start of the MC run
Definition HBFUtils.h:144
void updateRDH(H &rdh, const IR &rec, bool setHBTF=true) const
Definition HBFUtils.h:151
void checkConsistency() const
Definition HBFUtils.cxx:53
uint32_t runNumber
run number
Definition HBFUtils.h:141
uint32_t getHBF(const IR &rec) const
get TF ID corresponding to this IR
Definition HBFUtils.cxx:24
uint32_t maxNOrbits
max number of orbits to accept, used in digit->raw conversion
Definition HBFUtils.h:143
IR getFirstIR() const
Definition HBFUtils.h:47
IR getIRHBF(uint32_t hbf) const
get IR corresponding to start of the TF
Definition HBFUtils.h:52
O2ParamDef(HBFUtils, "HBFUtils")
void print() const
Definition HBFUtils.h:134
IR getFirstSampledTFIR() const
get TF and HB (abs) for this IR
Definition HBFUtils.h:74
uint32_t orbitFirstSampled
1st orbit sampled in the MC
Definition HBFUtils.h:142
std::pair< int, int > getTFandHB(const IR &rec) const
calculate TF timestamp in ms
Definition HBFUtils.h:77
IR getIRTF(uint32_t tf) const
get HBF ID corresponding to this IR
Definition HBFUtils.h:55
uint32_t getTF(const IR &rec) const
get TF and HB (within TF) for this IR
Definition HBFUtils.h:61
int nHBFPerTF
number of orbits per BC
Definition HBFUtils.h:138
uint64_t getTFTimeStamp(const IR &rec) const
create RDH for given IR
Definition HBFUtils.h:84
int fillHBIRvector(std::vector< IR > &dst, const IR &fromIR, const IR &toIR) const
Definition HBFUtils.cxx:37
uint32_t orbitFirst
orbit of 1st TF of the run
Definition HBFUtils.h:140
int getNOrbitsPerTF() const
get IR corresponding to start of the HBF
Definition HBFUtils.h:49
H createRDH(const IR &rec, bool setHBTF=true) const
update RDH for with given IR info
Definition HBFUtils.h:173
static void setTriggerType(H &rdh, uint32_t v, NOTPTR(H))
Definition RDHUtils.h:523
static void setTriggerBC(RDHv4 &rdh, uint16_t v)
Definition RDHUtils.h:433
static void setTriggerOrbit(RDHv4 &rdh, uint32_t v)
Definition RDHUtils.h:467
static void setHeartBeatOrbit(RDHv4 &rdh, uint32_t v)
Definition RDHUtils.h:362