Skip to content

Commit 90c3cf2

Browse files
dstoccoaphecetche
authored andcommitted
Synchronize MID data orbit with RDH orbit at TF limit
1 parent d1c21d2 commit 90c3cf2

File tree

8 files changed

+48
-54
lines changed

8 files changed

+48
-54
lines changed

Detectors/MUON/MID/Raw/include/MIDRaw/Decoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class Decoder
5050
/// Processes the page
5151
auto feeId = o2::raw::RDHUtils::getFEEID(rdh);
5252
#if defined(MID_RAW_VECTORS)
53-
mLinkDecoders[feeId]->process(payload, o2::raw::RDHUtils::getHeartBeatOrbit(rdh), mData, mROFRecords);
53+
mLinkDecoders[feeId]->process(payload, o2::raw::RDHUtils::getHeartBeatOrbit(rdh), o2::raw::RDHUtils::getTriggerType(rdh), mData, mROFRecords);
5454
#else
5555
auto linkDecoder = mLinkDecoders.find(feeId);
5656
if (linkDecoder != mLinkDecoders.end()) {
57-
linkDecoder->second->process(payload, o2::raw::RDHUtils::getHeartBeatOrbit(rdh), mData, mROFRecords);
57+
linkDecoder->second->process(payload, o2::raw::RDHUtils::getHeartBeatOrbit(rdh), o2::raw::RDHUtils::getTriggerType(rdh), mData, mROFRecords);
5858
} else {
5959
LOG(alarm) << "Unexpected feeId " << feeId << " in RDH";
6060
}

Detectors/MUON/MID/Raw/include/MIDRaw/ELinkDataShaper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ELinkDataShaper
3535
/// Main function to be executed when decoding is done
3636
inline void onDone(const ELinkDecoder& decoder, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs) { std::invoke(mOnDone, this, decoder, data, rofs); }
3737

38-
void set(uint32_t orbit);
38+
void set(uint32_t orbit, uint32_t trigger);
3939

4040
private:
4141
uint8_t mUniqueId = 0; /// UniqueId
@@ -58,7 +58,7 @@ class ELinkDataShaper
5858
void addLoc(const ELinkDecoder& decoder, EventType eventType, InteractionRecord ir, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs);
5959
bool checkLoc(const ELinkDecoder& decoder);
6060
EventType processCalibrationTrigger(const InteractionRecord& ir);
61-
void processOrbitTrigger(uint16_t localClock, uint8_t triggerWord);
61+
void processHBTrigger(uint16_t localClock, uint8_t triggerWord);
6262
EventType processSelfTriggered(InteractionRecord& ir);
6363
bool processTrigger(const ELinkDecoder& decoder, EventType& eventType, InteractionRecord& ir);
6464
};

Detectors/MUON/MID/Raw/include/MIDRaw/ELinkManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ELinkManager
3636
public:
3737
void init(uint16_t feeId, bool isDebugMode, bool isBare = false, const ElectronicsDelay& electronicsDelay = ElectronicsDelay(), const FEEIdConfig& feeIdConfig = FEEIdConfig());
3838

39-
void set(uint32_t orbit);
39+
void set(uint32_t orbit, uint32_t trigger);
4040

4141
/// Main function to be executed when decoding is done
4242
inline void onDone(const ELinkDecoder& decoder, uint8_t boardUniqueId, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs) { return onDone(decoder, raw::getCrateId(boardUniqueId), raw::getLocId(boardUniqueId), data, rofs); }

