LCOV - code coverage report
Current view: top level - detchannelmaps/src - TPCChannelMapSP.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 70 0
Test Date: 2025-12-21 13:07:08 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            0 :   fSubstituteCrate = 1;
      19            0 :   fNChans = 0;
      20            0 : }
      21              : 
      22            0 : void dune::TPCChannelMapSP::ReadMapFromFile(std::string& fullname)
      23              : {
      24            0 :   fNChans = 0;
      25              :   
      26            0 :   std::ifstream inFile(fullname, std::ios::in);
      27            0 :   std::string line;
      28              : 
      29            0 :   while (std::getline(inFile, line)) {
      30            0 :     std::stringstream linestream(line);
      31              : 
      32            0 :     TPCChanInfo_t chanInfo;
      33            0 :     linestream >>
      34            0 :       chanInfo.offlchan >>
      35            0 :       chanInfo.detid >>
      36            0 :       chanInfo.detelement >>
      37            0 :       chanInfo.crate >>
      38            0 :       chanInfo.slot >>
      39            0 :       chanInfo.stream >>
      40            0 :       chanInfo.streamchan >>
      41            0 :       chanInfo.plane >>
      42            0 :       chanInfo.chan_in_plane >>
      43            0 :       chanInfo.femb >>
      44            0 :       chanInfo.asic >> 
      45            0 :       chanInfo.asicchan;
      46              : 
      47            0 :     chanInfo.valid = true;
      48            0 :     ++fNChans;
      49              : 
      50              :     // fill maps.
      51              : 
      52            0 :     check_offline_channel(chanInfo.offlchan);
      53              : 
      54            0 :     auto hashval = make_hash(chanInfo.detid,chanInfo.crate,chanInfo.slot,chanInfo.stream,chanInfo.streamchan);
      55            0 :     if ( DetToChanInfo.find(hashval) != DetToChanInfo.end() ){
      56            0 :       std::cout << "TPCChannelMapSP: duplicate electronics channel found.  detid, crate, slot, stream, streamchan: " <<
      57            0 :         chanInfo.detid << " " <<
      58            0 :         chanInfo.crate << " " <<
      59            0 :         chanInfo.slot << " " <<
      60            0 :         chanInfo.stream << " " <<
      61            0 :         chanInfo.streamchan << std::endl;
      62            0 :       throw std::range_error("Duplicate Electronics ID");
      63              :     }
      64            0 :     DetToChanInfo[hashval] = chanInfo;
      65              : 
      66            0 :     if ( OfflToChanInfo.find(chanInfo.offlchan) != OfflToChanInfo.end() ) {
      67            0 :       std::cout << "TPCChannelMapSP: duplicate offline channel found: " <<
      68            0 :         chanInfo.offlchan << std::endl;
      69            0 :       throw std::range_error("Duplicate Offline TPC Channel ID");      
      70              :     }
      71            0 :     OfflToChanInfo[chanInfo.offlchan] = chanInfo;
      72            0 :   }
      73            0 :   inFile.close();
      74            0 : }
      75              : 
      76            0 : dune::TPCChannelMapSP::TPCChanInfo_t dune::TPCChannelMapSP::GetChanInfoFromElectronicsIDs(
      77              :                                                                                           unsigned int detid,
      78              :                                                                                           unsigned int crate,
      79              :                                                                                           unsigned int slot,
      80              :                                                                                           unsigned int stream,
      81              :                                                                                           unsigned int streamchan) const
      82              : {
      83            0 :   size_t h = make_hash(detid,crate,slot,stream,streamchan);
      84            0 :   auto ret = DetToChanInfo.find(h); 
      85            0 :   if (ret == DetToChanInfo.end())
      86              :     {
      87            0 :       h = make_hash(detid,fSubstituteCrate,slot,stream,streamchan);
      88            0 :       ret = DetToChanInfo.find(h);
      89            0 :       if (ret == DetToChanInfo.end())
      90              :         {
      91            0 :           TPCChanInfo_t badInfo = {};
      92            0 :           badInfo.valid = false;
      93            0 :           return badInfo;
      94              :         }
      95              :     }
      96            0 :   return ret->second;
      97              : }
      98              : 
      99            0 : dune::TPCChannelMapSP::TPCChanInfo_t dune::TPCChannelMapSP::GetChanInfoFromOfflChan(
     100              :                                                                                     unsigned int offlineChannel) const
     101              : {
     102            0 :   auto ci = OfflToChanInfo.find(offlineChannel);
     103            0 :   if (ci == OfflToChanInfo.end()) {
     104            0 :     TPCChanInfo_t badInfo = {};
     105            0 :     badInfo.valid = false;
     106            0 :     return badInfo;
     107              :   }
     108            0 :   return ci->second;
     109              : }
     110              : 
     111            0 : size_t dune::TPCChannelMapSP::make_hash( unsigned int detid,   //6 bits
     112              :                   unsigned int crate,   //10 bits
     113              :                   unsigned int slot,    //4 bits
     114              :                   unsigned int stream,  //8 bits
     115              :                   unsigned int streamch //12 bits
     116              :                                          ) const
     117              : {
     118            0 :   size_t hashval = (((size_t)detid & 0x3f)<<34);
     119            0 :   hashval ^=((crate & 0x3ff)<<24);
     120            0 :   hashval ^=((slot & 0xf)<<20);
     121            0 :   hashval ^=((stream & 0xff)<<12);
     122            0 :   hashval ^=(streamch & 0xfff);
     123            0 :   return hashval;
     124              : }
        

Generated by: LCOV version 2.0-1