Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

logger.cpp

Go to the documentation of this file.
00001 /*
00002  * ******** fete: From ENDF To ENDL *********
00003  * 
00004  * Copyright (c) 2006, The Regents of the University of California. 
00005  * All rights reserved.
00006  * 
00007  * Produced at the Lawrence Livermore National Laboratory. 
00008  * Written by David A. Brown, Gerry Hedstrom, Tony Hill
00009  * 
00010  * This file is part of fete v1.0  (UCRL-CODE-218718)
00011  * 
00012  * Please read the COPYING file for "Our Notice and GNU General 
00013  * Public License" in the root of this software distribution.  
00014  * 
00015  * This program is free software; you can redistribute it and/or modify 
00016  * it under the terms of the GNU General Public License (as published by 
00017  * the Free Software Foundation) version 2, dated June 1991. 
00018  * 
00019  * This program is distributed in the hope that it will be useful, 
00020  * but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF 
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms 
00022  * and conditions of the GNU General Public License for more details. 
00023  * 
00024  * You should have received a copy of the GNU General Public License along 
00025  * with this program; if not, write to the Free Software Foundation, Inc., 
00026  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00027  * 
00028  * $Revision: 1869 $
00029  * $Date: 2006-05-15 12:56:46 -0700 (Mon, 15 May 2006) $
00030  * $Author: dbrown $
00031  * $Id: logger.cpp 1869 2006-05-15 19:56:46Z dbrown $
00032  * 
00033  * ******** fete: From ENDF To ENDL *********
00034  */
00035 
00036 #include <fstream>
00037 #include <string>
00038 #include <sstream>
00039 #include "version.hpp"
00040 #include "logger.hpp"
00041 #include "convert.hpp"
00042 #include "global_params.hpp"
00043 
00044 extern GlobalParameterClass Global;
00045 
00046 //! output for MFMT
00047 ostream& operator<<(ostream& out, const MFMT& mfmt){
00048     out << "MF: "<<mfmt.MF<<" MT: "<<mfmt.MT;
00049     if (mfmt.C!=-1 && mfmt.I!=-1 && mfmt.S!=-1) {
00050         out << " c: "<<mfmt.C<<" i: "<<mfmt.I<<" s: "<<mfmt.S;
00051     }
00052     return out;
00053 }
00054 
00055 //! output for logEntry
00056 ostream& operator<<(ostream& out, const logEntry& ent){
00057     switch (ent.severity) {
00058         case 0: 
00059             out << rjust("Info",14); 
00060             break; 
00061         case 1: 
00062             out << rjust("Unimplemented",14);  
00063             break; 
00064         case 2: 
00065             out << rjust("Warning",14); 
00066             break; 
00067         case 3: 
00068             out << rjust("Severe Error",14);
00069             break; 
00070         case 4: 
00071             out << rjust("Fatal Error",14); 
00072     }
00073     out <<", "<< ent.message;
00074     return out;
00075 }
00076 
00077 void MessageLogger::logMessage(int MF, int MT, string msg, int severity){
00078     MFMT thisMFMT(MF=MF,MT=MT);
00079     while (find(thisMFMT)!=end()){
00080         thisMFMT.index+=1;
00081     }
00082     insert(make_pair(thisMFMT,logEntry(msg,severity)));
00083 }
00084     
00085 void MessageLogger::logMessage(int MF, int MT, int C, int I, int S, string msg, int severity){
00086     MFMT thisMFMT(MF,MT,C,I,S);
00087     while (find(thisMFMT)!=end()){
00088         thisMFMT.index+=1;
00089     }
00090     insert(make_pair(thisMFMT,logEntry(msg,severity)));
00091 }
00092 
00093 //! main output routine for the MessageLogger
00094 bool MessageLogger::write(void){
00095     bool isEndfDoc(false);
00096     ifstream inStream(inLogFile.c_str());
00097     stringstream oldStuff("");
00098     char buffer[81];
00099     if (inStream.good()) {
00100         while (inStream.getline(buffer,sizeof(buffer))){oldStuff<<buffer;oldStuff<<"\n";}
00101         isEndfDoc=true;
00102     } else {
00103         cout << "Info: Could not read "<<inLogFile<<", will not include ENDF documentation in log file"<<endl;
00104     }
00105     ofstream outStream(outLogFile.c_str());
00106     if (!outStream.good()) return false;
00107     if (isEndfDoc) {
00108         outStream << center(60*string("="),62) << endl;
00109         outStream << center("ENDF File Documentation",62) << endl;
00110         outStream << center(60*string("="),62) << endl;
00111         outStream << oldStuff.str() << endl << endl;
00112     }
00113     if (Global.Value( "skip_logging" )>0.0) return true;
00114     //Pretty banner to set off start of program & print the version information
00115     outStream << 11*string(" ") << "+" << 40*string("-") << "+"<<endl;
00116     outStream << 11*string(" ") << "|" << center("fete: from ENDF to endl...",40)<< "|"<<endl;
00117     outStream << 11*string(" ") << "|" << center("Version "+string(FETE_VERSION),40) << "|" <<endl;
00118     outStream << 11*string(" ") << "|" << center("Revision "+string(FETE_REVISION),40) << "|" <<endl;
00119     outStream << 11*string(" ") << "|" << center("Last SVN commit "+string(FETE_VERSION_DATE),40) << "|" <<endl;
00120     outStream << 11*string(" ") << "+" << 40*string("-") << "+"<<endl;
00121     outStream << endl;
00122     if (this->size()>0) {
00123         outStream << center(60*string("="),62) << endl;
00124         outStream << center("Problems encountered during translation",62) << endl;
00125         outStream << center(60*string("="),62) << endl;
00126         for (MessageLogger::const_iterator it=begin(); it!=end(); ++it){
00127             stringstream buf;
00128             buf<<it->first;
00129             outStream << ljust(buf.str(),35) << it->second << endl;
00130         }
00131     } else {
00132         outStream << center(60*string("="),62) << endl;
00133         outStream << center("No problems encountered during translation!!",62) << endl;
00134         outStream << center(60*string("="),62) << endl;
00135     }
00136     return true;
00137 }

Generated on Thu Sep 7 10:30:06 2006 for fete -- From ENDFB6 To ENDL by doxygen 1.3.4