LCOV - code coverage report
Current view: top level - /opt/artdaq/srcs/artdaq-mfextensions/mfextensions/Receivers - LogReader_receiver.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 83 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 6 0

            Line data    Source code
       1              : #include "mfextensions/Receivers/LogReader_receiver.hh"
       2              : #include <iostream>
       3              : #include "mfextensions/Receivers/ReceiverMacros.hh"
       4              : 
       5            0 : mfviewer::LogReader::LogReader(const fhicl::ParameterSet& pset)
       6            0 :     : MVReceiver(pset), pos_(0), filename_(pset.get<std::string>("filename")), counter_(0), metadata_1(R"(\%MSG-([wide])\s([^:]*):\s\s([^\s]*)\s*(\d\d-[^-]*-\d{4}\s\d+:\d+:\d+)\s.[DS]T\s\s(\w+))")
       7              : //, metadata_2
       8              : //  ( "([^\\s]*)\\s([^\\s]*)\\s([^\\s]*)\\s(([^\\s]*)\\s)?([^:]*):(\\d*)" )
       9              : {
      10            0 :         std::cout << "LogReader_receiver Constructor" << std::endl;
      11            0 :         this->setObjectName("viewer Log");
      12            0 : }
      13              : 
      14            0 : mfviewer::LogReader::~LogReader()
      15              : {
      16              :         try
      17              :         {
      18            0 :                 log_.close();
      19              :         }
      20            0 :         catch (...)
      21              :         {
      22              :                 // IGNORED
      23            0 :         }
      24            0 : }
      25              : 
      26            0 : void mfviewer::LogReader::run()
      27              : {
      28            0 :         while (!stopRequested_)
      29              :         {
      30            0 :                 log_.open(filename_.c_str(), std::fstream::in);
      31            0 :                 log_.seekg(pos_);
      32              : 
      33            0 :                 if (log_.is_open() && log_.good())
      34              :                 {
      35            0 :                         bool msgFound = false;
      36            0 :                         while (!msgFound)
      37              :                         {
      38            0 :                                 if (log_.eof())
      39              :                                 {
      40            0 :                                         break;
      41              :                                 }
      42              : 
      43            0 :                                 std::string line;
      44            0 :                                 pos_ = log_.tellg();
      45            0 :                                 getline(log_, line);
      46            0 :                                 if (line.find("%MSG") != std::string::npos)
      47              :                                 {
      48            0 :                                         msgFound = true;
      49            0 :                                         log_.seekg(pos_);
      50              :                                 }
      51            0 :                         }
      52              : 
      53            0 :                         if (msgFound)
      54              :                         {
      55            0 :                                 std::cout << "Message found, emitting!" << std::endl;
      56            0 :                                 emit NewMessage(read_next());
      57            0 :                                 ++counter_;
      58              :                         }
      59            0 :                         log_.clear();
      60            0 :                         pos_ = log_.tellg();
      61              :                 }
      62              : 
      63            0 :                 log_.clear();
      64            0 :                 log_.close();
      65            0 :                 usleep(500000);
      66              :                 // sleep(1);
      67              :         }
      68              : 
      69            0 :         std::cout << "LogReader_receiver shutting down!" << std::endl;
      70            0 : }
      71              : 
      72              : #include <ctime>
      73              : #include <iostream>
      74              : 
      75            0 : msg_ptr_t mfviewer::LogReader::read_next()
      76              : {
      77            0 :         std::string line;
      78              : 
      79              :         // meta data 1
      80            0 :         getline(log_, line);
      81              : 
      82            0 :         std::string category, application, eventID;
      83            0 :         timeval tv = {0, 0};
      84            0 :         sev_code_t sev = SERROR;
      85              : 
      86            0 :         if (boost::regex_search(line, what_, metadata_1))
      87              :         {
      88              : #if 0
      89              :                 std::cout << ">> " << std::string(what_[1].first, what_[1].second) << "\n";
      90              :                 std::cout << ">> " << std::string(what_[2].first, what_[2].second) << "\n";
      91              :                 std::cout << ">> " << std::string(what_[3].first, what_[3].second) << "\n";
      92              :                 std::cout << ">> " << std::string(what_[4].first, what_[4].second) << "\n";
      93              :                 std::cout << ">> " << std::string(what_[5].first, what_[5].second) << "\n";
      94              : #endif
      95              : 
      96            0 :                 std::string value = std::string(what_[1].first, what_[1].second);
      97              : 
      98            0 :                 switch (value[0])
      99              :                 {
     100            0 :                         case 'e':
     101            0 :                                 sev = SERROR;
     102            0 :                                 break;
     103            0 :                         case 'w':
     104            0 :                                 sev = SWARNING;
     105            0 :                                 break;
     106            0 :                         case 'i':
     107            0 :                                 sev = SINFO;
     108            0 :                                 break;
     109            0 :                         case 'd':
     110            0 :                                 sev = SDEBUG;
     111            0 :                                 break;
     112            0 :                         default:
     113            0 :                                 break;
     114              :                 }
     115              : 
     116              :                 struct tm tm;
     117              :                 time_t t;
     118              : 
     119            0 :                 value = std::string(what_[4].first, what_[4].second);
     120            0 :                 strptime(value.c_str(), "%d-%b-%Y %H:%M:%S", &tm);
     121              : 
     122            0 :                 tm.tm_isdst = -1;
     123            0 :                 t = mktime(&tm);
     124            0 :                 tv.tv_sec = t;
     125            0 :                 tv.tv_usec = 0;
     126              : 
     127            0 :                 category = std::string(what_[2].first, what_[2].second);
     128            0 :                 application = std::string(what_[3].first, what_[3].second);
     129              : 
     130            0 :                 eventID = std::string(what_[5].first, what_[5].second);
     131              :                 // msg.setHostname ( std::string(what_[4].first, what_[4].second) );
     132              :                 // msg.setHostaddr ( std::string(what_[5].first, what_[5].second) );
     133            0 :         }
     134            0 :         std::string body;
     135            0 :         getline(log_, line);
     136              : 
     137            0 :         msg_ptr_t msg = std::make_shared<qt_mf_msg>("", category, application, 0, tv);
     138            0 :         msg->setSeverityLevel(sev);
     139            0 :         msg->setEventID(eventID);
     140              : 
     141            0 :         while (!log_.eof() && line.find("%MSG") == std::string::npos)
     142              :         {
     143            0 :                 body += line;
     144            0 :                 getline(log_, line);
     145              :         }
     146              : 
     147            0 :         msg->setMessage(filename_, counter_, body);
     148            0 :         msg->updateText();
     149              : 
     150            0 :         return msg;
     151            0 : }
     152              : 
     153              : #include "moc_LogReader_receiver.cpp"
     154              : 
     155            0 : DEFINE_MFVIEWER_RECEIVER(mfviewer::LogReader)
        

Generated by: LCOV version 2.0-1