13#include <unordered_map>
17#include <fmt/format.h>
18#include <fmt/chrono.h>
52 bool sampledData =
true;
68 LOGP(info,
"Using sampled data");
78 size_t errorCount = 0;
82 bool readFirst =
false;
83 bool readFirstZS =
false;
86 if (returnOnNoTrigger && (triggerBC < 0)) {
99 const auto* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(
ref);
106 firstOrbit = dh->firstTForbit;
109 const auto subSpecification = dh->subSpecification;
116 const auto linkID = (
rdh_utils::FEEIDType)((subSpecification + (subSpecification >> 8)) & 0xFF) - 1;
118 feeID = rdh_utils::getFEEID(cruID, endPoint, linkID);
128 activeSectors |= (0x1 <<
sector);
133 rdh_utils::getMapping(feeID, cruID, endPoint, linkID);
134 const auto globalLinkID = linkID + endPoint * 12;
135 LOGP(
debug,
"Specifier: {}/{}/{} Part {} of {}", dh->dataOrigin, dh->dataDescription, subSpecification, dh->splitPayloadIndex, dh->splitPayloadParts);
136 LOGP(
debug,
"Payload size: {}", payloadSize);
137 LOGP(
debug,
"CRU: {}; linkID: {}; endPoint: {}; globalLinkID: {}", cruID, linkID, endPoint, globalLinkID);
141 const gsl::span<const char>
raw = inputs.
get<gsl::span<char>>(
ref);
142 std::unique_ptr<o2::framework::RawParser<8192>> rawparserPtr;
147 bool isLinkZS =
false;
149 auto it = parser.
begin();
152 if (!rdhPtr || rdhVersion < 6) {
153 throw std::runtime_error(fmt::format(
"could not get RDH from packet, or version {} < 6", rdhVersion).
data());
155 const auto link = RDHUtils::getLinkID(*rdhPtr);
156 const auto detField = RDHUtils::getDetectorField(*rdhPtr);
157 const auto feeID = RDHUtils::getFEEID(*rdhPtr);
158 const auto feeLinkID = rdh_utils::getLink(feeID);
162 if (feeLinkID == rdh_utils::DLBZSLinkID) {
163 LOGP(info,
"Detected Dense Link-based zero suppression");
164 }
else if (feeLinkID == rdh_utils::ILBZSLinkID) {
165 LOGP(info,
"Detected Improved Link-based zero suppression");
167 LOGP(info,
"Detected Link-based zero suppression");
169 if (!reader->getManager() || !reader->getManager()->getLinkZSCallback()) {
170 LOGP(fatal,
"LinkZSCallback must be set in RawReaderCRUManager");
178 LOGP(info,
"First orbit in present TF: {}", firstOrbit);
184 processLinkZS(parser, reader, firstOrbit, syncOffsetReference, decoderType, triggerBC);
189 }
catch (
const std::exception&
e) {
191 using namespace std::literals::chrono_literals;
192 static std::unordered_map<uint32_t, size_t> nErrorPerSubspec;
193 static std::chrono::time_point<std::chrono::steady_clock> lastReport = std::chrono::steady_clock::now();
194 const auto now = std::chrono::steady_clock::now();
195 static size_t reportedErrors = 0;
196 const size_t MAXERRORS = 10;
198 ++nErrorPerSubspec[subSpecification];
201 if (reportedErrors < MAXERRORS) {
203 std::string sleepInfo;
204 if (reportedErrors == MAXERRORS) {
205 sleepInfo = fmt::format(
", maximum error count ({}) reached, not reporting for the next {}", MAXERRORS,
sleepTime);
207 LOGP(alarm,
"EXCEPTIION in processRawData: {} -> skipping part:{}/{} of spec:{}/{}/{}, size:{}, error count for subspec: {}{}",
e.what(), dh->splitPayloadIndex, dh->splitPayloadParts,
208 dh->dataOrigin, dh->dataDescription, subSpecification, payloadSize, nErrorPerSubspec.at(subSpecification), sleepInfo);
220 *nerrors += errorCount;
222 return activeSectors;
230 rdh_utils::getMapping(feeID, cruID, endPoint, linkID);
231 const auto globalLinkID = linkID + endPoint * 12;
234 reader->forceCRU(cruID);
235 reader->setLink(globalLinkID);
240 for (
auto it = parser.
begin(),
end = parser.
end(); it !=
end; ++it) {
242 const auto size = it.size();
243 auto data = it.data();
247 for (
int i = 0;
i <
size;
i += 16) {
262 reader->runADCDataCallback(rawData);
267 for (
auto it = parser.
begin(),
end = parser.
end(); it !=
end; ++it) {
270 if (!rdhPtr || rdhVersion < 6) {
271 throw std::runtime_error(fmt::format(
"could not get RDH from packet, or version {} < 6", rdhVersion).
data());
279 const auto link = RDHUtils::getLinkID(*rdhPtr);
280 const auto detField = RDHUtils::getDetectorField(*rdhPtr);
281 const auto feeID = RDHUtils::getFEEID(*rdhPtr);
282 const auto linkID = rdh_utils::getLink(feeID);
285 ((linkID == rdh_utils::ILBZSLinkID || linkID == rdh_utils::DLBZSLinkID) && (detField == raw_data_types::Type::ZS)))) {
289 if ((decoderType == 1) && (linkID == rdh_utils::ILBZSLinkID || linkID == rdh_utils::DLBZSLinkID) && (detField == raw_data_types::Type::ZS)) {
290 std::vector<Digit>
digits;
292 gpuDecoder.
DecodePage(
digits, (
const void*)it.raw(), firstOrbit,
nullptr,
static_cast<unsigned int>((triggerBC > 0) ? triggerBC : 0));
293 for (
const auto& digit :
digits) {
294 reader->getManager()->getLinkZSCallback()(digit.getCRU(), digit.getRow(), digit.getPad(), digit.getTimeStamp(), digit.getChargeFloat());
297 const auto orbit = RDHUtils::getHeartBeatOrbit(*rdhPtr);
298 const auto data = (
const char*)it.data();
299 const auto size = it.size();
311 const auto* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(
ref);
318 const gsl::span<const char>
raw = inputs.
get<gsl::span<char>>(
ref);
321 for (
auto it = parser.begin(),
end = parser.end(); it !=
end; ++it) {
324 if (!rdhPtr || rdhVersion < 6) {
325 throw std::runtime_error(fmt::format(
"could not get RDH from packet, or version {} < 6", rdhVersion).
data());
329 const auto link = RDHUtils::getLinkID(*rdhPtr);
330 const auto detField = RDHUtils::getDetectorField(*rdhPtr);
331 const auto feeID = RDHUtils::getFEEID(*rdhPtr);
332 const auto linkID = rdh_utils::getLink(feeID);
335 ((linkID == rdh_utils::ILBZSLinkID) && (detField == raw_data_types::Type::ZS)))) {
339 const auto data = (
const char*)it.data();
340 const auto size = it.size();
345 while (zsdata < zsdataEnd) {
348 if (!
header.hasCorrectMagicWord()) {
354 if (
header.isTriggerInfo()) {
355 zsdata = zsdata->
next();
359 syncOffsetReference = std::max(
header.syncOffsetBC, syncOffsetReference);
367 LOGP(info,
"syncOffsetReference in this TF: {}", syncOffsetReference);
368 return syncOffsetReference;
374 const auto orbit = RDHUtils::getTriggerOrbit(rdh);
375 int triggerBCOffset = -1;
378 if (!
header.hasCorrectMagicWord()) {
382 if (
header.isTriggerInfo()) {
385 const auto triggerOrbit = triggerInfo->triggerInfo.getOrbit();
386 const auto triggerBC = triggerInfo->triggerInfo.bunchCrossing;
387 triggerBCOffset = int(triggerOrbit - firstOrbit) * o2::constants::lhc::LHCMaxBunches + triggerBC;
388 LOGP(
debug,
"TriggerInfoV1: orbit: {}, firstOrbit: {}, triggerOrbit: {}, triggerBC: {}, triggerBCOffset: {}",
orbit, firstOrbit, triggerOrbit, triggerBC, triggerBCOffset);
389 zsdata = zsdata->
next();
390 return triggerBCOffset;
391 }
else if (
header.isTriggerInfoV2()) {
394 const auto triggerOrbit = triggerInfo->orbit;
395 const auto triggerBC = triggerInfo->bunchCrossing;
396 triggerBCOffset = int(triggerOrbit - firstOrbit) * o2::constants::lhc::LHCMaxBunches + triggerBC;
397 LOGP(
debug,
"TriggerInfoV2: orbit: {}, firstOrbit: {}, triggerOrbit: {}, triggerBC: {}, triggerBCOffset: {}",
orbit, firstOrbit, triggerOrbit, triggerBC, triggerBCOffset);
398 zsdata = zsdata->
next();
399 return triggerBCOffset;
400 }
else if (
header.isMetaHeader()) {
404 if (triggerInfo.hasTrigger()) {
405 const auto triggerBC = triggerInfo.getFirstBC();
406 const auto triggerOrbit =
orbit;
407 triggerBCOffset = int(triggerOrbit - firstOrbit) * o2::constants::lhc::LHCMaxBunches + triggerBC;
408 LOGP(
debug,
"TriggerInfoV3: orbit: {}, firstOrbit: {}, triggerOrbit: {}, triggerBC: {}, triggerBCOffset: {}",
orbit, firstOrbit, triggerOrbit, triggerBC, triggerBCOffset);
411 return triggerBCOffset;
420 const auto feeId = RDHUtils::getFEEID(rdh);
421 const auto link = rdh_utils::getLink(feeId);
423 if (
link != rdh_utils::DLBZSLinkID) {
430 if (
header->magicWord != 0xfd) {
431 LOGP(
error,
"Wrong magic word: {}, wrong data type?",
header->magicWord);
434 if (!(
header->flags & TPCZSHDRV2::ZSFlags::TriggerWordPresent)) {
440 for (iTrg = 0; iTrg < TriggerWordDLBZS::MaxTriggerEntries; ++iTrg) {
441 if (triggerWord->isValid(iTrg)) {
450 const auto triggerBC = triggerWord->getTriggerBC(iTrg);
451 const auto orbit = RDHUtils::getHeartBeatOrbit(rdh);
452 const int orbitBC = ((
orbit - firstOrbit) * o2::constants::lhc::LHCMaxBunches) + triggerBC;
453 LOGP(
debug,
"TriggerWordDLBZS {}: Type = {}, orbit = {}, firstOrbit = {}, BC = {}, oribitBC = {}", iTrg, triggerWord->getTriggerType(iTrg),
orbit, firstOrbit, triggerWord->getTriggerBC(iTrg), orbitBC);
466 const auto* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(
ref);
473 firstOrbit = dh->firstTForbit;
476 const gsl::span<const char>
raw = inputs.
get<gsl::span<char>>(
ref);
477 std::unique_ptr<o2::framework::RawParser<8192>> rawparserPtr;
480 for (
auto it = parser.
begin(),
end = parser.
end(); it !=
end; ++it) {
483 if (!rdhPtr || rdhVersion < 6) {
484 throw std::runtime_error(fmt::format(
"could not get RDH from packet, or version {} < 6", rdhVersion).
data());
488 const auto link = RDHUtils::getLinkID(*rdhPtr);
489 const auto detField = RDHUtils::getDetectorField(*rdhPtr);
490 const auto feeID = RDHUtils::getFEEID(*rdhPtr);
491 const auto linkID = rdh_utils::getLink(feeID);
494 ((linkID == rdh_utils::ILBZSLinkID || linkID == rdh_utils::DLBZSLinkID) && (detField == raw_data_types::Type::ZS)))) {
498 const auto data = (
const char*)it.raw();
499 const auto size = it.sizeTotal();
502 if (thisTrigger >= 0 && !slowScan) {
503 triggerBC = thisTrigger;
507 if (triggerBC >= 0 && triggerBC != thisTrigger) {
508 LOGP(
error,
"inconsistent trigger information in raw pages of this TF");
513 if (triggerBC >= 0 && !slowScan) {
517 if (triggerBC >= 0) {
518 LOGP(info,
"Found triggerBCoffset: {}", triggerBC);
uint32_t getBCsyncOffsetReference(InputRecord &inputs, const std::vector< InputSpec > &filter)
int getTriggerInfoLBZS(const char *data, size_t size, uint32_t firstOrbit)
void processGBT(o2::framework::RawParser<> &parser, std::unique_ptr< o2::tpc::rawreader::RawReaderCRU > &reader, const rdh_utils::FEEIDType feeID)
void processLinkZS(o2::framework::RawParser<> &parser, std::unique_ptr< o2::tpc::rawreader::RawReaderCRU > &reader, uint32_t firstOrbit, uint32_t syncOffsetReference, uint32_t decoderType, int triggerBC)
std::vector< std::string > header
o2::raw::RawFileWriter * raw
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate sectors
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
char error[CURL_ERROR_SIZE]
Generic parser for consecutive raw pages.
definitions to deal with the link based zero suppression format
Definitions of TPC Zero Suppression Data Headers.
const_iterator begin() const
const_iterator end() const
void DecodePage(std::vector< o2::tpc::Digit > &outputBuffer, const void *page, uint32_t tfFirstOrbit, const GPUParam *param, uint32_t triggerBC=0)
helper to store the ADC raw data
helper to encapsulate a GBTFrame
void setFrameNumber(uint32_t frameNumber)
set packet number
void readFromMemory(gsl::span< const std::byte > data)
read from memory
void updateSyncCheck(SyncArray &syncArray)
update the sync check
void getFrameHalfWords()
extract the 4 5b halfwords for the 5 data streams from one GBT frame
void getAdcValues(ADCRawData &rawData)
decode ADC values
void setPacketNumber(uint32_t packetNumber)
set packet number
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
constexpr o2::header::DataOrigin gDataOriginTPC
Defining ITS Vertex explicitly as messageable.
uint64_t processRawData(o2::framework::InputRecord &inputs, std::unique_ptr< o2::tpc::rawreader::RawReaderCRU > &reader, bool useOldSubspec=false, const std::vector< int > §ors={}, size_t *nerrors=nullptr, uint32_t syncOffsetReference=144, uint32_t decoderType=1, bool useTrigger=true, bool returnOnNoTrigger=false)
int getTriggerBCoffset(o2::framework::InputRecord &inputs, std::vector< o2::framework::InputSpec > filter={}, bool slowScan=false)
absolute BC relative to TF start (firstOrbit)
std::vector< o2::framework::InputSpec > getFilter(o2::framework::InputRecord &inputs)
absolute BC relative to TF start (firstOrbit)
@ ZS
final Zero Suppression (can be ILBZS, DLBZS)
@ LinkZS
Link-based Zero Suppression.
bool processZSdata(const char *data, size_t size, rdh_utils::FEEIDType feeId, uint32_t orbit, uint32_t referenceOrbit, uint32_t syncOffsetReference, ADCCallback fillADC)
Global TPC definitions and constants.
static o2::header::DataHeader::PayloadSizeType getPayloadSize(const DataRef &ref)
static constexpr int getVersion()
get numeric version of the RDH
@ Cal
Laser (Calibration trigger)
ContainerT< DataBitSizeT, SignificantBitsT, HasHeaderT > cont
Templated data container.
Container * next() const
get position of next container. Validity check to be done outside!
Container for Trigger information, header + data.
Data definition for the new trigger information after FW update, allowing for interleaved triggers.
std::vector< Digit > digits