Line data Source code
1 : #include "config.hpp" 2 : #include <cstdint> 3 : 4 : 5 22 : ConfigToHost::ConfigToHost() : Config() { 6 22 : use_file = false; 7 22 : resource.toflx = false; 8 22 : } 9 : 10 : //ConfigToHost::~ConfigToHost() {} 11 : 12 0 : std::ostream& ConfigToHost::format(std::ostream& os) const { 13 0 : os << "ConfigToHost" << std::endl; 14 0 : os << "cmem_buffersize: " << resource.cmem_buffersize << std::endl; 15 0 : os << "netio_watermark: " << network.netio_watermark << std::endl; 16 0 : os << "daq_unbuffered: " << network.daq_unbuffered << std::endl; 17 0 : os << "dcs_ip: " << network.dcs_ip << std::endl; 18 0 : os << "dcs_tcp: " << network.dcs_tcp << std::endl; 19 0 : os << "dcs_netio_pages: " << network.dcs_netio_pages << std::endl; 20 0 : os << "dcs_netio_pagesize: " << network.dcs_netio_pagesize << std::endl; 21 0 : os << "max_dcs_chunk_size: " << max_dcs_chunk_size << std::endl; 22 0 : os << "dcs_netio_timeout: " << network.dcs_netio_timeout << std::endl; 23 0 : os << "dcs_unbuffered: " << network.dcs_unbuffered << std::endl; 24 0 : os << "dcs_netio_watermark: " << network.dcs_netio_watermark << std::endl; 25 0 : os << "dmaid: "; 26 0 : std::copy(resource.dma_ids.begin(), resource.dma_ids.end(), std::ostream_iterator<int>(os, " ")); 27 0 : os << std::endl; 28 0 : os << "l1id_check: " << l1id_check << std::endl; 29 0 : os << "max_daq_chunk_size: " << max_daq_chunk_size << std::endl; 30 0 : os << "poll_time (us): "<< poll_time << std::endl; 31 0 : os << "ttc_netio_pages: " << network.netio_pages << std::endl; 32 0 : os << "ttc_netio_pagesize: " << network.ttc_netio_pagesize << std::endl; 33 0 : os << "ttc_netio_timeout: " << network.ttc_netio_timeout << std::endl; 34 0 : os << "ttc_netio_watermark: " << network.ttc_netio_watermark << std::endl; 35 0 : os << std::endl; 36 0 : return Config::format(os); 37 : } 38 : 39 0 : std::ostream& operator<<(std::ostream& os, const ConfigToHost& c) { 40 0 : return c.format(os); 41 : } 42 : 43 0 : std::string ConfigToHost::usage() { 44 0 : return 45 0 : R"(felix-tohost - FELIX central data acquisition application 46 : 47 : Usage: 48 : felix-tohost [options --device=<device>... --cid=<cid>... --dma=<id>...] 49 : )"; 50 : } 51 : 52 22 : std::string ConfigToHost::options() { 53 22 : return Config::options() + 54 22 : R"( 55 : ToHost Options: 56 : -D, --dma=<id> Use DMA descriptor ID. [default: 0] 57 : -c, --cmem=SIZE CMEM buffer size in MB. [default: 512] 58 : --daq-unbuffered DAQ unbuffered mode: zero-copy readout (max O(100) kHz rate per link, useful for >O(kB) messages) 59 : -T, --netio-timeout=SIZE NetIO timeout in ms for DAQ traffic. [default: 2] 60 : -w, --netio-watermark=SIZE NetIO watermark in Byte for DAQ traffic. [default: 57344] 61 : --dcs-iface=IFACE Use this network interface for DCS traffic. [calculated: use libfabric on main iface] 62 : --dcs-pages=SIZE DCS Number of NetIO pages. [default: 64] 63 : --dcs-pagesize=SIZE DCS NetIO page size in Byte. [default: 1024] 64 : -s, --dcs-port=PORT Publish DCS data on port PORT. [calculated: 53500 + 10*device + dma] 65 : --dcs-size-limit=LIMIT Truncate DCS messages when size is above LIMIT in bytes [default: 65536] 66 : --dcs-timeout=SIZE DCS NetIO timeout in ms. [default: 1] 67 : --dcs-unbuffered DCS unbuffered mode. 68 : --dcs-watermark=SIZE DCS NetIO watermark in Byte. [default: 972] 69 : -l, --l1id-check=FORMAT Check L1ID sequence. Formats: 1=TTC2H only, 2=LATOME, 3=FMEMU, 4=FELIG, 5=NSWVMM, 6=NSWTP. 70 : Slow for unbuffered DAQ. [default: 0] 71 : -M, --max-chunk-size=LIMIT Maximum chunk size in Bytes for DAQ traffic. Larger chunks are truncated. [calculated from network page size] 72 : -p, --port=PORT Publish DAQ data on port PORT. [calculated: 53100 + 10*device + dma] 73 : -P, --poll-period=us Polling instead of interrupt-driven readout with the given poll period in microseconds [default: 1000] 74 : --threads=THREADS Number of threads per DMA to read DAQ links [default: 1] 75 : --ttc-netio-pages=SIZE TTC Number of NetIO pages. [default: 64] 76 : --ttc-netio-pagesize=SIZE TTC NetIO page size in Byte. [default: 1536] 77 : --ttc-netio-timeout=SIZE TTC NetIO timeout in ms. Not necessary as TTC2H buffers are flushed at end-of-block. [default: 0] 78 : --ttc-netio-watermark=SIZE TTC NetIO watermark in Byte. [default: 1248] 79 : -t, --ttc-port=PORT Publish TTC2H data on port PORT. [calculated: 53300 + 10*device + dma] 80 : )"; 81 : } 82 : 83 22 : void ConfigToHost::handle_cmd_line(std::map<std::string, docopt::value> args) 84 : { 85 22 : Config::handle_cmd_line(args); 86 : 87 22 : if (not args["--dma"].asStringList().empty()){ 88 44 : for(const auto& i : args["--dma"].asStringList()){ 89 22 : resource.dma_ids.push_back(stoi(i)); 90 : } 91 : } else { 92 0 : resource.dma_ids = {0}; 93 : } 94 : 95 22 : resource.cmem_buffersize = args["--cmem"].asLong() * 1024*1024; 96 : 97 22 : daq_threads = args["--threads"].asLong(); 98 : 99 44 : int base_daq_port = args["--port"] ? args["--port"].asLong() : PORT_TOHOST_OFFSET; 100 22 : int base_dcs_port = args["--dcs-port"] ? args["--dcs-port"].asLong() : PORT_DCS_OFFSET; 101 40 : int base_ttc_port = args["--ttc-port"] ? args["--ttc-port"].asLong() : PORT_TTC2HOST_OFFSET; 102 : 103 44 : for(auto dev : resource.device){ 104 44 : for ( auto dmaid : resource.dma_ids){ 105 22 : int unique_id = get_unique_dmaid(dmaid, dev); 106 22 : network.ports.emplace(unique_id, PORT(base_daq_port, dev, dmaid)); 107 22 : network.dcs_ports.emplace(unique_id, PORT(base_dcs_port, dev, dmaid)); 108 22 : network.ttc_ports.emplace(unique_id, PORT(base_ttc_port, dev, dmaid)); 109 : } 110 : } 111 : 112 : // derive dcs-ip 113 22 : if (args["--dcs-iface"]) { 114 0 : network.dcs_ip = get_value_from_getifaddrs(args["--dcs-iface"].asString(), true); 115 0 : network.dcs_tcp = true; 116 : } else { 117 22 : network.dcs_ip = network.ip; 118 22 : network.dcs_tcp = false; 119 : } 120 : 121 22 : network.daq_unbuffered = args["--daq-unbuffered"].asBool(); 122 22 : network.netio_timeout = args["--netio-timeout"].asLong(); 123 22 : network.netio_watermark = args["--netio-watermark"].asLong(); 124 : 125 22 : network.dcs_unbuffered = args["--dcs-unbuffered"].asBool(); 126 22 : network.dcs_netio_pages = args["--dcs-pages"].asLong(); 127 22 : network.dcs_netio_pagesize = args["--dcs-pagesize"].asLong(); 128 22 : network.dcs_netio_timeout = args["--dcs-timeout"].asLong(); 129 22 : network.dcs_netio_watermark = args["--dcs-watermark"].asLong(); 130 : 131 22 : network.ttc_netio_pages = args["--ttc-netio-pages"].asLong(); 132 22 : network.ttc_netio_pagesize = args["--ttc-netio-pagesize"].asLong(); 133 22 : network.ttc_netio_timeout = args["--ttc-netio-timeout"].asLong(); 134 22 : network.ttc_netio_watermark = args["--ttc-netio-watermark"].asLong(); 135 : 136 22 : poll_time = args["--poll-period"].asLong(); 137 22 : l1id_check = args["--l1id-check"].asLong(); 138 22 : max_dcs_chunk_size = args["--dcs-size-limit"].asLong(); 139 22 : max_daq_chunk_size = args["--max-chunk-size"] ? args["--max-chunk-size"].asLong() : UINT32_MAX; 140 22 : }