LCOV - code coverage report
Current view: top level - flagging/Flagging - grpcFlagAgentDisplay.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 3 0.0 %
Date: 2024-11-06 17:42:47 Functions: 0 3 0.0 %

          Line data    Source code
       1             : //# FlagAgentDisplay.h: This file contains the interface definition of the FlagAgentDisplay class.
       2             : //#
       3             : //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
       4             : //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
       5             : //#  Copyright (C) European Southern Observatory, 2011, All rights reserved.
       6             : //#
       7             : //#  This library is free software; you can redistribute it and/or
       8             : //#  modify it under the terms of the GNU Lesser General Public
       9             : //#  License as published by the Free software Foundation; either
      10             : //#  version 2.1 of the License, or (at your option) any later version.
      11             : //#
      12             : //#  This library is distributed in the hope that it will be useful,
      13             : //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
      14             : //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             : //#  Lesser General Public License for more details.
      16             : //#
      17             : //#  You should have received a copy of the GNU Lesser General Public
      18             : //#  License along with this library; if not, write to the Free Software
      19             : //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      20             : //#  MA 02111-1307  USA
      21             : //# $Id: $
      22             : 
      23             : #ifndef FlagAgentDisplay_H_
      24             : #define FlagAgentDisplay_H_
      25             : 
      26             : #include <mutex>
      27             : #include <vector>
      28             : #include <future>
      29             : #include <flagging/Flagging/FlagAgentBase.h>
      30             : #ifdef USE_GRPC
      31             : #include <grpc++/server.h>
      32             : #include "plotserver.grpc.pb.h"
      33             : #include "plotserver_events.grpc.pb.h"
      34             : 
      35             : namespace casa { //# NAMESPACE CASA - BEGIN
      36             : 
      37             :     struct grpcFlagAgentState {
      38             :         grpcFlagAgentState( );
      39             :         // GUI parameters
      40             :         std::string userChoice_p;
      41             :         std::string userFixA1_p, userFixA2_p;
      42             :         casacore::Int skipScan_p, skipSpw_p, skipField_p;
      43             : 
      44             :         std::string antenna1_p;
      45             :         std::string antenna2_p;
      46             : 
      47             :         std::mutex set_values;                  // protect state within object
      48             :         bool input_received;                    // state object has received input
      49             :         bool input_needed;                              // chaged to true when the controlling
      50             :                                                                                 // thread is waiting for input
      51             :         std::promise<bool> output;                // control thread needs input
      52             :     };
      53             : 
      54             :     class grpcFlagAgentResponse : public ::rpc::gui::plotserver_events::Service {
      55             :     public:
      56           0 :         grpcFlagAgentResponse( std::shared_ptr<grpcFlagAgentState> s ) : state(s) { }
      57             : 
      58             :         ::grpc::Status button( ::grpc::ServerContext *context,
      59             :                                const ::rpc::gui::ButtonEvent *req,
      60             :                                ::google::protobuf::Empty* );
      61             :         ::grpc::Status check( ::grpc::ServerContext *context,
      62             :                               const ::rpc::gui::CheckEvent *req,
      63             :                               ::google::protobuf::Empty* );
      64             :         ::grpc::Status radio( ::grpc::ServerContext *context,
      65             :                               const ::rpc::gui::RadioEvent *req,
      66             :                               ::google::protobuf::Empty* );
      67             :         ::grpc::Status linetext( ::grpc::ServerContext *context,
      68             :                                  const ::rpc::gui::LineTextEvent *req,
      69             :                                  ::google::protobuf::Empty* );
      70             :         ::grpc::Status slidevalue( ::grpc::ServerContext *context,
      71             :                                    const ::rpc::gui::SlideValueEvent *req,
      72             :                                    ::google::protobuf::Empty* );
      73             :         ::grpc::Status exiting( ::grpc::ServerContext *context,
      74             :                                 const ::google::protobuf::Empty*,
      75             :                                 ::google::protobuf::Empty* );
      76             :         ::grpc::Status closing( ::grpc::ServerContext *context,
      77             :                                 const ::rpc::gui::ClosingEvent *req,
      78             :                                 ::google::protobuf::Empty* );
      79             :     protected:
      80             :         std::shared_ptr<grpcFlagAgentState> state;
      81             :     };
      82             : 
      83             :     class FlagAgentDisplay : public FlagAgentBase {
      84             :     public:
      85             :       
      86             :         FlagAgentDisplay(FlagDataHandler *dh, casacore::Record config, casacore::Bool writePrivateFlagCube = false);
      87             :         ~FlagAgentDisplay();
      88             : 
      89             :         // Make plots and either display or write to a file
      90             :         casacore::Bool displayReports(FlagReport &combinedReport);
      91             :     
      92             :         // Get a report/summary
      93             :         FlagReport getReport();
      94             :     
      95             :     protected:
      96             : 
      97             :         std::string discover_executable( );
      98             : 
      99             :         struct plotter_t {
     100           0 :             bool active( ) const { return active_; }
     101             :             pid_t pid;
     102             :             std::string plot_uri;
     103             :             std::unique_ptr<rpc::gui::plotserver::Stub> plot;
     104             :             std::unique_ptr<rpc::gui::plotserver_events::Service> response;
     105             :             bool launch(std::string plotserver_path);
     106             :             plotter_t(std::shared_ptr<grpcFlagAgentState> state);
     107             :         protected:
     108             :             bool active_;
     109             :             bool start_response_manager( );
     110             :             std::string get_casaplotserver_path( ) const;
     111             :             std::string get_distro_data_path( ) const;
     112             :             std::string get_fifo( ) const;
     113             :             std::unique_ptr<grpcFlagAgentResponse> response_svc;
     114             :             std::unique_ptr<grpc::Server> response_server;
     115             :             std::string response_uri;
     116             :             bool plot_started_;
     117             :         };
     118             : 
     119             :         // shutdown a plotserver process
     120             :         bool done( std::shared_ptr<plotter_t> plotter );
     121             :         // create panel
     122             :         int create_panel( std::shared_ptr<plotter_t> plot, int parent, bool new_row );
     123             :         // erase
     124             :         void erase( std::shared_ptr<plotter_t> plot, int panel );
     125             :         // set labels
     126             :         void setlabel( std::shared_ptr<plotter_t> plot, int panel, std::string xlabel, std::string ylabel, std::string title );
     127             :         // load dock
     128             :         int create_dock( std::shared_ptr<plotter_t> plot, int panel, std::string xml );
     129             :         int raster( std::shared_ptr<plotter_t> plot, int panel, const std::vector<float> &data, ssize_t sizex, ssize_t sizey );
     130             :         int line( std::shared_ptr<plotter_t> plot, int panel, const std::vector<float> &xdata, const std::vector<float> &ydata, std::string color, std::string label );
     131             :         int scatter( std::shared_ptr<plotter_t> plot, int panel, const std::vector<float> &xdata,
     132             :                      const std::vector<float> &ydata, std::string color, std::string label,
     133             :                      std::string symbol, int symbol_size, int dot_size );
     134             : 
     135             :         // Compute flags for a given (time,freq) map
     136             :         bool computeAntennaPairFlags(const vi::VisBuffer2 &visBuffer, VisMapper &visibilities,FlagMapper &flag,casacore::Int antenna1,casacore::Int antenna2,std::vector<casacore::uInt> &rows);
     137             : 
     138             :         void preProcessBuffer(const vi::VisBuffer2 &visBuffer);
     139             :     
     140             :         // Choose how to step through the baselines in the current chunk
     141             :         void iterateAntennaPairsInteractive(antennaPairMap *antennaPairMap_ptr);
     142             :     
     143             :         // Parse configuration parameters
     144             :         void setAgentParameters(casacore::Record config);
     145             : 
     146             :     private:
     147             : 
     148             :         static constexpr int TIMEOUT = 80000;
     149             :     
     150             :         casacore::Bool setDataLayout();
     151             :         casacore::Bool setReportLayout();
     152             :         casacore::Bool buildDataPlotWindow();
     153             :         casacore::Bool buildReportPlotWindow();
     154             : 
     155             : 
     156             :         void getChunkInfo(const vi::VisBuffer2 &visBuffer);
     157             :         casacore::Bool skipBaseline(std::pair<casacore::Int,casacore::Int> antennaPair);
     158             :  
     159             :         void getUserInput();
     160             :         void getReportUserInput();
     161             :     
     162             :         void DisplayRaster(casacore::Int xdim, casacore::Int ydim, casacore::Vector<casacore::Float> &data, int frame);
     163             :         void DisplayLine(casacore::Int xdim, casacore::Vector<casacore::Double> &xdata, casacore::Vector<casacore::Float> &ydata, casacore::String label, casacore::String color, casacore::Bool hold, int frame);
     164             :         void DisplayScatter(casacore::Int xdim, casacore::Vector<casacore::Double> &xdata, casacore::Vector<casacore::Float> &ydata, casacore::String label, casacore::String color, casacore::Bool hold, int frame);
     165             :         void DisplayLineScatterError(std::shared_ptr<plotter_t> plotter, casacore::String &plottype, casacore::Vector<casacore::Float> &xdata, casacore::Vector<casacore::Float> &ydata, casacore::String &errortype, casacore::Vector<casacore::Float> &error, casacore::String label, casacore::String color, int frame);
     166             : 
     167             :         // Plotter members
     168             :         std::shared_ptr<grpcFlagAgentState> gui_state;
     169             :         std::shared_ptr<plotter_t> dataplotter_p;
     170             :         std::shared_ptr<plotter_t> reportplotter_p;
     171           0 :         bool active( ) const { return (dataplotter_p && dataplotter_p->active( )) || (reportplotter_p && reportplotter_p->active( )); }
     172             : 
     173             :         // Control parameters
     174             :         casacore::Bool pause_p;
     175             : 
     176             :         // visBuffer state variables
     177             :         casacore::Int fieldId_p;
     178             :         casacore::String fieldName_p;
     179             :         casacore::Int scanStart_p;
     180             :         casacore::Int scanEnd_p;
     181             :         casacore::Int spwId_p;
     182             :         casacore::uInt nPolarizations_p;
     183             :         casacore::Vector<casacore::Double> freqList_p;
     184             : 
     185             :         casacore::Bool dataDisplay_p, reportDisplay_p; // show per chunk plots and/or end-of-casacore::MS plots
     186             :         casacore::String reportFormat_p;
     187             :         casacore::Bool stopAndExit_p;
     188             :         // casacore::Bool reportReturn_p;
     189             :         casacore::Bool showBandpass_p;
     190             : 
     191             :         std::vector<int> panels_p;
     192             :         std::vector<int> report_panels_p;
     193             : 
     194             :         const char *dock_xml_p, *report_dock_xml_p;
     195             : //    casacore::Bool showBandpass_p;
     196             : 
     197             :     // Control parameters
     198             : //    casacore::Bool stopAndExit_p;
     199             : //    casacore::Bool pause_p;
     200             : //    casacore::Bool dataDisplay_p, reportDisplay_p; // show per chunk plots and/or end-of-casacore::MS plots
     201             : //    casacore::Bool reportReturn_p;
     202             : //    casacore::String reportFormat_p;
     203             :     
     204             :     // visBuffer state variables
     205             : //    casacore::Int fieldId_p;
     206             : //    casacore::String fieldName_p;
     207             : //    casacore::Int scanStart_p;
     208             : //    casacore::Int scanEnd_p;
     209             : //    casacore::Int spwId_p;
     210             : //    casacore::String antenna1_p;
     211             : //    casacore::String antenna2_p;
     212             :     
     213             : //    casacore::uInt nPolarizations_p;
     214             : //    casacore::Vector<casacore::Double> freqList_p;
     215             :     
     216             :     // GUI parameters
     217             : //    casacore::String userChoice_p;
     218             : //    casacore::String userFixA1_p, userFixA2_p;
     219             :     
     220             : //    casacore::Int skipScan_p, skipSpw_p, skipField_p;
     221             : 
     222             :         casacore::Vector<casacore::String> plotColours_p;
     223             :     
     224             :     
     225             :     };
     226             :   
     227             :   
     228             : } //# NAMESPACE CASA - END
     229             : 
     230             : #endif //# USE_GRPC
     231             : 
     232             : #endif /* FLAGAGENTDISPLAY_H_ */
     233             : 

Generated by: LCOV version 1.16