Detectors/MUON/MID/Raw/include/MIDRaw/LinkDecoder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ namespace mid
3434
class LinkDecoder
3535
{
3636
public:
37-
LinkDecoder(std::function<void(gsl::span<const uint8_t>, uint32_t orbit, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)> decode) : mDecode(decode) {}
38-
void process(gsl::span<const uint8_t> payload, uint32_t orbit, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs);
37+
LinkDecoder(std::function<void(gsl::span<const uint8_t>, uint32_t orbit, uint32_t trigger, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)> decode) : mDecode(decode) {}
38+
void process(gsl::span<const uint8_t> payload, uint32_t orbit, uint32_t trigger, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs);
3939

4040
template <class RDH>
4141
void process(gsl::span<const uint8_t> payload, const RDH& rdh, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
4242
{
43-
process(payload, o2::raw::RDHUtils::getHeartBeatOrbit(rdh), data, rofs);
43+
process(payload, o2::raw::RDHUtils::getHeartBeatOrbit(rdh), o2::raw::RDHUtils::getTriggerType(rdh), data, rofs);
4444
}
4545

4646
protected:
47-
std::function<void(gsl::span<const uint8_t>, uint32_t orbit, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)> mDecode{nullptr};
47+
std::function<void(gsl::span<const uint8_t>, uint32_t orbit, uint32_t trigger, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)> mDecode{nullptr};
4848
};
4949

5050
std::unique_ptr<LinkDecoder> createGBTDecoder(const o2::header::RDHAny& rdh, uint16_t feeId, bool isDebugMode, uint8_t mask, const ElectronicsDelay& electronicsDelay);

Detectors/MUON/MID/Raw/src/ELinkDataShaper.cxx

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "MIDRaw/ELinkDataShaper.h"
1818

1919
#include "CommonConstants/LHCConstants.h"
20-
// #define ORBITFROMMIDRO
20+
#include "CommonConstants/Triggers.h"
2121

2222
namespace o2
2323
{
@@ -43,27 +43,33 @@ ELinkDataShaper::ELinkDataShaper(bool isDebugMode, bool isLoc, uint8_t uniqueId,
4343
mLocalToBCSelfTrig = mElectronicsDelay.localToBC;
4444
if (!isLoc) {
4545
mLocalToBCSelfTrig -= electronicsDelay.localToReg;
46-
mElectronicsDelay.calibToFET += electronicsDelay.localToReg;
4746
}
47+
mElectronicsDelay.calibToFET += mLocalToBCSelfTrig;
4848
}
4949

50-
void ELinkDataShaper::set(uint32_t orbit)
50+
void ELinkDataShaper::set(uint32_t orbit, uint32_t trigger)
5151
{
5252
/// Sets the orbit and the output data vectors
53-
mRDHOrbit = orbit;
5453

5554
if (mIR.isDummy()) {
55+
// First initialization
5656
mIR.bc = 0;
57-
// The reset changes depending on the way we synch with the orbit
58-
// (see processOrbitTrigger for details)
59-
// FIXME: pick one of the two
60-
#ifdef ORBITFROMMIDRO
61-
mIR.orbit = orbit - 1; // with orbit increase
62-
#else
63-
mIR.orbit = orbit; // with reset to RDH
64-
#endif
57+
mIR.orbit = orbit - 1;
6558
mMaxBunches = constants::lhc::LHCMaxBunches;
59+
} else if ((trigger & o2::trigger::TF || trigger & o2::trigger::SOT) && mRDHOrbit != orbit) {
60+
// At TF limit, the CRU UL ensures that the first event is the answer of the electronics to a HB trigger,
61+
// so it is the right time to synch with the orbit in the RDH.
62+
// This also allows to consistently run on EPNs, since EPN receive packets of TFs
63+
// and the orbit is not consecutive from one packet to the other.
64+
// Notice that we subtract 1 to the orbit value, since the TF starts with the answer to a HB trigger,
65+
// and the value will be therefore correctly incremented.
66+
// Notice also that we might receive several RDH pages
67+
// (at least two since there is always an empty stop page),
68+
// but we want to set the orbit only for the first one.
69+
// The easiest way to do it is to check that the current orbit differs from the last saved RDH orbit.
70+
mIR.orbit = orbit - 1;
6671
}
72+
mRDHOrbit = orbit;
6773
}
6874

6975
bool ELinkDataShaper::checkLoc(const ELinkDecoder& decoder)
@@ -99,27 +105,16 @@ EventType ELinkDataShaper::processCalibrationTrigger(const InteractionRecord& ir
99105
return EventType::Calib;
100106
}
101107

102-
void ELinkDataShaper::processOrbitTrigger(uint16_t localClock, uint8_t triggerWord)
108+
void ELinkDataShaper::processHBTrigger(uint16_t localClock, uint8_t triggerWord)
103109
{
104-
/// Processes the orbit trigger event
110+
/// Processes the HB trigger event
105111

106112
// The local clock is reset: we are now in synch with the new HB
107-
// We have two ways to account for the orbit change:
108-
// - increase the orbit counter by 1 for this e-link
109-
// (CAVEAT: synch is lost if we lose some orbit)
110-
// - set the orbit to the one found in RDH
111-
// (CAVEAT: synch is lost if we have lot of data, spanning over two orbits)
112-
// FIXME: pick one of the two
113-
#ifdef ORBITFROMMIDRO
114-
++mIR.orbit; // orbit increase
115-
#else
116-
mIR.orbit = mRDHOrbit; // reset to RDH
117-
#endif
118-
if ((triggerWord & raw::sSOX) == 0) {
119-
// The clock counter starts from 0, so the total number of bunches
120-
// between two orbit triggers is the last clock value + 1
121-
mMaxBunches = localClock + 1;
122-
}
113+
++mIR.orbit;
114+
// The local clock value in an answer to the orbit trigger corresponds to the number of clocks elapsed since last reset.
115+
// Since the HB trigger is reset at each orbit, this corresponds to the number of bunches.
116+
// We need to add one because the local clock starts from 0.
117+
mMaxBunches = localClock + 1;
123118
}
124119

125120
bool ELinkDataShaper::processTrigger(const ELinkDecoder& decoder, EventType& eventType, InteractionRecord& ir)
@@ -149,10 +144,9 @@ bool ELinkDataShaper::processTrigger(const ELinkDecoder& decoder, EventType& eve
149144
eventType = EventType::Standard;
150145

151146
if (decoder.getTriggerWord() & raw::sORB) {
152-
// This is the answer to an orbit trigger
153-
processOrbitTrigger(localClock, decoder.getTriggerWord());
147+
// This is the answer to an HB trigger
148+
processHBTrigger(localClock, decoder.getTriggerWord());
154149
}
155-
applyElectronicsDelay(ir.orbit, ir.bc, mElectronicsDelay.localToBC, mMaxBunches);
156150

157151
if (decoder.getTriggerWord() & raw::sCALIBRATE) {
158152
// This is an answer to a calibration trigger

Detectors/MUON/MID/Raw/src/ELinkManager.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ void ELinkManager::onDone(const ELinkDecoder& decoder, uint8_t crateId, uint8_t
9292
return ds->second.onDone(decoder, data, rofs);
9393
}
9494

95-
void ELinkManager::set(uint32_t orbit)
95+
void ELinkManager::set(uint32_t orbit, uint32_t trigger)
9696
{
9797
/// Setup the orbit
9898
for (auto& shaper : mDataShapers) {
9999
#if defined(MID_RAW_VECTORS)
100-
shaper.set(orbit);
100+
shaper.set(orbit, trigger);
101101
#else
102-
shaper.second.set(orbit);
102+
shaper.second.set(orbit, trigger);
103103
#endif
104104
}
105105
}

Detectors/MUON/MID/Raw/src/LinkDecoder.cxx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class GBTUserLogicDecoderImplV2
3838
mELinkDecoder.setBareDecoder(false);
3939
}
4040

41-
void operator()(gsl::span<const uint8_t> payload, uint32_t orbit, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
41+
void operator()(gsl::span<const uint8_t> payload, uint32_t orbit, uint32_t trigger, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
4242
{
4343
/// Decodes the buffer
44-
mElinkManager.set(orbit);
44+
mElinkManager.set(orbit, trigger);
4545
// for (auto& byte : payload) {
4646
auto it = payload.begin();
4747
auto end = payload.end();
@@ -79,10 +79,10 @@ class GBTUserLogicDecoderImplV1
7979
mElinkManager.init(feeId, isDebugMode, true, electronicsDelay);
8080
}
8181

82-
void operator()(gsl::span<const uint8_t> payload, uint32_t orbit, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
82+
void operator()(gsl::span<const uint8_t> payload, uint32_t orbit, uint32_t trigger, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
8383
{
8484
/// Decodes the buffer
85-
mElinkManager.set(orbit);
85+
mElinkManager.set(orbit, trigger);
8686
// for (auto& byte : payload) {
8787
auto it = payload.begin();
8888
auto end = payload.end();
@@ -126,10 +126,10 @@ class GBTBareDecoderImplV1
126126
}
127127
}
128128

129-
void operator()(gsl::span<const uint8_t> payload, uint32_t orbit, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
129+
void operator()(gsl::span<const uint8_t> payload, uint32_t orbit, uint32_t trigger, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
130130
{
131131
/// Decodes the buffer
132-
mElinkManager.set(orbit);
132+
mElinkManager.set(orbit, trigger);
133133
mData = &data;
134134
mROFs = &rofs;
135135

@@ -209,10 +209,10 @@ class GBTBareDecoderImplV1
209209

210210
} // namespace impl
211211

212-
void LinkDecoder::process(gsl::span<const uint8_t> payload, uint32_t orbit, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
212+
void LinkDecoder::process(gsl::span<const uint8_t> payload, uint32_t orbit, uint32_t trigger, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
213213
{
214214
/// Decodes the data
215-
mDecode(payload, orbit, data, rofs);
215+
mDecode(payload, orbit, trigger, data, rofs);
216216
}
217217

218218
std::unique_ptr<LinkDecoder> createGBTDecoder(const o2::header::RDHAny& rdh, uint16_t feeId, bool isDebugMode, uint8_t mask, const ElectronicsDelay& electronicsDelay)

Detectors/MUON/MID/Workflow/src/RawGBTDecoderSpec.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class RawGBTDecoderDeviceDPL
7777
dh = it.o2DataHeader();
7878
auto const* rdhPtr = reinterpret_cast<const o2::header::RDHAny*>(it.raw());
7979
gsl::span<const uint8_t> payload(it.data(), it.size());
80-
mDecoder->process(payload, o2::raw::RDHUtils::getHeartBeatOrbit(rdhPtr), data, rofRecords);
80+
mDecoder->process(payload, o2::raw::RDHUtils::getHeartBeatOrbit(rdhPtr), o2::raw::RDHUtils::getTriggerType(rdhPtr), data, rofRecords);
8181
}
8282

8383
mTimerAlgo += std::chrono::high_resolution_clock::now() - tAlgoStart;

0 commit comments

Comments
 (0)