LCOV - code coverage report
Current view: top level - detchannelmaps/src - PD2HDChannelMapSPPluginBase.hpp (source / functions) Coverage Total Hit
Test: code.result Lines: 18.8 % 48 9
Test Date: 2026-10-11 15:05:20 Functions: 16.7 % 6 1

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : #include "PD2HDChannelMapSP.h"
       4              : #include "detchannelmaps/TPCChannelMap.hpp"
       5              : #include "logging/Logging.hpp" // NOLINT
       6              : 
       7              : namespace dunedaq {
       8              : namespace detchannelmaps {
       9              : 
      10              : class PD2HDChannelMapSPPluginBase : public TPCChannelMap
      11              : {
      12              : private:
      13              :   const uint m_det_id;
      14              :   std::unique_ptr<dune::PD2HDChannelMapSP> m_channel_map;
      15              : 
      16              : protected:
      17              :   std::function<uint(std::string)> m_elem_name_id_converter;
      18              : 
      19              : public:
      20              :   /**
      21              :    * @brief Construct a new PD2HDChannelMapSPPluginBase object
      22              :    *
      23              :    * @param det_id
      24              :    * @param channel_map_path
      25              :    */
      26            1 :   explicit PD2HDChannelMapSPPluginBase(uint det_id, const std::string& channel_map_path)
      27            1 :     : m_det_id(det_id)
      28              :   {
      29              : 
      30            1 :     const char* detchannelmaps_share_cstr = getenv("DETCHANNELMAPS_SHARE");
      31            1 :     if (!detchannelmaps_share_cstr) {
      32            0 :       throw std::runtime_error("Environment variable DETCHANNELMAPS_SHARE is not set");
      33              :     }
      34            1 :     std::string detchannelmaps_share(detchannelmaps_share_cstr);
      35            1 :     std::string channel_map_file = detchannelmaps_share + "/config/" + channel_map_path;
      36            1 :     m_channel_map.reset(new dune::PD2HDChannelMapSP());
      37            1 :     m_channel_map->ReadMapFromFile(channel_map_file);
      38            1 :   }
      39              : 
      40              :   PD2HDChannelMapSPPluginBase(const PD2HDChannelMapSPPluginBase&) =
      41              :     delete; ///< PD2HDChannelMapSPPluginBase is not copy-constructible
      42              :   PD2HDChannelMapSPPluginBase& operator=(const PD2HDChannelMapSPPluginBase&) =
      43              :     delete; ///< PD2HDChannelMapSPPluginBase is not copy-assignable
      44              :   PD2HDChannelMapSPPluginBase(PD2HDChannelMapSPPluginBase&&) =
      45              :     delete; ///< PD2HDChannelMapSPPluginBase is not move-constructible
      46              :   PD2HDChannelMapSPPluginBase& operator=(PD2HDChannelMapSPPluginBase&&) =
      47              :     delete; ///< PD2HDChannelMapSPPluginBase is not move-assignable
      48              : 
      49              :   /**
      50              :    * @brief Get the offline channel from detector crate slot stream chan object
      51              :    *
      52              :    * @param det
      53              :    * @param crate
      54              :    * @param slot
      55              :    * @param stream
      56              :    * @param channel
      57              :    *
      58              :    * @return offline channel identifier
      59              :    */
      60            0 :   uint get_offline_channel_from_det_crate_slot_stream_chan(uint det,
      61              :                                                            uint crate,
      62              :                                                            uint slot,
      63              :                                                            uint stream,
      64              :                                                            uint channel) final
      65              :   {
      66              : 
      67              :     // Must be a BDE channel
      68            0 :     if (det != m_det_id)
      69              :       return -1;
      70              : 
      71              :     // if stream number looks wrong (not 0,1,2,3 or 64,65,66,67)
      72            0 :     if ((stream & 0xbc))
      73              :       return -1;
      74              : 
      75            0 :     constexpr uint n_chan_per_stream = 64;
      76              : 
      77            0 :     uint link = (stream >> 6) & 1;
      78            0 :     uint stream_in_link = (stream & 0x3);
      79            0 :     uint wibframechan = n_chan_per_stream * stream_in_link + channel;
      80              : 
      81            0 :     auto chan_info = m_channel_map->GetChanInfoFromWIBElements(crate, slot, link, wibframechan);
      82              : 
      83            0 :     if (!chan_info.valid) {
      84              :       return -1;
      85              :     }
      86              : 
      87            0 :     return chan_info.offlchan;
      88            0 :   }
      89              : 
      90              :   /**
      91              :    * @brief Get the plane from offline channel object
      92              :    *
      93              :    * @param offchannel
      94              :    * @return plane id (0, 1 or 2)
      95              :    */
      96            0 :   uint get_plane_from_offline_channel(uint offchannel) final
      97              :   {
      98            0 :     auto chan_info = m_channel_map->GetChanInfoFromOfflChan(offchannel);
      99              : 
     100            0 :     if (!chan_info.valid) {
     101              :       return -1;
     102              :     }
     103              : 
     104            0 :     return chan_info.plane;
     105            0 :   };
     106              : 
     107              :   /**
     108              :    * @brief Get the element id from offline channel object
     109              :    *
     110              :    * @param offchannel
     111              :    * @return uint
     112              :    */
     113            0 :   uint get_element_id_from_offline_channel(uint offchannel) final
     114              :   {
     115            0 :     auto chan_info = m_channel_map->GetChanInfoFromOfflChan(offchannel);
     116              : 
     117            0 :     if (!chan_info.valid) {
     118              :       return -1;
     119              :     }
     120              : 
     121            0 :     return m_elem_name_id_converter(chan_info.APAName);
     122              : 
     123              :     // There is only one element
     124              :     return 0;
     125            0 :   }
     126              : 
     127              :   /**
     128              :    * @brief Get the tpc element name from offline channel object
     129              :    *
     130              :    * @param offchannel
     131              :    * @return std::string
     132              :    */
     133            0 :   std::string get_element_name_from_offline_channel(uint offchannel) final
     134              :   {
     135            0 :     auto chan_info = m_channel_map->GetChanInfoFromOfflChan(offchannel);
     136              : 
     137            0 :     if (!chan_info.valid) {
     138            0 :       return "";
     139              :     }
     140              : 
     141            0 :     return chan_info.APAName;
     142            0 :   }
     143              : 
     144            0 :   std::optional<TPCChannelMap::TPCChannelInfo> get_channel_info_from_offline_channel(uint offchannel) final
     145              :   {
     146            0 :     auto ci = m_channel_map->GetChanInfoFromOfflChan(offchannel);
     147              : 
     148            0 :     if (!ci.valid) {
     149            0 :       return std::nullopt;
     150              :     }
     151            0 :     constexpr uint n_chan_per_stream = 64;
     152            0 :     uint16_t slot_id = ci.wib - 1;
     153            0 :     uint16_t stream_id = ci.link * n_chan_per_stream + ci.wibframechan / n_chan_per_stream;
     154            0 :     uint16_t chan_id = ci.wibframechan % n_chan_per_stream;
     155              : 
     156            0 :     return TPCChannelMap::TPCChannelInfo{ m_det_id,  ci.crate, slot_id,
     157            0 :                                           stream_id, chan_id,  m_elem_name_id_converter(ci.APAName) };
     158            0 :   }
     159              : };
     160              : 
     161              : } // namespace detchannelmaps
     162              : } // namespace dunedaq
        

Generated by: LCOV version 2.0-1