File: DebugLog.cpp

package info (click to toggle)
clustalx 2.1%2Blgpl-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,336 kB
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 11
file content (81 lines) | stat: -rw-r--r-- 1,604 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
 * Author: Mark Larkin
 * 
 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.  
 */
#ifdef HAVE_CONFIG_H
    #include "config.h"
#endif
#include "DebugLog.h"
#include <sstream>
#include <iostream>
namespace clustalw
{

DebugLog::DebugLog(std::string _logFileName)
 : logFileName(_logFileName),
   logFile(0),
   numScores(0),
   sumSoFar(0.0),
   averageScore(0.0),
   minScore(0.0),
   maxScore(0.0)
{
    logFile = new std::ofstream();  
    logFile->open(logFileName.c_str(), ios::out);
    
    if(logFile->is_open())
    {
        std::cout << "Logging debug info to file: " << logFileName << std::endl;
    }
    else
    {
        std::cerr << "Could not open log file.\n";
    }    
}

DebugLog::~DebugLog()
{
    // Release the file!
    logFile->close();
    delete logFile;
}

void DebugLog::logMsg(std::string msg)
{
    if(logFile->is_open())
    {
        (*logFile) << msg << "\n";
    }
}

void DebugLog::logScore(float x)
{
    if(x < minScore)
    {
        minScore = x;
    }
    if(x > maxScore)
    {
        maxScore = x;
    }
        
    sumSoFar += x;
    numScores++;
}

void DebugLog::printScoreInfo()
{
    if(numScores > 0)
    {
        averageScore = sumSoFar / static_cast<float>(numScores);
        ostringstream outs;
        outs << "SCORE INFO--------------------------------------------------->"
             << " The score was calculated " << numScores << " times. The average = "
             << averageScore << "\n" << "The max score=" << maxScore << " The min score="
             << minScore << "\n";
        logMsg(outs.str());
    }
}

}