CbmRoot
Loading...
Searching...
No Matches
CbmFormatTsPrintout.cxx
Go to the documentation of this file.
1/* Copyright (C) 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
6
9
10#include <ios>
11
12std::string FormatTsHeaderPrintout(const fles::Timeslice& ts)
13{
14 std::stringstream ss;
15
16 uint64_t min_num_microslices = UINT64_MAX;
17 uint64_t max_num_microslices = 0;
18 uint64_t total_num_microslices = 0;
19 uint64_t min_microslice_size = UINT64_MAX;
20 uint64_t max_microslice_size = 0;
21 uint64_t total_microslice_size = 0;
22
23 size_t nbComps = ts.num_components();
24 size_t nbMicroslicesCore = ts.num_core_microslices();
25 for (uint64_t compIdx = 0; compIdx < nbComps; ++compIdx) {
26 uint64_t num_microslices = ts.num_microslices(compIdx);
27 min_num_microslices = std::min(min_num_microslices, num_microslices);
28 max_num_microslices = std::max(max_num_microslices, num_microslices);
29 total_num_microslices += num_microslices;
30 for (uint64_t msIdx = 0; msIdx < num_microslices; ++msIdx) {
31 uint64_t size = ts.descriptor(compIdx, msIdx).size;
32 total_microslice_size += size;
33 min_microslice_size = std::min(min_microslice_size, size);
34 max_microslice_size = std::max(max_microslice_size, size);
35 } // for( uint64_t msIdx = 0; msIdx < num_microslices; ++msIdx )
36 } // for( uint64_t compIdx = 0; compIdx < nbComps; ++compIdx )
37
38 uint64_t min_overlap = min_num_microslices - nbMicroslicesCore;
39 uint64_t max_overlap = max_num_microslices - nbMicroslicesCore;
40
41 ss << "Timeslice " << std::setw(6) << ts.index() << " with " << std::setw(3) << nbComps << " components "
42 << " x " << std::setw(6) << nbMicroslicesCore << " core microslices";
43 if (0 != nbComps) {
44 ss << " (+";
45 if (min_overlap != max_overlap) {
46 ss << std::setw(3) << min_overlap << std::setw(3) << ".." << max_overlap;
47 } // if( min_overlap != max_overlap )
48 else {
49 ss << std::setw(3) << min_overlap;
50 } // else of if( min_overlap != max_overlap )
51 ss << " overlap) = " << std::setw(9) << total_num_microslices << "\n";
52 ss
53 << "\tmicroslice size min/avg/max: " << std::setw(6) << min_microslice_size << " / " << std::fixed
54 << std::setprecision(0) << std::setw(6)
55 << (static_cast<double>(total_microslice_size) / total_num_microslices)
56 // << std::defaultfloat // commented out as not included in GCC 4.9.2 => restore defaults, probably not needed
57 << std::setprecision(6) // restore defaults, probably not needed
58 << " / " << std::setw(6) << max_microslice_size << " bytes"
59 << "\n";
60 } // if( 0 != nbComps )
61 else {
62 ss << " = " << std::setw(9) << total_num_microslices << "\n";
63 }
64
65 return ss.str();
66}
67
68std::string FormatTsContentPrintout(const fles::Timeslice& ts, std::underlying_type_t<fles::Subsystem> selSysId,
69 size_t nbMsPerComp)
70{
71 std::stringstream ss;
72
73 size_t nbComps = ts.num_components();
74 if (0 != nbComps) {
75 size_t nbMicroslicesCore = ts.num_core_microslices();
76 size_t nbMicroslicesOverlap = ts.num_microslices(0) - ts.num_core_microslices();
77 size_t nbCoreMsToLoop = nbMicroslicesCore;
78 size_t nbOverMsToLoop = nbMicroslicesOverlap;
79 if (nbMsPerComp < nbMicroslicesCore) {
80 nbCoreMsToLoop = nbMsPerComp;
81 nbOverMsToLoop = 0;
82 } // if (nbMsPerComp < nbMicroslicesCore)
83 else if (nbMsPerComp < nbMicroslicesCore + nbMicroslicesOverlap) {
84 nbOverMsToLoop = nbMicroslicesOverlap - (nbMsPerComp - nbMicroslicesCore);
85 } // else if (nbMsPerComp < nbMicroslicesCore + nbMicroslicesOverlap)
86
87 if (0 < nbMicroslicesCore) {
88 for (size_t compIdx = 0; compIdx < nbComps; ++compIdx) {
89 if (0 < nbMicroslicesCore && 0x00 != selSysId && ts.descriptor(compIdx, 0).sys_id != selSysId) {
90 // FIXME: define "reserved/undefined" system ID somewhere (best in flesnet microslice descriptor header)
91 continue;
92 } // if (0 < nbMicroslicesCore && 0x00 != selSysId && ts.descriptor(compIdx, 0).sys_id != selSysId)
93 // FIXME: Need safe accessor with range check for the cast, to be done in flesnet side
94 ss << "Component " << std::setw(3) << compIdx << ", Subsystem "
95 << fles::to_string(static_cast<fles::Subsystem>(ts.descriptor(compIdx, 0).sys_id)) << "\n";
96 if (0 < nbCoreMsToLoop) {
97 ss << "Core Microslices for component " << std::setw(3) << compIdx << " ("
98 << fles::to_string(static_cast<fles::Subsystem>(ts.descriptor(compIdx, 0).sys_id)) << ")"
99 << "\n";
100 for (size_t msIdx = 0; msIdx < nbCoreMsToLoop; ++msIdx) {
101 ss << ts.descriptor(compIdx, msIdx) << "\n";
102 ss << FormatMsBufferPrintout(ts, compIdx, msIdx);
103 ss << "----------------------------------------------"
104 << "\n";
105 } // for( size_t msIdx = 0; msIdx < nbOverMsToLoop; ++msIdx )
106 } // if (0 < nbCoreMsToLoop )
107 if (0 < nbOverMsToLoop) {
108 ss << "Overlap Microslices for component " << std::setw(3) << compIdx << " ("
109 << fles::to_string(static_cast<fles::Subsystem>(ts.descriptor(compIdx, 0).sys_id)) << ")"
110 << "\n";
111 for (size_t msIdx = 0; msIdx < nbOverMsToLoop; ++msIdx) {
112 ss << ts.descriptor(compIdx, msIdx + nbMicroslicesCore) << "\n";
113 ss << FormatMsBufferPrintout(ts, compIdx, msIdx + nbMicroslicesCore);
114 ss << "----------------------------------------------"
115 << "\n";
116 } // for( size_t msIdx = 0; msIdx < nbOverMsToLoop; ++msIdx )
117 } // if (0 < nbOverMsToLoop )
118 ss << "++++++++++++++++++++++++++++++++++++++++++++++"
119 << "\n";
120 } // for( size_t comp = 0; comp < nbComps; ++comp )
121 } // if (0 < nbMicroslicesCore) )
122 } // if( 0 != nbComps )
123 ss << "**********************************************"
124 << "\n";
125
126 return ss.str();
127}
128
129std::string FormatTsPrintout(const fles::Timeslice& ts, std::underlying_type_t<fles::Subsystem> selSysId,
130 size_t nbMsPerComp)
131{
132 std::stringstream ss;
133 ss << FormatTsHeaderPrintout(ts);
134 ss << FormatTsContentPrintout(ts, selSysId, nbMsPerComp);
135 return ss.str();
136}
137
138std::ostream& operator<<(std::ostream& os, const fles::Timeslice& ts)
139{
140 os << FormatTsHeaderPrintout(ts);
141 os << FormatTsContentPrintout(ts);
142 return os;
143}
std::string FormatMsBufferPrintout(const fles::Timeslice &ts, const size_t uMsCompIdx, const size_t uMsIdx, const uint32_t uBlocksPerLine)
std::string FormatTsHeaderPrintout(const fles::Timeslice &ts)
std::string FormatTsPrintout(const fles::Timeslice &ts, std::underlying_type_t< fles::Subsystem > selSysId, size_t nbMsPerComp)
std::string FormatTsContentPrintout(const fles::Timeslice &ts, std::underlying_type_t< fles::Subsystem > selSysId, size_t nbMsPerComp)
std::ostream & operator<<(std::ostream &os, const fles::Timeslice &ts)
static constexpr size_t size()
Definition KfSimdPseudo.h:2