Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-20 01:53:39

0001 #include "monitor_file_utilities.h"
0002 #include "FWCore/Utilities/interface/OStreamColumn.h"
0003 
0004 #include <vector>
0005 #include <cassert>
0006 #include <algorithm>
0007 
0008 namespace {
0009   std::string const space{"  "};
0010 }
0011 
0012 namespace edm::moduleAlloc::monitor_file_utilities {
0013   void moduleIdToLabel(std::ostream& oStream,
0014                        std::vector<std::string> const& iModuleLabels,
0015                        char moduleIdSymbol,
0016                        std::string const& iIDHeader,
0017                        std::string const& iLabelHeader) {
0018     std::size_t const width{std::to_string(iModuleLabels.size()).size()};
0019     OStreamColumn col0{iIDHeader, width};
0020     std::string const& lastCol = iLabelHeader;
0021 
0022     oStream << "\n#  " << col0 << space << lastCol << '\n';
0023     oStream << "#  " << std::string(col0.width() + space.size() + lastCol.size(), '-') << '\n';
0024 
0025     for (std::size_t i{}; i < iModuleLabels.size(); ++i) {
0026       auto const& label = iModuleLabels[i];
0027       if (not label.empty()) {
0028         oStream << '#' << moduleIdSymbol << ' ' << std::setw(width) << std::left << col0(i) << space << std::left
0029                 << label << '\n';
0030       }
0031     }
0032     oStream << '\n';
0033   }
0034 
0035   void moduleIdToLabelAndType(std::ostream& oStream,
0036                               std::vector<std::string> const& iModuleLabels,
0037                               std::vector<std::string> const& iModuleTypes,
0038                               char moduleIdSymbol,
0039                               std::string const& iIDHeader,
0040                               std::string const& iLabelHeader,
0041                               std::string const& iTypeHeader) {
0042     assert(iModuleLabels.size() == iModuleTypes.size());
0043     std::size_t const width{std::to_string(iModuleLabels.size()).size()};
0044     OStreamColumn col0{iIDHeader, width};
0045     auto itMax = std::max_element(iModuleLabels.begin(), iModuleLabels.end(), [](auto const& iL, auto const& iR) {
0046       return iL.size() < iR.size();
0047     });
0048     OStreamColumn labelCol{iLabelHeader, itMax->size()};
0049     std::string const& typeCol = iTypeHeader;
0050 
0051     oStream << "\n#  " << col0 << space << labelCol << space << typeCol << '\n';
0052     oStream << "#  " << std::string(col0.width() + space.size() + labelCol.width() + space.size() + typeCol.size(), '-')
0053             << '\n';
0054 
0055     for (std::size_t i{}; i < iModuleLabels.size(); ++i) {
0056       auto const& label = iModuleLabels[i];
0057       auto const& type = iModuleTypes[i];
0058       if (not label.empty()) {
0059         oStream << '#' << moduleIdSymbol << ' ' << std::setw(width) << std::left << col0(i) << space
0060                 << std::setw(itMax->size()) << std::left << labelCol(label) << space << std::left << type << '\n';
0061       }
0062     }
0063     oStream << '\n';
0064   }
0065 }  // namespace edm::moduleAlloc::monitor_file_utilities