|
| 1 | +////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | +// Class: SBND::CRTChannelMapService |
| 3 | +// Module type: service |
| 4 | +// File: SBND::CRTChannelMapService_service.cc |
| 5 | +// Author: Henry Lay, May 2024. |
| 6 | +// |
| 7 | +// Implementation of hardware-offline channel mapping reading from a file. |
| 8 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 9 | + |
| 10 | +#include <iostream> |
| 11 | +#include <fstream> |
| 12 | +#include <sstream> |
| 13 | +#include <stdlib.h> |
| 14 | + |
| 15 | +#include "CRTChannelMapService.h" |
| 16 | +#include "messagefacility/MessageLogger/MessageLogger.h" |
| 17 | + |
| 18 | +SBND::CRTChannelMapService::CRTChannelMapService(fhicl::ParameterSet const& pset) |
| 19 | +{ |
| 20 | + const std::string channelMapFile = pset.get<std::string>("FileName"); |
| 21 | + |
| 22 | + std::string fullname; |
| 23 | + cet::search_path sp("FW_SEARCH_PATH"); |
| 24 | + sp.find_file(channelMapFile, fullname); |
| 25 | + |
| 26 | + if(fullname.empty()) |
| 27 | + { |
| 28 | + std::cout << "SBND::CRTChannelMapService Input file " << channelMapFile << " not found" << std::endl; |
| 29 | + throw cet::exception("File not found"); |
| 30 | + } |
| 31 | + |
| 32 | + std::cout << "SBND CRT Channel Map: Building map from file " << channelMapFile << std::endl; |
| 33 | + std::ifstream inFile(fullname, std::ios::in); |
| 34 | + std::string line; |
| 35 | + |
| 36 | + while(std::getline(inFile,line)) |
| 37 | + { |
| 38 | + std::stringstream linestream(line); |
| 39 | + |
| 40 | + SBND::CRTChannelMapService::ModuleInfo_t m; |
| 41 | + linestream |
| 42 | + >> m.offline_module_id |
| 43 | + >> m.feb_mac5 |
| 44 | + >> m.channel_order_swapped; |
| 45 | + |
| 46 | + m.valid = true; |
| 47 | + |
| 48 | + fModuleInfoFromOfflineID[m.offline_module_id] = m; |
| 49 | + fModuleInfoFromFEBMAC5[m.feb_mac5] = m; |
| 50 | + } |
| 51 | + |
| 52 | + inFile.close(); |
| 53 | +} |
| 54 | + |
| 55 | +SBND::CRTChannelMapService::CRTChannelMapService(fhicl::ParameterSet const& pset, art::ActivityRegistry&) |
| 56 | + : SBND::CRTChannelMapService(pset) |
| 57 | +{ |
| 58 | +} |
| 59 | + |
| 60 | +SBND::CRTChannelMapService::ModuleInfo_t SBND::CRTChannelMapService::GetModuleInfoFromFEBMAC5(unsigned int feb_mac5) const |
| 61 | +{ |
| 62 | + SBND::CRTChannelMapService::ModuleInfo_t bad; |
| 63 | + bad.valid = false; |
| 64 | + |
| 65 | + auto moduleIter = fModuleInfoFromFEBMAC5.find(feb_mac5); |
| 66 | + |
| 67 | + if(moduleIter == fModuleInfoFromFEBMAC5.end()) |
| 68 | + { |
| 69 | + mf::LogInfo("SBND CRT Channel Map") << "Asked for FEB with MAC5: " << feb_mac5 << '\n' |
| 70 | + << "This FEB does not appear in the channel map." << std::endl; |
| 71 | + |
| 72 | + return bad; |
| 73 | + } |
| 74 | + |
| 75 | + return moduleIter->second; |
| 76 | +} |
| 77 | + |
| 78 | +SBND::CRTChannelMapService::ModuleInfo_t SBND::CRTChannelMapService::GetModuleInfoFromOfflineID(unsigned int offline_module_id) const |
| 79 | +{ |
| 80 | + SBND::CRTChannelMapService::ModuleInfo_t bad; |
| 81 | + bad.valid = false; |
| 82 | + |
| 83 | + auto moduleIter = fModuleInfoFromOfflineID.find(offline_module_id); |
| 84 | + |
| 85 | + if(moduleIter == fModuleInfoFromOfflineID.end()) |
| 86 | + { |
| 87 | + mf::LogInfo("SBND CRT Channel Map") << "Asked for module with offline ID: " << offline_module_id << '\n' |
| 88 | + << "This module does not appear in the channel map." << std::endl; |
| 89 | + |
| 90 | + return bad; |
| 91 | + } |
| 92 | + |
| 93 | + return moduleIter->second; |
| 94 | +} |
| 95 | + |
| 96 | +DEFINE_ART_SERVICE(SBND::CRTChannelMapService) |
0 commit comments