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 1 : Bool SakuraUtils::InitializeSakura() { 17 : // return if already initialized 18 1 : if (is_initialized_) { 19 0 : return true; 20 : } 21 : 22 2 : LogIO logger(LogOrigin("SakuraUtils", "InitializeSakura", WHERE)); 23 1 : logger << LogIO::DEBUGGING << "Initializing Sakura..."; 24 1 : is_initialized_ = false; 25 1 : LIBSAKURA_SYMBOL(Status) status = LIBSAKURA_SYMBOL(Initialize)(NULL, NULL); 26 1 : if (status == LIBSAKURA_SYMBOL(Status_kOK)) { 27 1 : logger << LogIO::DEBUGGING << "SUCCESS!" << LogIO::POST; 28 1 : is_initialized_ = true; 29 : } 30 : else { 31 0 : logger << LogIO::DEBUGGING << "FAILED!" << LogIO::POST; 32 : } 33 1 : return is_initialized_; 34 : } 35 : 36 0 : void SakuraUtils::CleanUpSakura() { 37 0 : if (is_initialized_) { 38 0 : LogIO logger(LogOrigin("SakuraUtils", "CleanUpSakura", WHERE)); 39 0 : logger << LogIO::DEBUGGING << "Cleaning up Sakura..." << LogIO::POST; 40 0 : LIBSAKURA_SYMBOL(CleanUp)(); 41 0 : is_initialized_ = false; 42 : } 43 0 : } 44 : 45 1 : Bool SakuraUtils::IsSakuraInitialized() { 46 2 : LogIO logger(LogOrigin("SakuraUtils", "IsSakuraInitialized", WHERE)); 47 : logger << LogIO::DEBUGGING << "sakura is " 48 1 : << ((is_initialized_) ? "" : "not ") << "initialized." << LogIO::POST; 49 2 : return is_initialized_; 50 : } 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.