Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:29:46

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