16#include <fmt/format.h>
28#define CHECK_BIT(var, pos) ((var) & (1 << (pos)))
34template <
typename DataType>
57 for (
auto& ev : mEventInformation) {
59 const long hbDiff =
long(heartbeatOrbit) -
long(ev.HeartbeatOrbits.front());
63 }
else if ((hbDiff >= 0) && (hbDiff < 128)) {
65 std::sort(ev.HeartbeatOrbits.begin(), ev.HeartbeatOrbits.end());
70 auto& ev = mEventInformation.emplace_back(heartbeatOrbit);
80 for (
int iEvent = mEventInformation.size() - 1; iEvent >= 0; --iEvent) {
81 auto&
event = mEventInformation[iEvent];
82 event.IsComplete =
true;
83 size_t totalPayloadSize = 0;
84 for (
size_t iCRU = 0; iCRU <
event.CRUInfoArray.size(); ++iCRU) {
85 const auto& cruInfo =
event.CRUInfoArray[iCRU];
86 if (!cruInfo.isPresent()) {
87 if (mCRUSeen[iCRU] >= 0) {
88 LOGP(info,
"CRU {} missing in event {}", iCRU, iEvent);
89 event.IsComplete =
false;
95 totalPayloadSize += cruInfo.totalPayloadSize();
98 if (!cruInfo.isComplete(rawDataType)) {
99 LOGP(info,
"CRU info is incomplete");
100 event.IsComplete =
false;
108 if (totalPayloadSize == 0) {
109 O2INFO(
"Removing empty event with HB Orbit %u",
event.HeartbeatOrbits[0]);
110 mEventInformation.erase(mEventInformation.begin() + iEvent);
117 for (
auto& ev : mEventInformation) {
118 auto& cruInfo = ev.CRUInfoArray[cru];
119 for (
int ilink = 0; ilink < cruInfo.LinkInformation.size(); ++ilink) {
120 auto& linkInfo = cruInfo.LinkInformation[ilink];
121 linkInfo.WasSeen = links[ilink];
128 const std::string redBG(
"\033[41m");
129 const std::string red(
"\033[31m");
130 const std::string
green(
"\033[32m");
131 const std::string bold(
"\033[1m");
132 const std::string
clear(
"\033[0m");
134 std::cout <<
"CRU information";
135 for (
size_t iCRU = 0; iCRU < mCRUSeen.size(); ++iCRU) {
136 const auto readerNumber = mCRUSeen[iCRU];
137 if (readerNumber >= 0) {
138 std::cout << fmt::format(
"CRU {:2} found in reader {}\n", iCRU, readerNumber);
142 std::cout <<
"Detailed event information\n";
144 for (
int i = 0;
i < mEventInformation.size(); ++
i) {
145 const auto&
event = mEventInformation[
i];
146 const bool isComplete =
event.IsComplete;
152 std::cout <<
"Event " <<
i <<
" \n"
153 <<
clear <<
" heartbeatOrbits: ";
154 for (
const auto&
orbit :
event.HeartbeatOrbits) {
155 std::cout <<
orbit <<
" ";
158 <<
" firstOrbit: " <<
event.getFirstOrbit() <<
"\n"
159 <<
" Is complete: " << isComplete <<
"\n";
162 for (
size_t iCRU = 0; iCRU <
event.CRUInfoArray.size(); ++iCRU) {
163 const auto& cruInfo =
event.CRUInfoArray[iCRU];
164 if (!cruInfo.isPresent()) {
168 if (!cruInfo.isComplete()) {
169 std::cout << bold + red;
171 std::cout <<
"CRU " << iCRU <<
clear <<
"\n";
172 const auto& cruLinks = cruInfo.LinkInformation;
175 for (
size_t iLink = 0; iLink < cruLinks.size(); ++iLink) {
176 const auto& linkInfo =
event.CRUInfoArray[iCRU].LinkInformation[iLink];
177 if (!linkInfo.IsPresent) {
181 if (!linkInfo.isComplete()) {
184 std::cout <<
"Link " << iLink <<
clear <<
"\n";
185 if (!linkInfo.HBEndSeen) {
188 std::cout <<
" HBEndSeen: " << linkInfo.HBEndSeen <<
clear <<
"\n";
193 std::cout <<
" Payload size : " << linkInfo.PayloadSize <<
" (" << linkInfo.PayloadSize / 16 <<
" GBT frames)"
195 std::cout <<
" Packets: ";
196 for (
const auto& packet : linkInfo.PacketPositions) {
197 std::cout << packet <<
" ";
209 if (mFileIsScanned) {
216 const uint64_t RDH_HEADERWORD0 = 0x00004000;
220 LOGP(info,
"scanning file {}", mInputFileName);
223 mFileSize =
file.tellg();
226 const bool isTFfile = (mInputFileName.rfind(
".tf") == mInputFileName.size() - 3);
232 const uint32_t numPackets = mFileSize / (8 * 1024);
237 uint32_t currentPacket = 0;
238 uint32_t lastHeartbeatOrbit = 0;
243 file.seekg(dh.payloadSize, std::ios::cur);
245 file.seekg(dh.payloadSize, std::ios::cur);
248 size_t currentPos =
file.tellg();
249 size_t dhPayloadSize{};
250 size_t dhPayloadSizeSeen{};
252 while ((currentPos < mFileSize) && !
file.eof()) {
254 if (isTFfile && (!dhPayloadSize || (dhPayloadSizeSeen == dhPayloadSize))) {
258 file.seekg(dhPayloadSize,
file.cur);
259 currentPos =
file.tellg();
263 dhPayloadSizeSeen = 0;
264 currentPos =
file.tellg();
270 const size_t packetSize = RDHUtils::getOffsetToNext(rdh);
271 const size_t offset = packetSize - RDHUtils::getHeaderSize(rdh);
272 const auto memorySize = RDHUtils::getMemorySize(rdh);
273 const auto payloadSize = memorySize - RDHUtils::getHeaderSize(rdh);
274 dhPayloadSizeSeen += packetSize;
277 const size_t curPos =
file.tellg();
278 if ((curPos +
offset) > mFileSize) {
279 LOGP(error,
"File truncated at {}, offset {} would exceed file size of {}", curPos,
offset, mFileSize);
284 const auto detField = o2::raw::RDHUtils::getDetectorField(rdh);
285 if (((detField != 0xdeadbeef) && (detField > 2)) || (payloadSize == 0)) {
288 currentPos =
file.tellg();
300 if (mManager->mDetectDataType) {
301 const uint64_t triggerTypeForTriggeredData = 0x10;
302 const uint64_t triggerType = RDHUtils::getTriggerType(rdh);
303 const uint64_t pageCnt = RDHUtils::getPageCounter(rdh);
304 const uint64_t linkID = RDHUtils::getLinkID(rdh);
307 if ((linkID == 15) || (detField == 0x1) || (detField == 0x2)) {
309 LOGP(info,
"Detected LinkZS data");
310 mManager->mDetectDataType =
false;
315 if (triggerType == triggerTypeForTriggeredData) {
317 O2INFO(
"Detected triggered data");
320 O2INFO(
"Detected HB scaling");
322 mManager->mDetectDataType =
false;
328 auto feeId = RDHUtils::getFEEID(rdh);
334 feeId = rdh_utils::getFEEID(cru, endPoint, link);
338 const auto heartbeatOrbit = RDHUtils::getHeartBeatOrbit(rdh);
339 const auto heartbeatOrbitEvent = isTFfile ? dh.
firstTForbit : RDHUtils::getHeartBeatOrbit(rdh);
340 const auto endPoint = rdh_utils::getEndPoint(feeId);
341 auto linkID = rdh_utils::getLink(feeId);
342 if (linkID == 21 && detField == 0x02) {
345 const auto globalLinkID = linkID + endPoint * 12;
349 mCRU = rdh_utils::getCRU(feeId);
360 if ((lastHeartbeatOrbit == 0) || (heartbeatOrbitEvent != lastHeartbeatOrbit)) {
362 lastHeartbeatOrbit = heartbeatOrbitEvent;
365 mManager->mEventSync.
setCRUSeen(mCRU, mReaderNumber);
374 if ((rdh.word0 & 0x0000FFF0) == RDH_HEADERWORD0) {
377 mPacketDescriptorMaps[globalLinkID].emplace_back(currentPos, mCRU, linkID, endPoint, memorySize, packetSize, heartbeatOrbit);
378 mLinkPresent[globalLinkID] =
true;
379 mPacketsPerLink[globalLinkID]++;
381 linkInfo->
PacketPositions.emplace_back(mPacketsPerLink[globalLinkID] - 1);
386 if (RDHUtils::getStop(rdh) == 1) {
394 O2ERROR(
"Found header word %x and required header word %x don't match, at %zu, stopping file scan", rdh.word0, RDH_HEADERWORD0, currentPos);
401 if (RDHUtils::getStop(rdh)) {
409 currentPos =
file.tellg();
423 std::cout <<
"Links present" << std::endl;
424 for (
int i = 0;
i < MaxNumberOfLinks;
i++) {
425 mLinkPresent[
i] ==
true ? std::cout <<
"1 " : std::cout <<
"0 ";
429 std::cout << std::dec
430 <<
"File Name : " << mInputFileName <<
"\n"
431 <<
"File size [bytes] : " << mFileSize <<
"\n"
432 <<
"Packets : " << numPackets <<
"\n"
435 if (mVerbosity > 1) {
437 for (
int i = 0;
i < MaxNumberOfLinks;
i++) {
438 if (mLinkPresent[
i]) {
439 std::cout <<
"Packets for link " <<
i <<
": " << mPacketsPerLink[
i] <<
"\n";
442 for (
const auto& pd : mPacketDescriptorMaps[
i]) {
443 std::cout << pd <<
"\n";
451 mFileIsScanned =
true;
463 for (
int link = 0; link < MaxNumberOfLinks; link++) {
470 std::cout <<
"Finding sync pattern for link " << link << std::endl;
471 std::cout <<
"Num packets : " << mPacketsPerLink[link] << std::endl;
475 uint32_t packetID{0};
478 for (
auto packet : mPacketDescriptorMaps[link]) {
481 file.seekg(packet.getPayloadOffset(),
file.beg);
486 for (
int frames = 0; frames < packet.getPayloadSize() / 16; frames++) {
490 gFrame.updateSyncCheck(mSyncPositions[link]);
499 std::cout <<
"Sync positions for link " << link <<
'\n';
500 const auto& syncs = mSyncPositions[link];
501 for (
int i = 0;
i < syncs.size(); ++
i) {
502 std::cout <<
i <<
" : " << syncs[
i];
523 for (
int frames = 0; frames <
size / 16; frames++) {
534 gFrame.getAdcValues(rawData);
550 for (
int iFrame = 0; iFrame <
data.size() / 16; ++iFrame) {
576 if (mDumpTextFiles && dumpSyncPositoins) {
577 const auto fileName = mOutputFilePrefix +
"/LinkPositions.txt";
578 std::ofstream
file(fileName, std::ofstream::app);
581 for (
int s = 0; s < 5; ++s) {
582 auto& syncPos = syncPositions[s];
583 if (syncPos.synched()) {
584 file << mEventNumber <<
"\t"
588 << syncPos.getPacketNumber() <<
"\t"
589 << syncPos.getFrameNumber() <<
"\t"
590 << syncPos.getHalfWordPosition() <<
"\n";
602void RawReaderCRU::fillADCdataMap(
const ADCRawData& rawData)
609 const int fecLinkOffsetCRU = (mapper.getPartitionInfo(cru.partition()).getNumberOfFECs() + 1) / 2;
610 const int fecInPartition = (mLink % 12) + (mLink > 11) * fecLinkOffsetCRU;
611 const int regionIter = mCRU % 2;
613 const int sampaMapping[10] = {0, 0, 1, 1, 2, 3, 3, 4, 4, 2};
614 const int channelOffset[10] = {0, 16, 0, 16, 0, 0, 16, 0, 16, 16};
616 for (
int istreamm = 0; istreamm < 5; ++istreamm) {
617 const int partitionStream = istreamm + regionIter * 5;
618 const int sampa = sampaMapping[partitionStream];
623 for (
int idata = 0; idata < dataVector.size(); ++idata) {
624 const int ichannel = idata % 16;
625 const int sampaChannel = ichannel + channelOffset[partitionStream];
626 const auto& padPos = mapper.padPosRegion(cru.region(), fecInPartition, sampa, sampaChannel);
627 mADCdata[padPos].emplace_back(dataVector[idata]);
639 const int fecLinkOffsetCRU = (mapper.getPartitionInfo(cru.
partition()).getNumberOfFECs() + 1) / 2;
640 const int fecInPartition = (mLink % 12) + (mLink > 11) * fecLinkOffsetCRU;
641 const int regionIter = mCRU % 2;
643 const int sampaMapping[10] = {0, 0, 1, 1, 2, 3, 3, 4, 4, 2};
644 const int channelOffset[10] = {0, 16, 0, 16, 0, 0, 16, 0, 16, 16};
646 for (
int istreamm = 0; istreamm < 5; ++istreamm) {
647 const int partitionStream = istreamm + regionIter * 5;
648 const int sampa = sampaMapping[partitionStream];
651 if (dataVector.size() < 16) {
656 for (
int ichannel = 0; ichannel < 16; ++ichannel) {
657 const int sampaChannel = ichannel + channelOffset[partitionStream];
658 const auto& padPos = mapper.padROCPos(cru, fecInPartition, sampa, sampaChannel);
660 mManager->mADCDataCallback(padPos, cru, gsl::span<const uint32_t>(dataVector.data() + ichannel, dataVector.size() - ichannel));
673 std::cout <<
"Processing data for link " << mLink << std::endl;
674 std::cout <<
"Num packets : " << mPacketsPerLink[mLink] << std::endl;
679 const int link = mLink;
685 for (
auto packetNumber : linkInfoArray[link].PacketPositions) {
686 const auto& packet = mPacketDescriptorMaps[link][packetNumber];
691 int retCode =
processPacket(gFrame, packet.getPayloadOffset(), packet.getPayloadSize(), rawData);
701 if (mFillADCdataMap) {
702 fillADCdataMap(rawData);
704 if (mManager && mManager->mADCDataCallback) {
711 if (mDumpTextFiles) {
713 std::string fileName;
714 for (
int s = 0; s < 5; s++) {
715 if (mStream == 0x0 or ((mStream >> s) & 0x1) == 0x1) {
717 std::cout <<
"No sync found" << std::endl;
723 std::cout << rawData << std::endl;
728 file.open(fileName, std::ofstream::out);
741 std::cout <<
"Processing data for link " << mLink << std::endl;
742 std::cout <<
"Num packets : " << mPacketsPerLink[mLink] << std::endl;
754 std::vector<std::byte>
data;
756 collectGBTData(
data);
762 if (mFillADCdataMap) {
763 fillADCdataMap(rawData);
765 if (mManager->mADCDataCallback) {
770void RawReaderCRU::collectGBTData(std::vector<std::byte>&
data)
775 size_t presentDataPosition = 0;
779 for (
auto packetNumber : linkInfoArray[mLink].PacketPositions) {
780 const auto& packet = mPacketDescriptorMaps[mLink][packetNumber];
782 const auto payloadStart = packet.getPayloadOffset();
783 const auto payloadSize = size_t(packet.getPayloadSize());
784 data.insert(
data.end(), payloadSize, (std::byte)0);
786 file.seekg(payloadStart, std::ios::beg);
789 file.read(((
char*)
data.data()) + presentDataPosition, payloadSize);
791 presentDataPosition += payloadSize;
797 const auto& eventInfo = mManager->mEventSync.
getEventInfo(mEventNumber);
798 const auto& linkInfoArray = eventInfo.
CRUInfoArray[mCRU].LinkInformation;
799 const auto firstOrbitInEvent = eventInfo.getFirstOrbit();
806 for (
const auto packetNumber : linkInfoArray[mLink].PacketPositions) {
807 const auto& packet = mPacketDescriptorMaps[mLink][packetNumber];
808 const size_t payloadOffset = packet.getPayloadOffset();
809 const size_t payloadSize = packet.getPayloadSize();
810 if ((payloadOffset + payloadSize) > mFileSize) {
811 LOGP(error,
"File truncated at {}, size {} would exceed file size of {}", payloadOffset, payloadSize, mFileSize);
814 file.seekg(payloadOffset,
file.beg);
816 const uint32_t syncOffsetReference = 144;
824 LOGP(error,
"cannont run without manager");
835 O2ERROR(
"Selected event number %u is larger than the events in file %lu", mEventNumber, mManager->mEventSync.
getNumberOfEvents());
842 for (
int lnk = 0; lnk < MaxNumberOfLinks; lnk++) {
844 if (((linkMask == 0) || ((linkMask >> lnk) & 1)) &&
checkLinkPresent(lnk) ==
true) {
847 fmt::print(
"Processing link {}\n", lnk);
860 std::cout << e.what() << std::endl;
862 }
catch (
const std::exception& e) {
863 std::cerr <<
"ERROR: " << e.what() << std::endl;
866 std::cerr <<
"ERROR: Unknown error" << std::endl;
878 for (
auto& reader : cruManager.
getReaders()) {
879 reader->mDumpTextFiles =
true;
880 reader->mFillADCdataMap =
false;
885 std::string outPrefix = outputFilePrefix.length() ? outputFilePrefix.data() :
"./";
886 const auto fileName = outPrefix +
"/LinkPositions.txt";
887 std::ofstream
file(fileName, std::ofstream::out);
888 file <<
"EventNumber/I"
900 <<
"HalfWordPosition"
906 fmt::print(
"=============| event {: 5d} |===============\n", ievent);
915 std::string outputFileName(gSystem->BaseName(mInputFileName.data()));
916 if (outputDirectory.empty()) {
917 outputFileName.insert(0,
"filtered.");
918 outputDirectory = gSystem->DirName(mInputFileName.data());
920 outputFileName.insert(0,
"/");
921 outputFileName.insert(0, outputDirectory);
923 std::ofstream outputFile(outputFileName, std::ios_base::binary |
mode);
932 for (
const auto eventNumber : eventNumbers) {
936 for (
int iLink = 0; iLink < MaxNumberOfLinks; ++iLink) {
937 const auto& linkInfo = linkInfoArray[iLink];
938 if (!linkInfo.IsPresent) {
941 for (
auto packetNumber : linkInfo.PacketPositions) {
942 const auto& packet = mPacketDescriptorMaps[iLink][packetNumber];
943 file.seekg(packet.getHeaderOffset(),
file.beg);
945 outputFile.write(
buffer, packet.getPacketSize());
961 if ((maxEvents > -1) && (eventNumber >= maxEvents)) {
967 for (
int iLink = 0; iLink < MaxNumberOfLinks; ++iLink) {
968 const auto& linkInfo = linkInfoArray[iLink];
969 if (!linkInfo.IsPresent) {
972 printf(
"Event %4d, Link %2d\n", eventNumber, iLink);
974 const int ep = iLink >= 12;
975 const int link = iLink - (ep)*12;
976 auto outputFileName = fmt::format(
"{}/CRU_{:02}_EP_{}_Link_{:02}", outputDirectory.data(), (
int)mCRU, ep, link);
977 std::ofstream outputFile(outputFileName, std::ios_base::binary | std::ios_base::app);
979 for (
auto packetNumber : linkInfo.PacketPositions) {
980 const auto& packet = mPacketDescriptorMaps[iLink][packetNumber];
981 file.seekg(packet.getPayloadOffset(),
file.beg);
983 outputFile.write(
buffer, packet.getPayloadSize());
994 const auto numTimeBins = std::min(
getNumTimebins(), mNumTimeBins);
995 for (
int i = 0;
i < numTimeBins * 16;
i++) {
999 output << std::setw(4) << mADCRaw[(mOutputStream)][
i];
1000 output << (((
i + 1) % 16 == 0) ?
"\n" :
" ");
1006 mFilePos = input.tellg();
1008 for (
int i = 0;
i < 4;
i++) {
1009 input.read(
reinterpret_cast<char*
>(&(mData[
i])),
sizeof(mData[
i]));
1016 const auto offset = mPrevHWpos ^ 4;
1017 output << std::dec <<
"\033[94m"
1018 << std::setfill(
'0') << std::setw(8) << mPacketNum <<
" "
1019 << std::setfill(
'0') << std::setw(8) << mFilePos <<
" "
1020 << std::setfill(
'0') << std::setw(8) << mFrameNum <<
" : "
1022 << std::setfill(
'0') << std::setw(8) << mData[3] <<
"."
1023 << std::setfill(
'0') << std::setw(8) << mData[2] <<
"."
1024 << std::setfill(
'0') << std::setw(8) << mData[1] <<
"."
1025 << std::setfill(
'0') << std::setw(8) << mData[0] <<
" : "
1027 for (
int i = 0;
i < 5;
i++) {
1028 for (
int j = 0;
j < 4;
j++) {
1029 output << std::hex << std::setw(4) << mFrameHalfWords[
i][
j +
offset] <<
" ";
1039 output <<
"===| Packet Descriptor |================================="
1052 output <<
"word0 : 0x" << std::setfill(
'0') << std::setw(16) << std::hex << rdh.
word0 <<
"\n"
1055 output <<
" headerSize : " << RDHUtils::getHeaderSize(rdh) <<
"\n";
1057 output <<
" blockLength : " << RDHUtils::getBlockLength(rdh) <<
"\n";
1059 output <<
" feeId : " << RDHUtils::getFEEID(rdh) <<
"\n";
1060 output <<
" priority : " << RDHUtils::getPriorityBit(rdh) <<
"\n";
1063 output <<
"word1 : 0x" << std::setfill(
'0') << std::setw(16) << std::hex << rdh.
word1 <<
"\n"
1065 output <<
" Offset to next : " <<
int(RDHUtils::getOffsetToNext(rdh)) <<
"\n";
1066 output <<
" Memory size : " <<
int(RDHUtils::getMemorySize(rdh)) <<
"\n";
1067 output <<
" LinkID : " <<
int(RDHUtils::getLinkID(rdh)) <<
"\n";
1068 output <<
" Global LinkID : " <<
int(RDHUtils::getLinkID(rdh)) + (((rdh.
word1 >> 32) >> 28) * 12) <<
"\n";
1069 output <<
" CRUid : " << RDHUtils::getCRUID(rdh) <<
"\n";
1070 output <<
" Packet Counter : " << RDHUtils::getPacketCounter(rdh) <<
"\n";
1071 output <<
" DataWrapper-ID : " << (((rdh.
word1 >> 32) >> 28) & 0x01) <<
"\n";
1074 output <<
"word2 : 0x" << std::setfill(
'0') << std::setw(16) << std::hex << rdh.
word2 <<
"\n"
1076 output <<
" triggerOrbit : " << RDHUtils::getTriggerOrbit(rdh) <<
"\n";
1077 output <<
" heartbeatOrbit : " << RDHUtils::getHeartBeatOrbit(rdh) <<
"\n";
1080 output <<
"word3 : 0x" << std::setfill(
'0') << std::setw(16) << std::hex << rdh.
word3 <<
"\n"
1084 output <<
"word4 : 0x" << std::setfill(
'0') << std::setw(16) << std::hex << rdh.
word4 <<
"\n"
1086 output <<
" triggerBC : " << RDHUtils::getTriggerBC(rdh) <<
"\n";
1087 output <<
" heartbeatBC : " << RDHUtils::getHeartBeatBC(rdh) <<
"\n";
1088 output <<
" triggerType : " << RDHUtils::getTriggerType(rdh) <<
"\n";
1091 output <<
"word5 : 0x" << std::setfill(
'0') << std::setw(16) << std::hex << rdh.
word5 <<
"\n"
1095 output <<
"word6 : 0x" << std::setfill(
'0') << std::setw(16) << std::hex << rdh.
word6 <<
"\n"
1097 output <<
" detectorField : " << RDHUtils::getDetectorField(rdh) <<
"\n";
1098 output <<
" par : " << RDHUtils::getDetectorPAR(rdh) <<
"\n";
1099 output <<
" stop : " << RDHUtils::getStop(rdh) <<
"\n";
1100 output <<
" pageCnt : " << RDHUtils::getPageCounter(rdh) <<
"\n";
1103 output <<
"word7 : 0x" << std::setfill(
'0') << std::setw(16) << std::hex << rdh.
word7 <<
"\n"
1112 fmt::print(
"{:>5} {:>4} {:>4} {:>4} {:>6} {:>4} {:>3} {:>4} {:>10} {:>5} {:>1}\n",
1113 "PkC",
"pCnt",
"trg",
"fId",
"OffN",
"Mem",
"CRU",
"GLID",
"HBOrbit",
"HBBC",
"s");
1118 const int globalLinkID =
int(RDHUtils::getLinkID(rdh)) + (((rdh.
word1 >> 32) >> 28) * 12);
1120 fmt::print(
"{:>5} {:>4} {:>4} {:>4} {:>6} {:>4} {:>3} {:>4} {:>10} {:>5} {:>1}\n",
1121 (uint64_t)RDHUtils::getPacketCounter(rdh),
1122 (uint64_t)RDHUtils::getPageCounter(rdh),
1123 (uint64_t)RDHUtils::getTriggerType(rdh),
1124 (uint64_t)RDHUtils::getFEEID(rdh),
1125 (uint64_t)RDHUtils::getOffsetToNext(rdh),
1126 (uint64_t)RDHUtils::getMemorySize(rdh),
1127 (uint64_t)RDHUtils::getCRUID(rdh),
1128 (uint64_t)globalLinkID,
1129 (uint64_t)RDHUtils::getHeartBeatOrbit(rdh),
1130 (uint64_t)RDHUtils::getHeartBeatBC(rdh),
1131 (uint64_t)RDHUtils::getStop(rdh));
1134template <
typename DataType>
1137 const int dataTypeSize =
sizeof(
data);
1138 auto charPtr =
reinterpret_cast<char*
>(&
data);
1139 input.read(charPtr, dataTypeSize);
1146 if (mIsInitialized) {
1150 for (
auto& reader : mRawReadersCRU) {
1154 mEventSync.sortEvents();
1155 mEventSync.analyse(mRawDataType);
1157 O2INFO(
"Event information:");
1159 O2INFO(
" Number of complete events: %lu", getNumberOfCompleteEvents());
1162 std::cout << mEventSync;
1165 mIsInitialized =
true;
1169 uint32_t numTimeBins,
1170 uint32_t debugLevel,
1172 const std::string_view outputFilePrefix)
1175 const TString files = gSystem->GetFromPipe(TString::Format(
"ls %s", inputFileNames.data()));
1176 std::unique_ptr<TObjArray> arr(files.Tokenize(
"\n"));
1179 for (
auto file : *arr) {
1181 auto& reader = createReader(
file->GetName(), numTimeBins);
1182 reader.setReaderNumber(mRawReadersCRU.size() - 1);
1184 reader.setDebugLevel(debugLevel);
1185 reader.setOutputFilePrefix(outputFilePrefix);
1186 O2INFO(
"Adding file: %s\n",
file->GetName());
1194 const auto& cruSeen = mEventSync.getCRUSeen();
1196 for (
size_t iCRU = 0; iCRU < cruSeen.size(); ++iCRU) {
1197 const auto readerNumber = cruSeen[iCRU];
1198 if (readerNumber >= 0) {
1199 auto& reader = mRawReadersCRU[readerNumber];
1200 reader->forceCRU(iCRU);
1201 reader->copyEvents(eventNumbers, outputDirectory.data(),
mode);
1216 const auto& cruSeen = mEventSync.getCRUSeen();
1218 for (
size_t iCRU = 0; iCRU < cruSeen.size(); ++iCRU) {
1219 const auto readerNumber = cruSeen[iCRU];
1220 if (readerNumber >= 0) {
1221 auto& reader = mRawReadersCRU[readerNumber];
1222 reader->forceCRU(iCRU);
1223 reader->writeGBTDataPerLink(outputDirectory, maxEvents);
1230 if (!std::filesystem::exists(outputDirectory)) {
1231 if (!std::filesystem::create_directories(outputDirectory)) {
1232 LOG(fatal) <<
"could not create output directory " << outputDirectory;
1234 LOG(info) <<
"created output directory " << outputDirectory;
1245 const auto& cruSeen = mEventSync.getCRUSeen();
1247 for (
size_t iCRU = 0; iCRU < cruSeen.size(); ++iCRU) {
1248 const auto readerNumber = cruSeen[iCRU];
1249 if (readerNumber >= 0) {
1250 auto& reader = mRawReadersCRU[readerNumber];
1251 if (reader->getFillADCdataMap()) {
1252 LOGF(warning,
"Filling of ADC data map not supported in RawReaderCRUManager::processEvent, it is disabled now. use ADCDataCallback");
1253 reader->setFillADCdataMap(
false);
1255 reader->setEventNumber(eventNumber);
1256 reader->forceCRU(iCRU);
1257 reader->processLinks();
void printHorizontal(const RDH &rdh)
std::istream & operator>>(std::istream &input, DataType &data)
#define CHECK_BIT(var, pos)
std::ostream & operator<<(std::ostream &output, const RDH &rdh)
unsigned short number() const
unsigned char partition() const
static Mapper & instance(const std::string mappingDir="")
helper to store the ADC raw data
void streamTo(std::ostream &output) const
write data to ostream
const DataVector & getDataVector(int stream) const
get the data vector for a specific stream
uint32_t getNumTimebins() const
number of time bin for selected stream
void setNumTimebins(uint32_t numTB)
void setOutputStream(uint32_t outStream)
select the stream for which data should be processed
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
bool syncFound(int stream)
void streamFrom(std::istream &input)
read from istream
void streamTo(std::ostream &output) const
write data to ostream
const SyncArray & getSyncArray() const
get the syncronisation array
const EventInfo & getEventInfo(size_t eventNumber) const
information of specific event
LinkInfo & getLinkInfo(const RDH &rdh, DataType dataType)
get link information for a specific event and cru
static constexpr size_t ExpectedNumberOfPacketsPerHBFrame
expected number of packets in one HB frame per link for HB scaling mode
size_t getNumberOfEvents() const
get number of all events
void setCRUSeen(const CRU cru, const uint16_t reader=0)
set a cru as seen
void analyse(RAWDataType rawDataType=RAWDataType::GBT)
analyse events and mark complete events
void setLinksSeen(const CRU cru, const std::bitset< MaxNumberOfLinks > &links)
set links that were seen for a CRU
const LinkInfoArray_t & getLinkInfoArrayForEvent(size_t eventNumber, int cru) const
get array with all link informaiton for a specific event number and cru
void streamTo(std::ostream &output) const
write data to ostream
EventInfo & createEvent(const uint32_t heartbeatOrbit, DataType dataType)
create a new event or return the one with the given HB orbit
void writeGBTDataPerLink(std::string_view outputDirectory, int maxEvents=-1)
copy single events from raw input files to another file
DataType getDataType() const
get data type
void init()
initialize all readers
std::function< void()> EndReaderCallback
void processEvent(uint32_t eventNumber, EndReaderCallback endReader=nullptr)
process event calling mADCDataCallback to process values
void setupReaders(const std::string_view inputFileNames, uint32_t numTimeBins=1000, uint32_t debugLevel=0, uint32_t verbosity=0, const std::string_view outputFilePrefix="")
size_t getNumberOfEvents() const
get number of all events
void copyEvents(const std::vector< uint32_t > eventNumbers, std::string_view outputDirectory, std::ios_base::openmode mode=std::ios_base::openmode(0))
copy single events to another file
void setDebugLevel(uint32_t debugLevel)
set debug level
auto & getReaders()
return vector of readers
FEEIDType getLinkID() const
FEEIDType getGlobalLinkID() const
FEEIDType getCRUID() const
uint32_t getPayloadSize() const
size_t getHeaderOffset() const
size_t getPayloadOffset() const
void streamTo(std::ostream &output) const
write data to ostream
int processDataFile()
process all data for the selected link reading single 8k packet from file
void findSyncPositions()
find sync positions for all links
static void processFile(const std::string_view inputFile, uint32_t timeBins=0, uint32_t linkMask=0, uint32_t stream=0, uint32_t debugLevel=0, uint32_t verbosity=0, const std::string_view outputFilePrefix="")
bool checkLinkPresent(uint32_t link)
status bits of present links
void processLinks(const uint32_t linkMask=0)
process links
void processDataMemory()
Collect data to memory and process data.
void runADCDataCallback(const ADCRawData &rawData)
run a data filling callback function
std::ifstream & getFileHandle()
file handling
void setDebugLevel(uint32_t debugLevel=1)
set debug level
void copyEvents(const std::vector< uint32_t > &eventNumbers, std::string outputDirectory, std::ios_base::openmode mode=std::ios_base::openmode(0))
copy single events to another file
int processMemory(const std::vector< std::byte > &data, ADCRawData &rawData)
size_t getNumberOfEvents() const
get number of events
bool syncFoundForLink(const int link) const
void processLinkZS()
process data in case of Link based zero suppression
void setLink(uint32_t link)
int processPacket(GBTFrame &gFrame, uint32_t startPos, uint32_t size, ADCRawData &rawData)
process single packet
void writeGBTDataPerLink(std::string_view outputDirectory, int maxEvents=-1)
write GBT data into separate files per link
constexpr o2::header::DataOrigin gDataOriginTPC
std::istream & operator>>(std::istream &stream, o2::header::RAWDataHeaderV4 &header)
bool processZSdata(const char *data, size_t size, rdh_utils::FEEIDType feeId, uint32_t orbit, uint32_t referenceOrbit, uint32_t syncOffsetReference, ADCCallback fillADC)
@ Triggered
triggered data
@ HBScaling
heart beat sclaing mode
@ GBT
GBT encoded raw data.
@ LinkZS
Link based zero suppression.
@ EventInfo
dump event synchronisation information
@ GBTFrames
dump all GBT frames
@ SyncPositions
dump sync positions
@ ADCValues
dump extracted ADC values
std::ostream & operator<<(std::ostream &out, const tpc::FECInfo &fec)
std::string to_string(gsl::span< T, Size > span)
static void setFEEID(RDHv4 &rdh, uint16_t v)
static constexpr int getVersion()
get numeric version of the RDH
static void setCRUID(H &rdh, uint16_t v, NOTPTR(H))
helper to store event information
CRUInfoArray_t CRUInfoArray
Link information for each cru.
bool hasHearbeatOrbit(uint32_t heartbeatOrbit) const
check if heartbeatOrbit contributes to the event
std::vector< uint32_t > HeartbeatOrbits
vector of heartbeat orbits contributing to the event
helper to store link information in an event
bool IsPresent
if the link is present in the current event
bool HBEndSeen
if HB end frame was seen
size_t PayloadSize
total payload size of the link in the present event
std::vector< size_t > PacketPositions
all packet positions of this link in an event
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"