1717#include " MIDRaw/ELinkDataShaper.h"
1818
1919#include " CommonConstants/LHCConstants.h"
20- // #define ORBITFROMMIDRO
20+ # include " CommonConstants/Triggers.h "
2121
2222namespace 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
6975bool 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
125120bool 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
0 commit comments