LCOV - code coverage report
Current view: top level - casa_sakura - SakuraUtils.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 24 40 60.0 %
Date: 2024-10-29 13:38:20 Functions: 3 5 60.0 %

          Line data    Source code
       1             : #include <iostream>
       2             : 
       3             : #include <libsakura/sakura.h>
       4             : //#include <libsakura/config.h>
       5             : 
       6             : #include <casacore/casa/Logging/LogIO.h>
       7             : #include <casacore/casa/Logging/LogOrigin.h>
       8             : 
       9             : #include <casa_sakura/SakuraUtils.h>
      10             : #include <casa_sakura/SakuraAlignedArray.h>
      11             : 
      12             : using namespace casacore;
      13             : namespace casa {
      14             : Bool SakuraUtils::is_initialized_ = false;
      15             :   
      16           3 : Bool SakuraUtils::InitializeSakura() {
      17             :   // return if already initialized
      18           3 :   if (is_initialized_) {
      19           0 :     return true;
      20             :   }
      21             :   
      22           6 :   LogIO logger(LogOrigin("SakuraUtils", "InitializeSakura", WHERE));
      23           3 :   logger << LogIO::DEBUGGING << "Initializing Sakura...";
      24           3 :   is_initialized_ = false;
      25           3 :   LIBSAKURA_SYMBOL(Status) status = LIBSAKURA_SYMBOL(Initialize)(NULL, NULL);
      26           3 :   if (status == LIBSAKURA_SYMBOL(Status_kOK)) {
      27           3 :     logger << LogIO::DEBUGGING << "SUCCESS!" << LogIO::POST;
      28           3 :     is_initialized_ = true;
      29             :   }
      30             :   else {
      31           0 :     logger << LogIO::DEBUGGING << "FAILED!" << LogIO::POST;
      32             :   }
      33           3 :   return is_initialized_;
      34           3 : }
      35             : 
      36           1 : void SakuraUtils::CleanUpSakura() {
      37           1 :   if (is_initialized_) {
      38           2 :     LogIO logger(LogOrigin("SakuraUtils", "CleanUpSakura", WHERE));
      39           1 :     logger << LogIO::DEBUGGING << "Cleaning up Sakura..." << LogIO::POST;
      40           1 :     LIBSAKURA_SYMBOL(CleanUp)();
      41           1 :     is_initialized_ = false;
      42           1 :   }
      43           1 : }
      44             : 
      45           3 : Bool SakuraUtils::IsSakuraInitialized() {
      46           6 :   LogIO logger(LogOrigin("SakuraUtils", "IsSakuraInitialized", WHERE));
      47             :   logger << LogIO::DEBUGGING << "sakura is "
      48           3 :          << ((is_initialized_) ? "" : "not ") << "initialized." << LogIO::POST;
      49           3 :   return is_initialized_;
      50           3 : }
      51             : 
      52             : // SakuraDriver
      53             : // initialize instance counter for SakuraDriver
      54             : int SakuraDriver::num_instances_ = 0;
      55             : 
      56             : // Constructor increments num_instances_
      57             : // InitlaizeSakura is called if num_instances_ is 0 (i.e. first instantiation)
      58             : // or Sakura is not initialized yet.
      59           0 : SakuraDriver::SakuraDriver() {
      60           0 :   if (num_instances_ == 0 || !(SakuraUtils::IsSakuraInitialized())) {
      61           0 :     std::cerr << "Initialize Sakura: num_instances_ = " << num_instances_ << endl;
      62           0 :     SakuraUtils::InitializeSakura();
      63             :   }
      64           0 :   num_instances_++;
      65           0 :   std::cerr << "num_instances_ = " << num_instances_ << std::endl;
      66           0 : }
      67             : 
      68             : // Destructor decrements num_instances_
      69             : // FinalizeSakura is called when num_instances_ is 0 (i.e. the last
      70             : // instance is to be destructed). 
      71           0 : SakuraDriver::~SakuraDriver() {
      72           0 :   std::cerr << "num_instances_ = " << num_instances_ << std::endl;
      73           0 :   num_instances_--;
      74           0 :   if (num_instances_ == 0 && SakuraUtils::IsSakuraInitialized()) {
      75           0 :     std::cerr << "Finalize Sakura: num_instances_ = " << num_instances_ << std::endl;
      76           0 :     SakuraUtils::CleanUpSakura();
      77             :   }
      78           0 : }
      79             :   
      80             : }  // End of casa namespace.

Generated by: LCOV version 1.16