Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:23

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "SimG4Core/Geometry/interface/SensitiveDetectorCatalog.h"
0003 
0004 #include <iostream>
0005 
0006 void SensitiveDetectorCatalog::insert(const std::string &cN, const std::string &rN, const std::string &lvN) {
0007   theClassNameMap[cN].insert(rN);
0008   theROUNameMap[rN].insert(lvN);
0009 #ifdef EDM_ML_DEBUG
0010   edm::LogVerbatim("SensitiveDetector") << "SenstiveDetectorCatalog: insert (" << cN << "," << rN << "," << lvN << ")\n"
0011                                         << "                         has     " << readoutNames().size() << " ROUs "
0012                                         << readoutNames().front() << "\n"
0013                                         << "                         has     " << classNames().size() << " classes "
0014                                         << classNames().front();
0015 #endif
0016 }
0017 
0018 std::vector<std::string_view> SensitiveDetectorCatalog::readoutNames() const {
0019   std::vector<std::string_view> temp;
0020   for (auto const &it : theROUNameMap)
0021     temp.emplace_back(it.first);
0022   return temp;
0023 }
0024 
0025 const std::vector<std::string_view> SensitiveDetectorCatalog::readoutNames(const std::string &className) const {
0026   return std::vector<std::string_view>(theClassNameMap.at(className).begin(), theClassNameMap.at(className).end());
0027 }
0028 
0029 const std::vector<std::string_view> SensitiveDetectorCatalog::logicalNames(const std::string &readoutName) const {
0030   return std::vector<std::string_view>(theROUNameMap.at(readoutName).begin(), theROUNameMap.at(readoutName).end());
0031 }
0032 
0033 std::vector<std::string_view> SensitiveDetectorCatalog::logicalNamesFromClassName(const std::string &className) const {
0034   std::vector<std::string_view> temp;
0035   const std::vector<std::string_view> rous(theClassNameMap.at(className).begin(), theClassNameMap.at(className).end());
0036   temp.reserve(rous.size());
0037   for (auto const &it : rous)
0038     temp.emplace_back(it);
0039   return temp;
0040 }
0041 
0042 std::string_view SensitiveDetectorCatalog::className(const std::string &readoutName) const {
0043   for (auto const &it : theClassNameMap) {
0044     std::vector<std::string_view> temp(it.second.begin(), it.second.end());
0045     for (auto const &it2 : temp) {
0046       if (it2 == readoutName)
0047         return it.first;
0048     }
0049   }
0050   return "NotFound";
0051 }
0052 
0053 std::vector<std::string_view> SensitiveDetectorCatalog::classNames() const {
0054   std::vector<std::string_view> temp;
0055   for (auto const &it : theClassNameMap)
0056     temp.emplace_back(it.first);
0057   return temp;
0058 }
0059 
0060 void SensitiveDetectorCatalog::printMe() const {
0061   edm::LogVerbatim("SensitiveDetector") << "Class names map size is: " << theClassNameMap.size() << "\n";
0062   edm::LogVerbatim("SensitiveDetector").log([&](auto &log) {
0063     int i(0);
0064     for (const auto &cn : theClassNameMap) {
0065       log << "#" << ++i << ": " << cn.first << " has " << cn.second.size() << " class names:\n";
0066       for (const auto &cnv : cn.second)
0067         log << cnv << ", ";
0068       log << "\n";
0069     }
0070     log << "\n";
0071   });
0072   edm::LogVerbatim("SensitiveDetector") << "\nROU names map: " << theROUNameMap.size() << "\n";
0073   edm::LogVerbatim("SensitiveDetector").log([&](auto &log) {
0074     int i(0);
0075     for (const auto &rn : theROUNameMap) {
0076       log << "#" << ++i << ": " << rn.first << " has " << rn.second.size() << " ROU names:\n";
0077       for (const auto &rnv : rn.second)
0078         log << rnv << "\n ";
0079       log << "\n";
0080     }
0081     log << "\n";
0082   });
0083 
0084   edm::LogVerbatim("SensitiveDetector") << "\n========== Here are the accessors =================\n";
0085   edm::LogVerbatim("SensitiveDetector").log([&](auto &log) {
0086     for (auto c : classNames()) {
0087       log << "ClassName:" << c << "\n";
0088       for (auto r : readoutNames({c.data(), c.size()})) {
0089         log << "       RedoutName:" << r << "\n";
0090         for (auto l : logicalNames({r.data(), r.size()})) {
0091           log << "              LogicalName:" << l << "\n";
0092         }
0093       }
0094     }
0095   });
0096 }