1717#include " MIDRaw/ELinkDataShaper.h"
1818
1919#include " CommonConstants/LHCConstants.h"
20+ // #define ORBITFROMMIDRO
2021
2122namespace o2
2223{
@@ -39,9 +40,10 @@ ELinkDataShaper::ELinkDataShaper(bool isDebugMode, bool isLoc, uint8_t uniqueId,
3940 mOnDone = &ELinkDataShaper::onDoneReg;
4041 }
4142 }
43+ mLocalToBCSelfTrig = mElectronicsDelay .localToBC ;
4244 if (!isLoc) {
43- mElectronicsDelay . BCToLocal + = electronicsDelay.regToLocal ;
44- mElectronicsDelay .calibToFET += electronicsDelay.regToLocal ;
45+ mLocalToBCSelfTrig - = electronicsDelay.localToReg ;
46+ mElectronicsDelay .calibToFET += electronicsDelay.localToReg ;
4547 }
4648}
4749
@@ -52,12 +54,15 @@ void ELinkDataShaper::set(uint32_t orbit)
5254
5355 if (mIR .isDummy ()) {
5456 mIR .bc = 0 ;
55- // The reset changes depending on the way we synch with the orbit
56- // (see processOrbitTrigger for details)
57- // FIXME: pick one of the two
58- // mIR.orbit = orbit - 1; // with orbit increase
59- mIR .orbit = orbit; // with reset to RDH
60- mLastClock = constants::lhc::LHCMaxBunches;
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
65+ mMaxBunches = constants::lhc::LHCMaxBunches;
6166 }
6267}
6368
@@ -67,42 +72,30 @@ bool ELinkDataShaper::checkLoc(const ELinkDecoder& decoder)
6772 return (decoder.getId () == (mUniqueId & 0xF ));
6873}
6974
70- EventType ELinkDataShaper::processSelfTriggered (uint16_t localClock, InteractionRecord& ir)
75+ EventType ELinkDataShaper::processSelfTriggered (InteractionRecord& ir)
7176{
7277 // / Processes the self-triggered event
7378
74- // This is a self-triggered events .
79+ // This is a self-triggered event .
7580 // The physics data arrives with a delay compared to the BC,
7681 // which is due to the travel time of muons up to the MID chambers
7782 // plus the travel time of the signal to the readout electronics.
7883 // In the case of regional cards, a further delay is expected
7984 // since this card needs to wait for the tracklet decision of each local card.
80- // For simplicity, this delay is added to the BCToLocal in the constructor.
85+ // For simplicity, this delay is added to the localToBC in the constructor.
8186 // In both cases, we need to correct for the delay in order to go back to the real BC.
82- if (ir.bc < mElectronicsDelay .BCToLocal ) {
83- // If the bc is smaller than the delay, it means that the local clock was reset
84- // This events therefore belongs to the previous orbit.
85- // We therefore add the value of the last BC (+1 to account for the reset)
86- // and we decrease the orbit by 1.
87- ir.bc += mLastClock + 1 ;
88- --ir.orbit ;
89- }
90- // We can now safely subtract the delay, which, thanks to the above protection,
91- // will not result in a negative number
92- ir.bc -= mElectronicsDelay .BCToLocal ;
93- if (mReceivedCalibration && (localClock == mExpectedFETClock )) {
94- // Reset the calibration flag for this e-link
95- mReceivedCalibration = false ;
87+ applyElectronicsDelay (ir.orbit , ir.bc , mLocalToBCSelfTrig , mMaxBunches );
88+ if (ir == mExpectedFET ) {
9689 return EventType::FET ;
9790 }
9891 return EventType::Standard;
9992}
10093
101- EventType ELinkDataShaper::processCalibrationTrigger (uint16_t localClock )
94+ EventType ELinkDataShaper::processCalibrationTrigger (const InteractionRecord& ir )
10295{
10396 // / Processes the calibration event
104- mExpectedFETClock = localClock + mElectronicsDelay . calibToFET ;
105- mReceivedCalibration = true ;
97+ mExpectedFET = ir ;
98+ applyElectronicsDelay ( mExpectedFET . orbit , mExpectedFET . bc , mElectronicsDelay . calibToFET , mMaxBunches ) ;
10699 return EventType::Calib;
107100}
108101
@@ -117,15 +110,15 @@ void ELinkDataShaper::processOrbitTrigger(uint16_t localClock, uint8_t triggerWo
117110 // - set the orbit to the one found in RDH
118111 // (CAVEAT: synch is lost if we have lot of data, spanning over two orbits)
119112 // FIXME: pick one of the two
120- // ++mIR.orbit; // orbit increase
113+ #ifdef ORBITFROMMIDRO
114+ ++mIR .orbit ; // orbit increase
115+ #else
121116 mIR .orbit = mRDHOrbit ; // reset to RDH
117+ #endif
122118 if ((triggerWord & raw::sSOX ) == 0 ) {
123- mLastClock = localClock;
124- }
125- // The orbit trigger resets the clock.
126- // If we received a calibration trigger, we need to change the value of the expected clock accordingly
127- if (mReceivedCalibration ) {
128- mExpectedFETClock -= (localClock + 1 );
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 ;
129122 }
130123}
131124
@@ -147,23 +140,25 @@ bool ELinkDataShaper::processTrigger(const ELinkDecoder& decoder, EventType& eve
147140
148141 if (decoder.getTriggerWord () == 0 ) {
149142 // This is a self-triggered event
150- eventType = processSelfTriggered (localClock, ir);
143+ eventType = processSelfTriggered (ir);
151144 return true ;
152145 }
153146
154147 // From here we treat triggered events
155148 bool goOn = false ;
156149 eventType = EventType::Standard;
157- if (decoder.getTriggerWord () & raw::sCALIBRATE ) {
158- // This is an answer to a calibration trigger
159- eventType = processCalibrationTrigger (localClock);
160- goOn = true ;
161- }
162150
163151 if (decoder.getTriggerWord () & raw::sORB ) {
164152 // This is the answer to an orbit trigger
165153 processOrbitTrigger (localClock, decoder.getTriggerWord ());
166154 }
155+ applyElectronicsDelay (ir.orbit , ir.bc , mElectronicsDelay .localToBC , mMaxBunches );
156+
157+ if (decoder.getTriggerWord () & raw::sCALIBRATE ) {
158+ // This is an answer to a calibration trigger
159+ eventType = processCalibrationTrigger (ir);
160+ goOn = true ;
161+ }
167162
168163 return goOn;
169164}
0 commit comments