Skip to content

Commit ec51b3e

Browse files
mfasDashahor02
authored andcommitted
[EMCAL-650] Fix encoding of L1 phase
Time sample and L1 phase must be encoded at the same time, because the L1 phase depends on the sample time (number of phases = number of bunch crossing within sample time). Functions setTimeSample and setL1Phase are merged into 1, and the unit is changed from seconds to nanoseconds. In addition settings not yet printed are added to to the PrintStream function in the debug streaming.
1 parent 002c8fb commit ec51b3e

4 files changed

Lines changed: 45 additions & 42 deletions

File tree

Detectors/EMCAL/base/include/EMCALBase/RCUTrailer.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,19 @@ class RCUTrailer
167167
/// \brief Access to the sampling time
168168
/// \return Sampling time in seconds.
169169
/// \throw Error if the RCU trailer was not properly initializied
170-
double getTimeSample() const;
171-
172-
/// \brief set time sample
173-
/// \param timesample Time sample (in ns)
174-
void setTimeSample(double timesample);
170+
double getTimeSampleNS() const;
175171

176172
/// \brief Access to the L1 phase
177173
/// \return L1 phase w.r.t to the LHC clock
178-
double getL1Phase() const;
174+
double getL1PhaseNS() const;
179175

180-
/// \brief Set the L1 phase
181-
/// \param l1phase L1 phase (in ns)
182-
void setL1Phase(double l1phase);
176+
/// \brief Set the time sample length and L1 phase based on the trigger time
177+
/// \param time Trigger time (in ns)
178+
/// \param timesample Time sample (in ns)
179+
///
180+
/// L1 phase: Collision time with respect to the sample length. Number
181+
/// of phases: Sample length / bunch spacing (25 ns)
182+
void setTimeSamplePhaseNS(uint64_t triggertime, uint64_t timesample);
183183

184184
//
185185
// Error counters

Detectors/EMCAL/base/src/RCUTrailer.cxx

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void RCUTrailer::constructFromRawPayload(const gsl::span<const uint32_t> payload
6060
}
6161
int parCode = (word >> 26) & 0xF;
6262
int parData = word & 0x3FFFFFF;
63+
// std::cout << "Found trailer word 0x" << std::hex << word << "(Par code: " << std::dec << parCode << ", Par data: 0x" << std::hex << parData << std::dec << ")";
6364
switch (parCode) {
6465
case 1:
6566
// ERR_REG1
@@ -99,7 +100,7 @@ void RCUTrailer::constructFromRawPayload(const gsl::span<const uint32_t> payload
99100
mIsInitialized = true;
100101
}
101102

102-
double RCUTrailer::getTimeSample() const
103+
double RCUTrailer::getTimeSampleNS() const
103104
{
104105
uint8_t fq = mAltroConfig.mSampleTime;
105106
double tSample;
@@ -120,40 +121,40 @@ double RCUTrailer::getTimeSample() const
120121
throw Error(Error::ErrorType_t::SAMPLINGFREQ_INVALID, fmt::format("Invalid sampling frequency value %d !", int(fq)).data());
121122
}
122123

123-
return tSample * o2::constants::lhc::LHCBunchSpacingNS * 1.e-9;
124+
return tSample * o2::constants::lhc::LHCBunchSpacingNS;
124125
}
125126

126-
void RCUTrailer::setTimeSample(double timesample)
127+
void RCUTrailer::setTimeSamplePhaseNS(uint64_t triggertime, uint64_t timesample)
127128
{
128-
int fq = 0;
129-
if (std::abs(timesample - 50) < DBL_EPSILON) {
130-
fq = 0;
131-
} else if (std::abs(timesample - 100) < DBL_EPSILON) {
132-
fq = 1;
133-
} else if (std::abs(timesample - 200) < DBL_EPSILON) {
134-
fq = 2;
135-
} else {
136-
throw Error(Error::ErrorType_t::SAMPLINGFREQ_INVALID, fmt::format("invalid time sample: %f", timesample).data());
137-
}
138-
mAltroConfig.mSampleTime = fq;
129+
int sample = 0;
130+
switch (timesample) {
131+
case 50:
132+
sample = 0;
133+
break;
134+
case 100:
135+
sample = 1;
136+
break;
137+
case 200:
138+
sample = 2;
139+
break;
140+
default:
141+
throw Error(Error::ErrorType_t::SAMPLINGFREQ_INVALID, fmt::format("invalid time sample: %f", timesample).data());
142+
};
143+
mAltroConfig.mSampleTime = sample;
144+
// calculate L1 phase
145+
mAltroConfig.mL1Phase = (triggertime % timesample) / 25;
139146
}
140147

141-
double RCUTrailer::getL1Phase() const
148+
double RCUTrailer::getL1PhaseNS() const
142149
{
143-
double tSample = getTimeSample(),
144-
phase = static_cast<double>(mAltroConfig.mL1Phase) * o2::constants::lhc::LHCBunchSpacingNS * 1.e-9;
150+
double tSample = getTimeSampleNS(),
151+
phase = static_cast<double>(mAltroConfig.mL1Phase) * o2::constants::lhc::LHCBunchSpacingNS;
145152
if (phase >= tSample) {
146-
throw Error(Error::ErrorType_t::L1PHASE_INVALID, fmt::format("Invalid L1 trigger phase (%e s (phase) >= %e s (sampling time)) !", phase, tSample).data());
153+
throw Error(Error::ErrorType_t::L1PHASE_INVALID, fmt::format("Invalid L1 trigger phase (%e ns (phase) >= %e ns (sampling time)) !", phase, tSample).data());
147154
}
148155
return phase;
149156
}
150157

