LCOV - code coverage report
Current view: top level - src/config - config.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 5 80.0 %
Date: 2025-09-09 12:09:29 Functions: 0 1 0.0 %

          Line data    Source code
       1             : #ifndef FELIX_STAR_CONFIG_H_
       2             : #define FELIX_STAR_CONFIG_H_
       3             : 
       4             : #include <map>
       5             : #include <vector>
       6             : #include <string>
       7             : #include <iostream>
       8             : #include <iterator>
       9             : #include <sstream>
      10             : #include <algorithm>
      11             : 
      12             : #include <map>
      13             : #include "block.hpp"                    //for MAX_BUF_CHUNK_SIZE
      14             : #include "felix/felix_fid.h"
      15             : #include "felix/felix_ports.h"          //PORT macros
      16             : #include "felix/felix_client_util.hpp"  //ip-iface conversion
      17             : 
      18             : #include "docopt/docopt.h"
      19             : 
      20             : 
      21             : enum class EventLoopType {
      22             :     netio_next,
      23             :     netio3_native,
      24             :     netio3_asio,
      25             : };
      26             : 
      27             : struct NetworkConfig
      28             : {
      29             :     std::string ip{"127.0.0.1"};
      30             :     std::map<int, int> ports;
      31             :     bool daq_unbuffered{false};
      32             :     bool daq_tcp{false};
      33             :     unsigned netio_pages{256};
      34             :     uint32_t netio_pagesize{65536};
      35             :     uint32_t netio_watermark{64511};
      36             :     unsigned long netio_timeout{0};
      37             : 
      38             :     std::string dcs_ip{""};
      39             :     std::map<int, int> dcs_ports;
      40             :     bool dcs_tcp{false};
      41             :     bool dcs_unbuffered{true};
      42             :     unsigned dcs_netio_pages{128};
      43             :     uint32_t dcs_netio_pagesize{6144};
      44             :     uint32_t dcs_netio_watermark{6100};
      45             :     unsigned long dcs_netio_timeout{10000};
      46             : 
      47             :     std::map<int, int> ttc_ports;
      48             :     unsigned ttc_netio_pages{64};
      49             :     uint32_t ttc_netio_pagesize{1536};
      50             :     uint32_t ttc_netio_watermark{1280};
      51             :     unsigned long ttc_netio_timeout{1000};
      52             : 
      53             :     std::string bus_dir{""};
      54             :     std::string bus_groupname{"FELIX"};
      55             :     bool verbose_bus{false};
      56             : 
      57             :     EventLoopType evloop_type{EventLoopType::netio_next};
      58             : };
      59             : 
      60             : 
      61          27 : struct ResourceConfig
      62             : {
      63             :     std::vector<uint16_t> device;
      64             :     std::vector<uint16_t> cid;
      65             :     std::vector<int> dma_ids;
      66             :     uint8_t vid{1};
      67             :     uint16_t did{0};
      68             :     size_t cmem_buffersize{1024*1024*1024};
      69             :     bool free_previous_cmem{true};
      70             :     bool toflx{false};
      71             :     bool use_file{false};
      72             : };
      73             : 
      74             : 
      75          54 : struct MonitoringConfig
      76             : {
      77             :     std::string monitoring_fifo{""};
      78             :     int monitoring_period_ms{1000};
      79             : };
      80             : 
      81             : /**
      82             :  * Base configuration data structure used by felix-tohost and felix-toflx.
      83             :  */
      84             : class Config
      85             : {
      86             :     public:
      87             :         Config();
      88             :         virtual ~Config();
      89             :         virtual void parse(int argc, char **argv);
      90             :         virtual std::ostream& format(std::ostream& os) const;
      91             :         friend std::ostream& operator<<(std::ostream& os, const Config& c);
      92             :         int get_number_devices();
      93             :         uint16_t get_device_cid(unsigned int dev_no);
      94             :         int get_unique_dmaid(int dmaid, uint16_t device);
      95             :         int udmaid_to_deviceid(int udmaid);
      96             :         int udmaid_to_dmaid(int udmaid);
      97             : 
      98             :     protected:
      99           0 :         virtual std::string usage() { return "undefined"; } // = 0; FIXME, can only be added if we do not instantiate Config, needs to be reference (statistics, register)
     100             :         virtual std::string options();
     101             :         virtual std::string bugs();
     102             :         virtual void handle_cmd_line(std::map<std::string, docopt::value> args);
     103             : 
     104             :     public:
     105             :         bool verbose{false};
     106             :         std::string appname{""};
     107             :         ResourceConfig resource;
     108             :         MonitoringConfig stats;
     109             :         NetworkConfig network;
     110             : 
     111             :         // derived for easy class check
     112             :         bool use_file{false};
     113             :         bool vmem{false};
     114             : 
     115             :     private:
     116             :         [[nodiscard]] static std::string evloop_type_to_str(EventLoopType type);
     117             :         [[nodiscard]] static EventLoopType evloop_type_from_str(std::string_view type);
     118             : };
     119             : 
     120             : 
     121             : class ConfigFile : public virtual Config
     122             : {
     123             :     public:
     124             :         ConfigFile();
     125             :         virtual ~ConfigFile();
     126             :         virtual std::ostream& format(std::ostream& os) const override;
     127             :         friend std::ostream& operator<<(std::ostream& os, const ConfigFile& c);
     128             : 
     129             :     protected:
     130             :         virtual std::string options() override;
     131             :         virtual void handle_cmd_line(std::map<std::string, docopt::value> args) override;
     132             : 
     133             :     public:
     134             :         u_int    firmware{0};
     135             :         u_int    lock_mask{0};
     136             :         u_int    regmap{0};
     137             :         u_int    channels{24};
     138             :         u_int    block_size{1024};
     139             :         int      fromHostDataFormat{0};
     140             :         int      toHostDataFormat{0};
     141             :         bool     wide_mode{0};
     142             :         int      toflx_dmaid{-1};
     143             :         int      max_tlp_bytes{256};
     144             :         uint32_t status_leds{0};
     145             :         bool     fifo_as_file{false};
     146             :         std::string file{""};
     147             :         std::map<int, std::vector<uint16_t>> elinks;
     148             :         std::map<int, std::vector<uint16_t>> elinks_with_streams;
     149             : };
     150             : 
     151             : 
     152          22 : class ConfigToHost : public virtual Config {
     153             :     public:
     154             :         ConfigToHost();
     155             :         virtual std::ostream& format(std::ostream& os) const override;
     156             :         friend std::ostream& operator<<(std::ostream& os, const ConfigToHost& c);
     157             : 
     158             :     protected:
     159             :         virtual std::string usage() override;
     160             :         virtual std::string options() override;
     161             :         virtual void handle_cmd_line(std::map<std::string, docopt::value> args) override;
     162             : 
     163             :     public:
     164             :         unsigned int daq_threads{1};
     165             :         int dcs_rate_limit{-1};
     166             :         int l1id_check{-1};
     167             :         uint32_t max_dcs_chunk_size{UINT32_MAX};
     168             :         uint32_t max_daq_chunk_size{UINT32_MAX};
     169             :         int poll_time{10000};
     170             : };
     171             : 
     172             : 
     173           5 : class ConfigToFlx : public virtual Config {
     174             :     public:
     175             :         ConfigToFlx();
     176             :         virtual std::ostream& format(std::ostream& os) const override;
     177             :         friend std::ostream& operator<<(std::ostream& os, const ConfigToFlx& c);
     178             : 
     179             :     protected:
     180             :         virtual std::string usage() override;
     181             :         virtual std::string options() override;
     182             :         virtual void handle_cmd_line(std::map<std::string, docopt::value> args) override;
     183             : 
     184             :     public:
     185             :         bool unbuffered{false};
     186             :         bool trickle{false};
     187             : };
     188             : 
     189             : 
     190             : class ConfigFileToHost : public ConfigToHost, public ConfigFile {
     191             :     public:
     192             :         ConfigFileToHost();
     193             :         virtual ~ConfigFileToHost();
     194             :         virtual std::ostream& format(std::ostream& os) const override;
     195             :         friend std::ostream& operator<<(std::ostream& os, const ConfigFileToHost& c);
     196             : 
     197             :     protected:
     198             :         virtual std::string usage() override;
     199             :         virtual std::string options() override;
     200             :         virtual void handle_cmd_line(std::map<std::string, docopt::value> args) override;
     201             : 
     202             :     public:
     203             :         // alphabetical
     204             :         unsigned block_rate{0};
     205             :         bool full_mode{false};
     206             :         bool repeat{true};
     207             : };
     208             : 
     209             : 
     210             : class ConfigToFlxToFile : public ConfigToFlx, public ConfigFile {
     211             :     public:
     212             :         ConfigToFlxToFile();
     213             :         virtual ~ConfigToFlxToFile();
     214             :         virtual std::ostream& format(std::ostream& os) const override;
     215             :         friend std::ostream& operator<<(std::ostream& os, const ConfigToFlxToFile& c);
     216             : 
     217             :     protected:
     218             :         virtual std::string usage() override;
     219             :         virtual std::string options() override;
     220             :         virtual void handle_cmd_line(std::map<std::string, docopt::value> args) override;
     221             : };
     222             : 
     223             : #endif /* FELIX_STAR_CONFIG_H_ */

Generated by: LCOV version 1.0