LCOV - code coverage report
Current view: top level - detchannelmaps/src - TPCChannelMapSP.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 56 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 5 0

            Line data    Source code
       1              : ///////////////////////////////////////////////////////////////////////////////////////////////////
       2              : // Class:       TPCChannelMapSP
       3              : // Module type: standalone algorithm
       4              : // File:        TPCChannelMapSP.cxx
       5              : // Author:      Tom Junk, Jan 2025
       6              : //
       7              : // Implementation of hardware-offline channel mapping reading from a file.
       8              : ///////////////////////////////////////////////////////////////////////////////////////////////////
       9              : 
      10              : #include "TPCChannelMapSP.h"
      11              : 
      12              : #include <fstream>
      13              : #include <iostream>
      14              : #include <sstream>
      15              : #include <stdexcept>
      16              : 
      17            0 : dune::TPCChannelMapSP::TPCChannelMapSP()
      18              : {
      19            0 :   fSubstituteCrate = 1;
      20            0 :   fNChans = 0;
      21            0 : }
      22              : 
      23              : void
      24            0 : dune::TPCChannelMapSP::ReadMapFromFile(std::string& fullname)
      25              : {
      26            0 :   fNChans = 0;
      27              : 
      28            0 :   std::ifstream inFile(fullname, std::ios::in);
      29            0 :   std::string line;
      30              : 
      31            0 :   while (std::getline(inFile, line)) {
      32            0 :     std::stringstream linestream(line);
      33              : 
      34            0 :     TPCChanInfo_t chanInfo;
      35            0 :     linestream >> chanInfo.offlchan >> chanInfo.detid >> chanInfo.detelement >> chanInfo.crate >> chanInfo.slot >>
      36            0 :       chanInfo.stream >> chanInfo.streamchan >> chanInfo.plane >> chanInfo.chan_in_plane >> chanInfo.femb >>
      37            0 :       chanInfo.asic >> chanInfo.asicchan;
      38              : 
      39            0 :     chanInfo.valid = true;
      40            0 :     ++fNChans;
      41              : 
      42              :     // fill maps.
      43              : 
      44            0 :     check_offline_channel(chanInfo.offlchan);
      45              : 
      46            0 :     auto hashval = make_hash(chanInfo.detid, chanInfo.crate, chanInfo.slot, chanInfo.stream, chanInfo.streamchan);
      47            0 :     if (DetToChanInfo.find(hashval) != DetToChanInfo.end()) {
      48            0 :       std::cout << "TPCChannelMapSP: duplicate electronics channel found.  detid, crate, slot, stream, streamchan: "
      49            0 :                 << chanInfo.detid << " " << chanInfo.crate << " " << chanInfo.slot << " " << chanInfo.stream << " "
      50            0 :                 << chanInfo.streamchan << std::endl;
      51            0 :       throw std::range_error("Duplicate Electronics ID");
      52              :     }
      53            0 :     DetToChanInfo[hashval] = chanInfo;
      54              : 
      55            0 :     if (OfflToChanInfo.find(chanInfo.offlchan) != OfflToChanInfo.end()) {
      56            0 :       std::cout << "TPCChannelMapSP: duplicate offline channel found: " << chanInfo.offlchan << std::endl;
      57            0 :       throw std::range_error("Duplicate Offline TPC Channel ID");
      58              :     }
      59            0 :     OfflToChanInfo[chanInfo.offlchan] = chanInfo;
      60            0 :   }
      61            0 :   inFile.close();
      62            0 : }
      63              : 
      64              : dune::TPCChannelMapSP::TPCChanInfo_t
      65            0 : dune::TPCChannelMapSP::GetChanInfoFromElectronicsIDs(unsigned int detid,
      66              :                                                      unsigned int crate,
      67              :                                                      unsigned int slot,
      68              :                                                      unsigned int stream,
      69              :                                                      unsigned int streamchan) const
      70              : {
      71            0 :   size_t h = make_hash(detid, crate, slot, stream, streamchan);
      72            0 :   auto ret = DetToChanInfo.find(h);
      73            0 :   if (ret == DetToChanInfo.end()) {
      74            0 :     h = make_hash(detid, fSubstituteCrate, slot, stream, streamchan);
      75            0 :     ret = DetToChanInfo.find(h);
      76            0 :     if (ret == DetToChanInfo.end()) {
      77            0 :       TPCChanInfo_t badInfo = {};
      78            0 :       badInfo.valid = false;
      79            0 :       return badInfo;
      80              :     }
      81              :   }
      82            0 :   return ret->second;
      83              : }
      84              : 
      85              : dune::TPCChannelMapSP::TPCChanInfo_t
      86            0 : dune::TPCChannelMapSP::GetChanInfoFromOfflChan(unsigned int offlineChannel) const
      87              : {
      88            0 :   auto ci = OfflToChanInfo.find(offlineChannel);
      89            0 :   if (ci == OfflToChanInfo.end()) {
      90            0 :     TPCChanInfo_t badInfo = {};
      91            0 :     badInfo.valid = false;
      92            0 :     return badInfo;
      93              :   }
      94            0 :   return ci->second;
      95              : }
      96              : 
      97              : size_t
      98            0 : dune::TPCChannelMapSP::make_hash(unsigned int detid,   // 6 bits
      99              :                                  unsigned int crate,   // 10 bits
     100              :                                  unsigned int slot,    // 4 bits
     101              :                                  unsigned int stream,  // 8 bits
     102              :                                  unsigned int streamch // 12 bits
     103              : ) const
     104              : {
     105            0 :   size_t hashval = (((size_t)detid & 0x3f) << 34);
     106            0 :   hashval ^= ((crate & 0x3ff) << 24);
     107            0 :   hashval ^= ((slot & 0xf) << 20);
     108            0 :   hashval ^= ((stream & 0xff) << 12);
     109            0 :   hashval ^= (streamch & 0xfff);
     110            0 :   return hashval;
     111              : }
        

Generated by: LCOV version 2.0-1