151-
void RCUTrailer::setL1Phase(double l1phase)
152-
{
153-
int phase = l1phase / 25.;
154-
mAltroConfig.mL1Phase = phase;
155-
}
156-
157158
std::vector<uint32_t> RCUTrailer::encode() const
158159
{
159160
std::vector<uint32_t> encoded;
@@ -177,12 +178,12 @@ void RCUTrailer::printStream(std::ostream& stream) const
177178
std::vector<std::string> errors;
178179
double timesample = -1., l1phase = -1.;
179180
try {
180-
timesample = getTimeSample();
181+
timesample = getTimeSampleNS();
181182
} catch (Error& e) {
182183
errors.push_back(e.what());
183184
}
184185
try {
185-
l1phase = getL1Phase();
186+
l1phase = getL1PhaseNS();
186187
} catch (Error& e) {
187188
errors.push_back(e.what());
188189
}
@@ -201,20 +202,22 @@ void RCUTrailer::printStream(std::ostream& stream) const
201202
<< "Active FECs (branch A): 0x" << std::hex << mActiveFECsA << "\n"
202203
<< "Active FECs (branch B): 0x" << std::hex << mActiveFECsB << "\n"
203204
<< "Baseline corr: " << std::hex << getBaselineCorrection() << "\n"
205+
<< "Polarity: " << (getPolarity() ? "yes" : "no") << "\n"
204206
<< "Number of presamples: " << std::dec << getNumberOfPresamples() << "\n"
205207
<< "Number of postsamples: " << std::dec << getNumberOfPostsamples() << "\n"
206208
<< "Second baseline corr: " << (hasSecondBaselineCorr() ? "yes" : "no") << "\n"
207209
<< "Glitch filter: " << std::dec << getGlitchFilter() << "\n"
208210
<< "Number of non-ZS postsamples: " << std::dec << getNumberOfNonZeroSuppressedPostsamples() << "\n"
209211
<< "Number of non-ZS presamples: " << std::dec << getNumberOfNonZeroSuppressedPresamples() << "\n"
212+
<< "Zero suppression: " << (hasZeroSuppression() ? "yes" : "no") << "\n"
210213
<< "Number of ALTRO buffers: " << std::dec << getNumberOfAltroBuffers() << "\n"
211214
<< "Number of pretrigger samples: " << std::dec << getNumberOfPretriggerSamples() << "\n"
212215
<< "Number of samples per channel: " << std::dec << getNumberOfSamplesPerChannel() << "\n"
213216
<< "Sparse readout: " << (isSparseReadout() ? "yes" : "no") << "\n"
214217
<< "AltroCFG1: 0x" << std::hex << mAltroConfig.mWord1 << "\n"
215218
<< "AltroCFG2: 0x" << std::hex << mAltroConfig.mWord2 << "\n"
216-
<< "Sampling time: " << std::scientific << timesample << " s\n"
217-
<< "L1 Phase: " << std::scientific << l1phase << " s\n"
219+
<< "Sampling time: " << timesample << " ns\n"
220+
<< "L1 Phase: " << l1phase << " ns\n"
218221
<< std::dec << std::fixed;
219222
if (errors.size()) {
220223
stream << "Errors: \n"

Detectors/EMCAL/simulation/include/EMCALSimulation/RawWriter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <gsl/span>
1515

1616
#include <array>
17+
#include <cstdint>
1718
#include <fstream>
1819
#include <memory>
1920
#include <string>
@@ -107,7 +108,7 @@ class RawWriter
107108
std::tuple<int, int> getLinkAssignment(int ddlID);
108109

109110
ChannelHeader createChannelHeader(int hardwareAddress, int payloadSize, bool isBadChannel);
110-
std::vector<char> createRCUTrailer(int payloadsize, int feca, int fecb, double timesample, double l1phase);
111+
std::vector<char> createRCUTrailer(int payloadsize, int feca, int fecb, double timesample, uint64_t triggertime);
111112
std::vector<int> encodeBunchData(const std::vector<int>& data);
112113

113114
private:

Detectors/EMCAL/simulation/src/RawWriter.cxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ bool RawWriter::processTrigger(const o2::emcal::TriggerRecord& trg)
159159
}
160160

161161
// Create RCU trailer
162-
auto trailerwords = createRCUTrailer(payload.size() / 4, 16, 16, 100., 0.);
162+
auto trailerwords = createRCUTrailer(payload.size() / 4, 16, 16, 100., trg.getBCData().toLong());
163163
for (auto word : trailerwords) {
164164
payload.emplace_back(word);
165165
}
@@ -286,14 +286,13 @@ ChannelHeader RawWriter::createChannelHeader(int hardwareAddress, int payloadSiz
286286
return header;
287287
}
288288

289-
std::vector<char> RawWriter::createRCUTrailer(int payloadsize, int feca, int fecb, double timesample, double l1phase)
289+
std::vector<char> RawWriter::createRCUTrailer(int payloadsize, int feca, int fecb, double timesample, uint64_t triggertime)
290290
{
291291
RCUTrailer trailer;
292292
trailer.setActiveFECsA(feca);
293293
trailer.setActiveFECsB(fecb);
294294
trailer.setPayloadSize(payloadsize);
295-
trailer.setL1Phase(l1phase);
296-
trailer.setTimeSample(timesample);
295+
trailer.setTimeSamplePhaseNS(triggertime, timesample);
297296
auto trailerwords = trailer.encode();
298297
std::vector<char> encoded(trailerwords.size() * sizeof(uint32_t));
299298
memcpy(encoded.data(), trailerwords.data(), trailerwords.size() * sizeof(uint32_t));

0 commit comments

Comments
 (0)