LCOV - code coverage report
Current view: top level - dbe/src/internal - messenger.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 54 0
Test Date: 2026-07-12 15:23:06 Functions: 0.0 % 13 0

            Line data    Source code
       1              : // DUNE DAQ modification notice:
       2              : // This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
       3              : // Fork baseline commit: dbe-02-12-17 (2022-05-12).
       4              : // Renamed since fork: no.
       5              : 
       6              : /*
       7              :  * messenger.cpp
       8              :  *
       9              :  *  Created on: Nov 3, 2015
      10              :  *      Author: Leonidas Georgopoulos
      11              :  */
      12              : 
      13              : #include "logging/Logging.hpp"
      14              : 
      15              : #include "dbe/messenger.hpp"
      16              : #include "dbe/messenger_proxy.hpp"
      17              : 
      18              : #include <map>
      19              : #include <cassert>
      20              : 
      21              : namespace dbe
      22              : {
      23              : namespace interface
      24              : {
      25              : namespace messenger
      26              : {
      27              : 
      28              : //------------------------------------------------------------------------------------------
      29              : msglevels::t_str const msglevels::debug = "DEBUG";
      30              : msglevels::t_str const msglevels::info = "INFO";
      31              : msglevels::t_str const msglevels::note = "NOTE";
      32              : msglevels::t_str const msglevels::warn = "WARN";
      33              : msglevels::t_str const msglevels::error = "ERROR";
      34              : msglevels::t_str const msglevels::fail = "FAIL";
      35              : 
      36              : msglevels::t_levels const msglevels::all_levels = {debug, info, note, warn, error, fail};
      37              : // provides codes from message level type ( level -> code )
      38              : static std::map<qt::t_str const, messages const> codes =
      39              : {
      40              :   { msglevels::info, messages::DEBUG},
      41              :   { msglevels::info, messages::INFO },
      42              :   { msglevels::note, messages::NOTE },
      43              :   { msglevels::warn, messages::WARN },
      44              :   { msglevels::error, messages::ERROR },
      45              :   { msglevels::fail, messages::FAIL }
      46              : };
      47              : 
      48              : // provides level types from code ( code->level)
      49              : static std::map<messages const, qt::t_str const> levels =
      50              : {
      51              :   { messages::DEBUG, msglevels::debug },
      52              :   { messages::INFO, msglevels::info },
      53              :   { messages::NOTE, msglevels::note },
      54              :   { messages::WARN, msglevels::warn },
      55              :   { messages::ERROR, msglevels::error },
      56              :   { messages::FAIL, msglevels::fail }
      57              : };
      58              : 
      59              : // provides titles from level types
      60              : static std::map<qt::t_str const, qt::t_str const> titles =
      61              : {
      62              :   { msglevels::debug, "Debug info" },
      63              :   { msglevels::info, "Information" },
      64              :   { msglevels::note, "Notice" },
      65              :   { msglevels::warn, "Warning" },
      66              :   { msglevels::error, "Error" },
      67              :   { msglevels::fail, "Failure" }
      68              : };
      69              : 
      70              : std::mutex qt::m_block;
      71              : std::atomic<bool> qt::m_batch_mode ( false );
      72              : qt::t_batches qt::m_batches;
      73              : //------------------------------------------------------------------------------------------
      74              : 
      75              : //------------------------------------------------------------------------------------------
      76            0 : qt::post_ret_type qt::post ( t_str const & m, t_str const & l )
      77              : {
      78            0 :   std::lock_guard<std::mutex> lock ( m_block );
      79              : 
      80            0 :   if ( m_batch_mode )
      81              :   {
      82            0 :     merge_post ( m, l );
      83              :   }
      84              :   else
      85              :   {
      86            0 :     direct_post ( m, l );
      87              :   }
      88            0 : }
      89              : //------------------------------------------------------------------------------------------
      90              : 
      91              : //------------------------------------------------------------------------------------------
      92            0 : qt::post_ret_type qt::direct_post ( t_str const & m, t_str const & l )
      93              : {
      94            0 :   if ( warn == l )
      95              :   {
      96            0 :     TLOG_DEBUG(0) <<  static_cast<int> ( messages::WARN ) <<  m ;
      97            0 :     messenger_proxy::ref().warn ( titles[warn], m );
      98              :   }
      99            0 :   else if ( error == l )
     100              :   {
     101            0 :     TLOG_DEBUG(0) << static_cast<int> ( messages::ERROR ) << m ;
     102            0 :     messenger_proxy::ref().error ( titles[error], m );
     103              :   }
     104            0 :   else if ( info == l )
     105              :   {
     106            0 :     TLOG_DEBUG(0) << static_cast<int> ( messages::INFO ) << m ;
     107            0 :     messenger_proxy::ref().info ( titles[info], m );
     108              :   }
     109            0 :   else if ( fail == l )
     110              :   {
     111            0 :     TLOG_DEBUG(0) << static_cast<int> ( messages::FAIL ) << m ;
     112            0 :     messenger_proxy::ref().fail ( titles[fail], m );
     113              :   }
     114            0 :   else if ( note == l )
     115              :   {
     116            0 :     TLOG_DEBUG(0) << static_cast<int> ( messages::NOTE ) << m ;
     117            0 :     messenger_proxy::ref().fail ( titles[note], m );
     118              :   }
     119            0 :   else if ( debug == l )
     120              :   {
     121            0 :     TLOG_DEBUG(0) << static_cast<int> ( messages::DEBUG ) << m ;
     122            0 :     messenger_proxy::ref().fail ( titles[debug], m );
     123              :   }
     124            0 : }
     125              : //------------------------------------------------------------------------------------------
     126              : 
     127              : //------------------------------------------------------------------------------------------
     128            0 : qt::post_ret_type qt::merge_post ( t_str const & m, t_str const & l )
     129              : {
     130            0 :   auto codeit = codes.find ( l );
     131            0 :   assert ( codeit != codes.end() );
     132            0 :   m_batches[static_cast<int> ( codeit->second )].insert ( m );
     133            0 : }
     134              : //------------------------------------------------------------------------------------------
     135              : 
     136              : //------------------------------------------------------------------------------------------
     137            0 : void qt::purge()
     138              : {
     139            0 :   for ( auto clevel = m_batches.begin(); clevel != m_batches.end(); ++clevel )
     140              :   {
     141            0 :     if ( not clevel->empty() )
     142              :     {
     143            0 :         t_str merged ( "Summary of messages during batch mode" );
     144              : 
     145            0 :         for(auto it = clevel->begin(); it != clevel->end(); ) {
     146            0 :             auto cnt = clevel->count(*it);
     147              : 
     148            0 :             t_str cmessage = *it;
     149            0 :             merged += t_str ( "\n\n" ) + cmessage + t_str ( "\n\n #Occurances=" ) + std::to_string(cnt);
     150              : 
     151            0 :             std::advance(it, cnt);
     152            0 :         }
     153              : 
     154            0 :         direct_post ( merged, levels[static_cast<messages> ( clevel - m_batches.begin() )] );
     155            0 :         clevel->clear();
     156            0 :     }
     157              :   }
     158            0 : }
     159              : //------------------------------------------------------------------------------------------
     160              : 
     161              : //------------------------------------------------------------------------------------------
     162            0 : std::unique_ptr<batch_guard> qt::batchmode()
     163              : {
     164            0 :   return std::unique_ptr<batch_guard> ( new batch_guard() );
     165              : }
     166              : //------------------------------------------------------------------------------------------
     167              : 
     168              : //------------------------------------------------------------------------------------------
     169            0 : batch_guard::~batch_guard()
     170              : {
     171            0 :   qt::m_batch_mode = false;
     172            0 :   qt::purge();
     173            0 : }
     174              : //------------------------------------------------------------------------------------------
     175              : 
     176              : //------------------------------------------------------------------------------------------
     177            0 : batch_guard::batch_guard()
     178              : {
     179            0 :   qt::m_batch_mode = true;
     180            0 : }
     181              : //------------------------------------------------------------------------------------------
     182              : 
     183              : }// namespace messenger
     184              : } /* namespace interface */
     185              : } /* namespace dbe */
        

Generated by: LCOV version 2.0-1