1 /** 2 * Author: Mark Larkin 3 * 4 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson. 5 */ 6 #ifdef HAVE_CONFIG_H 7 #include "config.h" 8 #endif 9 #include "DebugLog.h" 10 #include <sstream> 11 #include <iostream> 12 namespace clustalw 13 { 14 DebugLog(std::string _logFileName)15DebugLog::DebugLog(std::string _logFileName) 16 : logFileName(_logFileName), 17 logFile(0), 18 numScores(0), 19 sumSoFar(0.0), 20 averageScore(0.0), 21 minScore(0.0), 22 maxScore(0.0) 23 { 24 logFile = new std::ofstream(); 25 logFile->open(logFileName.c_str(), ios::out); 26 27 if(logFile->is_open()) 28 { 29 std::cout << "Logging debug info to file: " << logFileName << std::endl; 30 } 31 else 32 { 33 std::cerr << "Could not open log file.\n"; 34 } 35 } 36 ~DebugLog()37DebugLog::~DebugLog() 38 { 39 // Release the file! 40 logFile->close(); 41 delete logFile; 42 } 43 logMsg(std::string msg)44void DebugLog::logMsg(std::string msg) 45 { 46 if(logFile->is_open()) 47 { 48 (*logFile) << msg << "\n"; 49 } 50 } 51 logScore(float x)52void DebugLog::logScore(float x) 53 { 54 if(x < minScore) 55 { 56 minScore = x; 57 } 58 if(x > maxScore) 59 { 60 maxScore = x; 61 } 62 63 sumSoFar += x; 64 numScores++; 65 } 66 printScoreInfo()67void DebugLog::printScoreInfo() 68 { 69 if(numScores > 0) 70 { 71 averageScore = sumSoFar / static_cast<float>(numScores); 72 ostringstream outs; 73 outs << "SCORE INFO--------------------------------------------------->" 74 << " The score was calculated " << numScores << " times. The average = " 75 << averageScore << "\n" << "The max score=" << maxScore << " The min score=" 76 << minScore << "\n"; 77 logMsg(outs.str()); 78 } 79 } 80 81 } 82