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