61 uint32_t numChansPerAsicSts = 128;
62 uint32_t numAsicsPerModuleSts = 16;
65 auto equipIdsSts =
fStsConfig.GetEquipmentIds();
66 for (
auto& equip : equipIdsSts) {
67 std::unique_ptr<UnpackStsPar> par(
new UnpackStsPar());
68 par->fNumChansPerAsic = numChansPerAsicSts;
69 par->fNumAsicsPerModule = numAsicsPerModuleSts;
70 const size_t numElinks =
fStsConfig.GetNumElinks(equip);
71 for (
size_t elink = 0; elink < numElinks; elink++) {
72 UnpackStsElinkPar elinkPar;
74 elinkPar.fAddress = mapEntry.first;
75 elinkPar.fAsicNr = mapEntry.second;
76 elinkPar.fTimeOffset = 0.;
77 elinkPar.fAdcOffset = 0.;
78 elinkPar.fAdcGain = 0.;
80 par->fElinkParams.push_back(elinkPar);
82 fAlgoSts[equip].SetParams(std::move(par));
83 LOG(info) <<
"--- Configured equipment " << equip <<
" with " << numElinks <<
" elinks";
86 LOG(info) <<
"--- Configured " <<
fAlgoSts.size() <<
" unpacker algorithms for STS.";
87 LOG(debug) <<
"Readout map:" <<
fStsConfig.PrintReadoutMap();
88 LOG(info) <<
"==================================================";
89 std::cout << std::endl;
93 for (
auto& equip : equipIdsMuch) {
94 std::unique_ptr<UnpackMuchPar> par(
new UnpackMuchPar());
95 const size_t numElinks =
fMuchConfig.GetNumElinks(equip);
96 for (
size_t elink = 0; elink < numElinks; elink++) {
97 UnpackMuchElinkPar elinkPar;
99 elinkPar.fTimeOffset = 0.;
100 par->fElinkParams.push_back(elinkPar);
102 fAlgoMuch[equip].SetParams(std::move(par));
103 LOG(info) <<
"--- Configured equipment " << equip <<
" with " << numElinks <<
" elinks";
106 LOG(info) <<
"--- Configured " <<
fAlgoMuch.size() <<
" unpacker algorithms for MUCH.";
107 LOG(info) <<
"==================================================";
108 std::cout << std::endl;
118 std::string message =
"full";
119 LOG(debug) <<
"Requesting new TS by sending message: full" << message;
120 FairMQMessagePtr req(NewSimpleMessage(message));
121 FairMQMessagePtr rep(NewMessage());
124 LOG(error) <<
"Failed to send the request! message was " << message;
128 LOG(error) <<
"Failed to receive a reply to the request! message was " << message;
131 else if (rep->GetSize() == 0) {
132 LOG(error) <<
"Received empty reply. Something went wrong with the timeslice generation! message was " << message;
142 LOG(debug) <<
"Received message number " <<
fNumMessages <<
" with size " << rep->GetSize();
146 std::string msgStr(
static_cast<char*
>(rep->GetData()), rep->GetSize());
147 std::istringstream iss(msgStr);
148 boost::archive::binary_iarchive inputArchive(iss);
151 fles::StorableTimeslice ts{0};
155 const size_t NbCoreMsPerTs = ts.num_core_microslices();
156 const size_t NbOverMsPerTs = ts.num_microslices(0) - ts.num_core_microslices();
157 const double MsSizeInNs = (ts.descriptor(0, NbCoreMsPerTs).idx - ts.descriptor(0, 0).idx) / NbCoreMsPerTs;
158 const double TsCoreSizeInNs = MsSizeInNs * (NbCoreMsPerTs);
159 const double TsOverSizeInNs = MsSizeInNs * (NbOverMsPerTs);
160 const double TsFullSizeInNs = TsCoreSizeInNs + TsOverSizeInNs;
161 const TimesliceMetaData TsMetaData(ts.start_time(), TsCoreSizeInNs, TsOverSizeInNs, ts.index());
164 LOG(info) <<
"Timeslice parameters: each TS has " << NbCoreMsPerTs <<
" Core MS and " << NbOverMsPerTs
165 <<
" Overlap MS, for a MS duration of " << MsSizeInNs <<
" ns, a core duration of " << TsCoreSizeInNs
166 <<
" ns and a full duration of " << TsFullSizeInNs <<
" ns";
172 LOG(debug) <<
"Unpack: Sending TS index " << ts.index();
174 if (!
SendData(digiTs, TsMetaData))
return false;
175 LOG(debug) <<
"Unpack: Sent TS index " << ts.index();
220 const uint64_t tsIndex = timeslice.index();
221 const uint64_t tsTime = timeslice.start_time();
222 const uint64_t numComp = timeslice.num_components();
232 uint64_t numCompUsed = 0;
235 for (uint64_t comp = 0; comp < numComp; comp++) {
238 size_t numBytesInComp = 0;
239 size_t numDigisInComp = 0;
240 uint64_t numMsInComp = 0;
242 TStopwatch compTimer;
245 auto systemId =
static_cast<fles::Subsystem
>(timeslice.descriptor(comp, 0).sys_id);
247 if (systemId == fles::Subsystem::STS) {
248 const uint16_t equipmentId = timeslice.descriptor(comp, 0).eq_id;
249 const auto algoIt =
fAlgoSts.find(equipmentId);
256 assert(timeslice.descriptor(comp, 0).sys_ver == 0x20);
259 numMsInComp = timeslice.num_microslices(comp);
260 for (uint64_t mslice = 0; mslice < numMsInComp; mslice++) {
261 const auto msDescriptor = timeslice.descriptor(comp, mslice);
262 const auto msContent = timeslice.content(comp, mslice);
263 numBytesInComp += msDescriptor.size;
264 auto result = (algoIt->second)(msContent, msDescriptor, tsTime);
265 LOG(debug1) <<
"CbmDevUnpack::DoUnpack(): Component " << comp <<
", microslice " << mslice <<
", digis "
266 << result.first.size() <<
", errors " << result.second.fNumNonHitOrTsbMessage <<
" | "
267 << result.second.fNumErrElinkOutOfRange <<
" | " << result.second.fNumErrInvalidFirstMessage
268 <<
" | " << result.second.fNumErrInvalidMsSize <<
" | " << result.second.fNumErrTimestampOverflow
271 digiTs.
fData.
fSts.
fDigis.insert(it, result.first.begin(), result.first.end());
272 numDigisInComp += result.first.size();
277 if (systemId == fles::Subsystem::MUCH) {
278 const uint16_t equipmentId = timeslice.descriptor(comp, 0).eq_id;
279 const auto algoIt =
fAlgoMuch.find(equipmentId);
286 assert(timeslice.descriptor(comp, 0).sys_ver == 0x20);
289 numMsInComp = timeslice.num_microslices(comp);
290 for (uint64_t mslice = 0; mslice < numMsInComp; mslice++) {
291 const auto msDescriptor = timeslice.descriptor(comp, mslice);
292 const auto msContent = timeslice.content(comp, mslice);
293 numBytesInComp += msDescriptor.size;
294 auto result = (algoIt->second)(msContent, msDescriptor, tsTime);
295 LOG(debug1) <<
"CbmDevUnpack::DoUnpack(): Component " << comp <<
", microslice " << mslice <<
", digis "
296 << result.first.size() <<
", errors " << result.second.fNumNonHitOrTsbMessage <<
" | "
297 << result.second.fNumErrElinkOutOfRange <<
" | " << result.second.fNumErrInvalidFirstMessage
298 <<
" | " << result.second.fNumErrInvalidMsSize <<
" | " << result.second.fNumErrTimestampOverflow
301 digiTs.
fData.
fMuch.
fDigis.insert(it, result.first.begin(), result.first.end());
302 numDigisInComp += result.first.size();
309 LOG(debug) <<
"CbmDevUnpack::DoUnpack(): Component " << comp <<
", microslices " << numMsInComp <<
" input size "
310 << numBytesInComp <<
" bytes, "
311 <<
", digis " << numDigisInComp <<
", CPU time " << compTimer.CpuTime() * 1000. <<
" ms";
312 numBytes += numBytesInComp;
313 numDigis += numDigisInComp;
314 numMs += numMsInComp;
326 logOut << setw(15) << left <<
"CbmDevUnpack::DoUnpackGetName(): [";
327 logOut << fixed << setw(8) << setprecision(1) << right << timer.RealTime() * 1000. <<
" ms] ";
328 logOut <<
"TS " <<
fNumTs <<
" (index " << tsIndex <<
")";
329 logOut <<
", components " << numCompUsed <<
" / " << numComp <<
", microslices " << numMs;
330 logOut <<
", input rate " << double(numBytes) / timer.RealTime() / 1.e6 <<
" MB/s";
331 logOut <<
", digis " << numDigis;
332 LOG(debug) << logOut.str();
334 if (0 ==
fNumTs % 10000) LOG(info) <<
"Processed " <<
fNumTs <<
" time slices";