@@ -207,20 +207,16 @@ void GPUReconstructionConvert::ZSfillEmpty(void* ptr, int shift, unsigned int fe
207207
208208static inline auto ZSEncoderGetDigits (const GPUTrackingInOutDigits& in, int i) { return in.tpcDigits [i]; }
209209static inline auto ZSEncoderGetNDigits (const GPUTrackingInOutDigits& in, int i) { return in.nTPCDigits [i]; }
210- template void GPUReconstructionConvert::RunZSEncoder<o2::tpc::Digit, GPUTrackingInOutDigits>(const GPUTrackingInOutDigits&, std::unique_ptr<unsigned long long int []>*, unsigned int *, o2::raw::RawFileWriter*, const o2::InteractionRecord*, const GPUParam&, bool , bool , float , bool );
210+ template void GPUReconstructionConvert::RunZSEncoder<GPUTrackingInOutDigits>(const GPUTrackingInOutDigits&, std::unique_ptr<unsigned long long int []>*, unsigned int *, o2::raw::RawFileWriter*, const o2::InteractionRecord*, const GPUParam&, bool , bool , float , bool );
211211#ifdef GPUCA_O2_LIB
212212using DigitArray = std::array<gsl::span<const o2::tpc::Digit>, o2::tpc::Sector::MAXSECTOR >;
213- template void GPUReconstructionConvert::RunZSEncoder<o2::tpc::Digit, DigitArray>(const DigitArray&, std::unique_ptr<unsigned long long int []>*, unsigned int *, o2::raw::RawFileWriter*, const o2::InteractionRecord*, const GPUParam&, bool , bool , float , bool );
213+ template void GPUReconstructionConvert::RunZSEncoder<DigitArray>(const DigitArray&, std::unique_ptr<unsigned long long int []>*, unsigned int *, o2::raw::RawFileWriter*, const o2::InteractionRecord*, const GPUParam&, bool , bool , float , bool );
214214static inline auto ZSEncoderGetDigits (const DigitArray& in, int i) { return in[i].data (); }
215215static inline auto ZSEncoderGetNDigits (const DigitArray& in, int i) { return in[i].size (); }
216- #endif
217- static inline auto ZSEncoderGetTime (const o2::tpc::Digit a) { return a.getTimeStamp (); }
218- static inline auto ZSEncoderGetPad (const o2::tpc::Digit a) { return a.getPad (); }
219- static inline auto ZSEncoderGetRow (const o2::tpc::Digit a) { return a.getRow (); }
220- static inline auto ZSEncoderGetCharge (const o2::tpc::Digit a) { return a.getChargeFloat (); }
221- #endif
216+ #endif // GPUCA_O2_LIB
217+ #endif // GPUCA_HAVE_O2HEADERS
222218
223- template <class T , class S >
219+ template <class S >
224220void GPUReconstructionConvert::RunZSEncoder (const S& in, std::unique_ptr<unsigned long long int []>* outBuffer, unsigned int * outSizes, o2::raw::RawFileWriter* raw, const o2::InteractionRecord* ir, const GPUParam& param, bool zs12bit, bool verify, float threshold, bool padding)
225221{
226222 // Pass in either outBuffer / outSizes, to fill standalone output buffers, or raw to use RawFileWriter
@@ -250,31 +246,31 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr<unsigne
250246 int rawendpoint = 0 ;
251247 (void )(rawcru + rawendpoint); // avoid compiler warning
252248
253- std::vector<T > tmpBuffer;
249+ std::vector<o2::tpc::Digit > tmpBuffer;
254250 std::array<unsigned short , TPCZSHDR ::TPC_ZS_PAGE_SIZE > streamBuffer;
255251 std::array<unsigned char , TPCZSHDR ::TPC_ZS_PAGE_SIZE > streamBuffer8;
256252 tmpBuffer.resize (ZSEncoderGetNDigits (in, i));
257253 if (threshold > 0 .f ) {
258- auto it = std::copy_if (ZSEncoderGetDigits (in, i), ZSEncoderGetDigits (in, i) + ZSEncoderGetNDigits (in, i), tmpBuffer.begin (), [threshold](auto & v) { return ZSEncoderGetCharge (v ) >= threshold; });
254+ auto it = std::copy_if (ZSEncoderGetDigits (in, i), ZSEncoderGetDigits (in, i) + ZSEncoderGetNDigits (in, i), tmpBuffer.begin (), [threshold](auto & v) { return v. getChargeFloat ( ) >= threshold; });
259255 tmpBuffer.resize (std::distance (tmpBuffer.begin (), it));
260256 } else {
261257 std::copy (ZSEncoderGetDigits (in, i), ZSEncoderGetDigits (in, i) + ZSEncoderGetNDigits (in, i), tmpBuffer.begin ());
262258 }
263- std::sort (tmpBuffer.begin (), tmpBuffer.end (), [¶m](const T a, const T b) {
264- int endpointa = param.tpcGeometry .GetRegion (ZSEncoderGetRow (a ));
265- int endpointb = param.tpcGeometry .GetRegion (ZSEncoderGetRow (b ));
266- endpointa = 2 * endpointa + (ZSEncoderGetRow (a ) >= param.tpcGeometry .GetRegionStart (endpointa) + param.tpcGeometry .GetRegionRows (endpointa) / 2 );
267- endpointb = 2 * endpointb + (ZSEncoderGetRow (b ) >= param.tpcGeometry .GetRegionStart (endpointb) + param.tpcGeometry .GetRegionRows (endpointb) / 2 );
259+ std::sort (tmpBuffer.begin (), tmpBuffer.end (), [¶m](const o2::tpc::Digit a, const o2::tpc::Digit b) {
260+ int endpointa = param.tpcGeometry .GetRegion (a. getRow ( ));
261+ int endpointb = param.tpcGeometry .GetRegion (b. getRow ( ));
262+ endpointa = 2 * endpointa + (a. getRow ( ) >= param.tpcGeometry .GetRegionStart (endpointa) + param.tpcGeometry .GetRegionRows (endpointa) / 2 );
263+ endpointb = 2 * endpointb + (b. getRow ( ) >= param.tpcGeometry .GetRegionStart (endpointb) + param.tpcGeometry .GetRegionRows (endpointb) / 2 );
268264 if (endpointa != endpointb) {
269265 return endpointa <= endpointb;
270266 }
271- if (ZSEncoderGetTime (a ) != ZSEncoderGetTime (b )) {
272- return ZSEncoderGetTime (a ) <= ZSEncoderGetTime (b );
267+ if (a. getTimeStamp ( ) != b. getTimeStamp ( )) {
268+ return a. getTimeStamp ( ) <= b. getTimeStamp ( );
273269 }
274- if (ZSEncoderGetRow (a ) != ZSEncoderGetRow (b )) {
275- return ZSEncoderGetRow (a ) <= ZSEncoderGetRow (b );
270+ if (a. getRow ( ) != b. getRow ( )) {
271+ return a. getRow ( ) <= b. getRow ( );
276272 }
277- return ZSEncoderGetPad (a ) < ZSEncoderGetPad (b );
273+ return a. getPad ( ) < b. getPad ( );
278274 });
279275 int lastEndpoint = -2 , lastRow = GPUCA_ROW_COUNT , lastTime = -1 ;
280276 long hbf = -1 , nexthbf = 0 ;
@@ -289,27 +285,27 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr<unsigne
289285 for (unsigned int k = 0 ; k <= tmpBuffer.size (); k++) {
290286 int seqLen = 1 ;
291287 if (k < tmpBuffer.size ()) {
292- if (lastRow != ZSEncoderGetRow ( tmpBuffer[k])) {
293- region = param.tpcGeometry .GetRegion (ZSEncoderGetRow ( tmpBuffer[k]));
288+ if (lastRow != tmpBuffer[k]. getRow ( )) {
289+ region = param.tpcGeometry .GetRegion (tmpBuffer[k]. getRow ( ));
294290 endpointStart = param.tpcGeometry .GetRegionStart (region);
295291 endpoint = region * 2 ;
296- if (ZSEncoderGetRow ( tmpBuffer[k]) >= endpointStart + param.tpcGeometry .GetRegionRows (region) / 2 ) {
292+ if (tmpBuffer[k]. getRow ( ) >= endpointStart + param.tpcGeometry .GetRegionRows (region) / 2 ) {
297293 endpoint++;
298294 endpointStart += param.tpcGeometry .GetRegionRows (region) / 2 ;
299295 }
300296 }
301297 for (unsigned int l = k + 1 ; l < tmpBuffer.size (); l++) {
302- if (ZSEncoderGetRow ( tmpBuffer[l]) == ZSEncoderGetRow ( tmpBuffer[k]) && ZSEncoderGetTime ( tmpBuffer[l]) == ZSEncoderGetTime ( tmpBuffer[k]) && ZSEncoderGetPad ( tmpBuffer[l]) == ZSEncoderGetPad ( tmpBuffer[l - 1 ]) + 1 ) {
298+ if (tmpBuffer[l]. getRow ( ) == tmpBuffer[k]. getRow ( ) && tmpBuffer[l]. getTimeStamp ( ) == tmpBuffer[k]. getTimeStamp ( ) && tmpBuffer[l]. getPad ( ) == tmpBuffer[l - 1 ]. getPad ( ) + 1 ) {
303299 seqLen++;
304300 } else {
305301 break ;
306302 }
307303 }
308- if (lastTime != -1 && (int )hdr->nTimeBins + ZSEncoderGetTime ( tmpBuffer[k]) - lastTime >= 256 ) {
304+ if (lastTime != -1 && (int )hdr->nTimeBins + tmpBuffer[k]. getTimeStamp ( ) - lastTime >= 256 ) {
309305 lastEndpoint = -1 ;
310306 }
311- if (ZSEncoderGetTime ( tmpBuffer[k]) != lastTime) {
312- nexthbf = ((long )ZSEncoderGetTime ( tmpBuffer[k]) * LHCBCPERTIMEBIN + bcShiftInFirstHBF) / o2::constants::lhc::LHCMaxBunches;
307+ if (tmpBuffer[k]. getTimeStamp ( ) != lastTime) {
308+ nexthbf = ((long )tmpBuffer[k]. getTimeStamp ( ) * LHCBCPERTIMEBIN + bcShiftInFirstHBF) / o2::constants::lhc::LHCMaxBunches;
313309 if (nexthbf < 0 ) {
314310 throw std::runtime_error (" Received digit before the defined first orbit" );
315311 }
@@ -319,25 +315,25 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr<unsigne
319315 }
320316 if (endpoint == lastEndpoint) {
321317 unsigned int sizeChk = (unsigned int )(pagePtr - reinterpret_cast <unsigned char *>(page)); // already written
322- sizeChk += 2 * (nRowsInTB + (ZSEncoderGetRow ( tmpBuffer[k]) != lastRow && ZSEncoderGetTime ( tmpBuffer[k]) == lastTime)); // TB HDR
318+ sizeChk += 2 * (nRowsInTB + (tmpBuffer[k]. getRow ( ) != lastRow && tmpBuffer[k]. getTimeStamp ( ) == lastTime)); // TB HDR
323319 sizeChk += streamSize8; // in stream buffer
324- sizeChk += (lastTime != ZSEncoderGetTime ( tmpBuffer[k])) && ((sizeChk + (streamSize * encodeBits + 7 ) / 8 ) & 1 ); // time bin alignment
325- sizeChk += (ZSEncoderGetTime ( tmpBuffer[k]) != lastTime || ZSEncoderGetRow ( tmpBuffer[k]) != lastRow) ? 3 : 0 ; // new row overhead
326- sizeChk += (lastTime != -1 && ZSEncoderGetTime ( tmpBuffer[k]) > lastTime) ? ((ZSEncoderGetTime ( tmpBuffer[k]) - lastTime - 1 ) * 2 ) : 0 ; // empty time bins
320+ sizeChk += (lastTime != tmpBuffer[k]. getTimeStamp ( )) && ((sizeChk + (streamSize * encodeBits + 7 ) / 8 ) & 1 ); // time bin alignment
321+ sizeChk += (tmpBuffer[k]. getTimeStamp ( ) != lastTime || tmpBuffer[k]. getRow ( ) != lastRow) ? 3 : 0 ; // new row overhead
322+ sizeChk += (lastTime != -1 && tmpBuffer[k]. getTimeStamp ( ) > lastTime) ? ((tmpBuffer[k]. getTimeStamp ( ) - lastTime - 1 ) * 2 ) : 0 ; // empty time bins
327323 sizeChk += 2 ; // sequence metadata
328- const unsigned int streamSizeChkBits = streamSize * encodeBits + ((lastTime != ZSEncoderGetTime ( tmpBuffer[k]) && (streamSize * encodeBits) % 8 ) ? (8 - (streamSize * encodeBits) % 8 ) : 0 );
324+ const unsigned int streamSizeChkBits = streamSize * encodeBits + ((lastTime != tmpBuffer[k]. getTimeStamp ( ) && (streamSize * encodeBits) % 8 ) ? (8 - (streamSize * encodeBits) % 8 ) : 0 );
329325 if (sizeChk + (encodeBits + streamSizeChkBits + 7 ) / 8 > TPCZSHDR ::TPC_ZS_PAGE_SIZE ) {
330326 lastEndpoint = -1 ;
331327 } else if (sizeChk + (seqLen * encodeBits + streamSizeChkBits + 7 ) / 8 > TPCZSHDR ::TPC_ZS_PAGE_SIZE ) {
332328 seqLen = ((TPCZSHDR ::TPC_ZS_PAGE_SIZE - sizeChk) * 8 - streamSizeChkBits) / encodeBits;
333329 }
334330 // sizeChk += (seqLen * encodeBits + streamSizeChkBits + 7) / 8;
335- // printf("Endpoint %d (%d), Pos %d, Chk %d, Len %d, rows %d, StreamSize %d %d, time %d (%d), row %d (%d), pad %d\n", endpoint, lastEndpoint, (int) (pagePtr - reinterpret_cast<unsigned char*>(page)), sizeChk, seqLen, nRowsInTB, streamSize8, streamSize, (int) ZSEncoderGetTime( tmpBuffer[k]), lastTime, (int) ZSEncoderGetRow( tmpBuffer[k]), lastRow, ZSEncoderGetPad( tmpBuffer[k]));
331+ // printf("Endpoint %d (%d), Pos %d, Chk %d, Len %d, rows %d, StreamSize %d %d, time %d (%d), row %d (%d), pad %d\n", endpoint, lastEndpoint, (int) (pagePtr - reinterpret_cast<unsigned char*>(page)), sizeChk, seqLen, nRowsInTB, streamSize8, streamSize, (int)tmpBuffer[k].getTimeStamp( ), lastTime, (int)tmpBuffer[k].getRow( ), lastRow, tmpBuffer[k].getPad( ));
336332 }
337333 } else {
338334 nexthbf = -1 ;
339335 }
340- if (k >= tmpBuffer.size () || endpoint != lastEndpoint || ZSEncoderGetTime ( tmpBuffer[k]) != lastTime) {
336+ if (k >= tmpBuffer.size () || endpoint != lastEndpoint || tmpBuffer[k]. getTimeStamp ( ) != lastTime) {
341337 if (pagePtr != reinterpret_cast <unsigned char *>(page)) {
342338 pagePtr += 2 * nRowsInTB;
343339 ZSstreamOut (streamBuffer.data (), streamSize, streamBuffer8.data (), streamSize8, encodeBits);
@@ -395,19 +391,19 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr<unsigne
395391 hdr->cruID = i * 10 + region;
396392 rawcru = i * 10 + region;
397393 rawendpoint = endpoint & 1 ;
398- hdr->timeOffset = (long )ZSEncoderGetTime ( tmpBuffer[k]) * LHCBCPERTIMEBIN - (long )hbf * o2::constants::lhc::LHCMaxBunches;
394+ hdr->timeOffset = (long )tmpBuffer[k]. getTimeStamp ( ) * LHCBCPERTIMEBIN - (long )hbf * o2::constants::lhc::LHCMaxBunches;
399395 lastTime = -1 ;
400396 tbHdr = nullptr ;
401397 lastEndpoint = endpoint;
402398 totalPages++;
403399 }
404- if (ZSEncoderGetTime ( tmpBuffer[k]) != lastTime) {
400+ if (tmpBuffer[k]. getTimeStamp ( ) != lastTime) {
405401 if (lastTime != -1 ) {
406- hdr->nTimeBins += ZSEncoderGetTime ( tmpBuffer[k]) - lastTime - 1 ;
407- pagePtr += (ZSEncoderGetTime ( tmpBuffer[k]) - lastTime - 1 ) * 2 ;
402+ hdr->nTimeBins += tmpBuffer[k]. getTimeStamp ( ) - lastTime - 1 ;
403+ pagePtr += (tmpBuffer[k]. getTimeStamp ( ) - lastTime - 1 ) * 2 ;
408404 }
409405 hdr->nTimeBins ++;
410- lastTime = ZSEncoderGetTime ( tmpBuffer[k]);
406+ lastTime = tmpBuffer[k]. getTimeStamp ( );
411407 if ((pagePtr - reinterpret_cast <unsigned char *>(page)) & 1 ) {
412408 pagePtr++;
413409 }
@@ -416,9 +412,9 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr<unsigne
416412 nRowsInTB = 0 ;
417413 lastRow = GPUCA_ROW_COUNT ;
418414 }
419- if (ZSEncoderGetRow ( tmpBuffer[k]) != lastRow) {
420- tbHdr->rowMask |= 1 << (ZSEncoderGetRow ( tmpBuffer[k]) - endpointStart);
421- lastRow = ZSEncoderGetRow ( tmpBuffer[k]);
415+ if (tmpBuffer[k]. getRow ( ) != lastRow) {
416+ tbHdr->rowMask |= 1 << (tmpBuffer[k]. getRow ( ) - endpointStart);
417+ lastRow = tmpBuffer[k]. getRow ( );
422418 ZSstreamOut (streamBuffer.data (), streamSize, streamBuffer8.data (), streamSize8, encodeBits);
423419 if (nRowsInTB) {
424420 tbHdr->rowAddr1 ()[nRowsInTB - 1 ] = (pagePtr - reinterpret_cast <unsigned char *>(page)) + streamSize8;
@@ -428,11 +424,11 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr<unsigne
428424 *nSeq = 0 ;
429425 }
430426 (*nSeq)++;
431- streamBuffer8[streamSize8++] = ZSEncoderGetPad ( tmpBuffer[k]);
427+ streamBuffer8[streamSize8++] = tmpBuffer[k]. getPad ( );
432428 streamBuffer8[streamSize8++] = streamSize + seqLen;
433429 hdr->nADCsamples += seqLen;
434430 for (int l = 0 ; l < seqLen; l++) {
435- streamBuffer[streamSize++] = (unsigned short )(ZSEncoderGetCharge ( tmpBuffer[k + l]) * encodeBitsFactor + 0 .5f );
431+ streamBuffer[streamSize++] = (unsigned short )(tmpBuffer[k + l]. getChargeFloat ( ) * encodeBitsFactor + 0 .5f );
436432 }
437433 k += seqLen - 1 ;
438434 }
@@ -529,14 +525,14 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr<unsigne
529525 for (unsigned int j = 0 ; j < tmpBuffer.size (); j++) {
530526 const unsigned int decodeBits = zs12bit ? TPCZSHDR ::TPC_ZS_NBITS_V2 : TPCZSHDR ::TPC_ZS_NBITS_V1 ;
531527 const float decodeBitsFactor = (1 << (decodeBits - 10 ));
532- const float c = zs12bit ? (float )((int )(ZSEncoderGetCharge ( tmpBuffer[j]) * decodeBitsFactor + 0 .5f )) / decodeBitsFactor : (float )(int )(ZSEncoderGetCharge ( tmpBuffer[j]) + 0 .5f );
533- int ok = c == ZSEncoderGetCharge ( compareBuffer[j]) && (int )ZSEncoderGetTime ( tmpBuffer[j]) == (int )ZSEncoderGetTime ( compareBuffer[j]) && (int )ZSEncoderGetPad ( tmpBuffer[j]) == (int )ZSEncoderGetPad ( compareBuffer[j]) && (int )ZSEncoderGetRow ( tmpBuffer[j]) == (int )ZSEncoderGetRow ( compareBuffer[j]);
528+ const float c = zs12bit ? (float )((int )(tmpBuffer[j]. getChargeFloat ( ) * decodeBitsFactor + 0 .5f )) / decodeBitsFactor : (float )(int )(tmpBuffer[j]. getChargeFloat ( ) + 0 .5f );
529+ int ok = c == compareBuffer[j]. getChargeFloat ( ) && (int )tmpBuffer[j]. getTimeStamp ( ) == (int )compareBuffer[j]. getTimeStamp ( ) && (int )tmpBuffer[j]. getPad ( ) == (int )compareBuffer[j]. getPad ( ) && (int )tmpBuffer[j]. getRow ( ) == (int )compareBuffer[j]. getRow ( );
534530 if (ok) {
535531 continue ;
536532 }
537533 nErrors++;
538534 printf (" %4u: OK %d: Charge %3d %3d Time %4d %4d Pad %3d %3d Row %3d %3d\n " , j, ok,
539- (int )c, (int )ZSEncoderGetCharge ( compareBuffer[j]), (int )ZSEncoderGetTime ( tmpBuffer[j]), (int )ZSEncoderGetTime ( compareBuffer[j]), (int )ZSEncoderGetPad ( tmpBuffer[j]), (int )ZSEncoderGetPad ( compareBuffer[j]), (int )ZSEncoderGetRow ( tmpBuffer[j]), (int )ZSEncoderGetRow ( compareBuffer[j]));
535+ (int )c, (int )compareBuffer[j]. getChargeFloat ( ), (int )tmpBuffer[j]. getTimeStamp ( ), (int )compareBuffer[j]. getTimeStamp ( ), (int )tmpBuffer[j]. getPad ( ), (int )compareBuffer[j]. getPad ( ), (int )tmpBuffer[j]. getRow ( ), (int )compareBuffer[j]. getRow ( ));
540536 }
541537 }
542538 }
0 commit comments