CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018MsCrcCheck.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5// -----------------------------------------------------------------------------
6// ----- -----
7// ----- CbmMcbm2018MsCrcCheck -----
8// ----- Created 02.02.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
16
17#include "Timeslice.hpp"
18#include "TimesliceInputArchive.hpp"
19#include "TimesliceSubscriber.hpp"
20
21#include <Logger.h>
22
23#include <fstream>
24#include <iomanip>
25#include <iostream>
26
28 : fFileName("")
29 , fInputFileList(new TObjString())
30 , fFileCounter(0)
31 , fTSNumber(0)
32 , fTSCounter(0)
33 , fSource(nullptr)
34{
35}
36
38
40{
41 while (OpenNextFile()) {
42 while (auto timeslice = fSource->get()) {
43 const fles::Timeslice& ts = *timeslice;
44 auto tsIndex = ts.index();
45
46 if (0 == tsIndex % 1000) { LOG(info) << "Reading Timeslice " << tsIndex; } // if( 0 == tsIndex % 1000 )
47
48 UInt_t fuNbCoreMsPerTs = ts.num_core_microslices();
49 UInt_t fuNbComponents = ts.num_components();
51 for (UInt_t uMsIdx = 0; uMsIdx < fuNbCoreMsPerTs; uMsIdx++) {
53 for (UInt_t uMsCompIdx = 0; uMsCompIdx < fuNbComponents; ++uMsCompIdx) {
54 bool bCrcOk = ts.get_microslice(uMsCompIdx, uMsIdx).check_crc();
55
56 if (!bCrcOk) {
57 auto msDescriptor = ts.descriptor(uMsCompIdx, uMsIdx);
58 uint32_t uSize = msDescriptor.size;
59 const uint8_t* msContent = reinterpret_cast<const uint8_t*>(ts.content(uMsCompIdx, uMsIdx));
60 LOG(info) << "-----------------------------------------------------"
61 "----------";
62 // LOG(info) << Form( " CRC error for TS %6llu MS %3u Component %2u, dump following", tsIndex, uMsIdx, uMsCompIdx );
63 LOG(info) << " CRC error for TS " << FormatDecPrintout(tsIndex, 6)
64 << Form(" MS %3u Component %2u, dump following", uMsIdx, uMsCompIdx);
65 LOG(info) << "-----------------------------------------------------"
66 "----------";
67 /*
68 LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
69 LOG(info) << Form( "%02x %02x %04x %04x %02x %02x %016llx %08x %08x %016llx",
70 static_cast<unsigned int>(msDescriptor.hdr_id),
71 static_cast<unsigned int>(msDescriptor.hdr_ver), msDescriptor.eq_id, msDescriptor.flags,
72 static_cast<unsigned int>(msDescriptor.sys_id),
73 static_cast<unsigned int>(msDescriptor.sys_ver), msDescriptor.idx, msDescriptor.crc,
74 msDescriptor.size, msDescriptor.offset );
75*/
76 LOG(info) << FormatMsHeaderPrintout(msDescriptor);
77 std::stringstream ss;
78 for (UInt_t uByte = 0; uByte < uSize; ++uByte) {
79 ss << Form("%02x", msContent[uByte]);
80 if (3 == uByte % 4) ss << " ";
81 if (15 == uByte % 16) ss << "\n";
82 } // for( UInt_t uByte = 0; uByte < uSize; ++uByte )
83 if (0 == uSize % 16) ss << "\n";
84 LOG(info) << ss.str();
85 } // if( !bCrcOk )
86 } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fuNbComponents; ++uMsCompIdx )
87 } // for( UInt_t uMsIdx = 0; uMsIdx < fuNbCoreMsPerTs; uMsIdx ++ )
88
89 fTSCounter++;
90 if (0 == fTSCounter % 10000) {
91 LOG(info) << "Analysed " << fTSCounter << " TS ";
92 } // if( 0 == fTSCounter % 10000 )
93 } // while( auto timeslice = fSource->get() )
94
96 if (fSource->eos() && 0 < fFileName.Length()) {
97 fFileCounter++; // Increment file counter to go to next item in List
98 } // if( fSource->eos() && 0 < fFileName.Length() )
99 } // while( OpenNextFile() )
100}
101
103{
104 // First Close and delete existing source
105 if (nullptr != fSource) delete fSource;
106
107 if (fFileCounter < fInputFileList.GetSize()) {
108 // --- Open current input file
109 TObjString* tmp = dynamic_cast<TObjString*>(fInputFileList.At(fFileCounter));
110 fFileName = tmp->GetString();
111
112 LOG(info) << "Open the Flib input file " << fFileName;
113 // Check if the input file exist
114 FILE* inputFile = fopen(fFileName.Data(), "r");
115 if (!inputFile) {
116 LOG(error) << "Input file " << fFileName << " doesn't exist.";
117 return kFALSE;
118 }
119 fclose(inputFile);
120 fSource = new fles::TimesliceInputArchive(fFileName.Data());
121 if (!fSource) {
122 LOG(error) << "Could not open input file.";
123 return kFALSE;
124 }
125 } // if( fFileCounter < fInputFileList.GetSize() )
126 else {
127 LOG(info) << "End of files list reached: file counter is " << fFileCounter << " for " << fInputFileList.GetSize()
128 << " entries in the file list.";
129 return kFALSE;
130 } // else of if( fFileCounter < fInputFileList.GetSize() )
131
132 return kTRUE;
133}
134
135
ClassImp(CbmConverterManager)
std::string FormatDecPrintout(uint64_t ulVal, char cFill, uint uWidth)
std::string FormatMsHeaderPrintout(const fles::MicrosliceDescriptor &msDescriptor)
TList fInputFileList
List of input files.
fles::TimesliceSource * fSource