SundanceOut.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_OUT_H
00032 #define SUNDANCE_OUT_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "Teuchos_TestForException.hpp"
00036 #include "SundanceObjectWithVerbosity.hpp"
00037 #include "Teuchos_RefCountPtr.hpp"
00038 #include "Teuchos_FancyOStream.hpp"
00039 #include "Teuchos_MPIComm.hpp"
00040 
00041 namespace Teuchos
00042 {
00043 template <class T> class Array;
00044 }
00045 namespace Sundance
00046 {
00047 class Tabs;
00048 using namespace Teuchos;
00049 
00050 /**
00051  *
00052  */
00053 class Out
00054 {
00055 public:
00056       
00057   static void println(const std::string& str) 
00058     {
00059       if (hasLogFile()) *logFile() << str << std::endl;
00060       if (!suppressStdout()) os() << str << std::endl;
00061     }
00062 
00063   static void setLogFile(const std::string& filename)
00064     {
00065       logFile() = rcp(new std::ofstream(filename.c_str()));
00066       hasLogFile() = true;
00067     }
00068 
00069   static FancyOStream& os()
00070     {
00071       static RCP<std::ostream> os = rcp(&std::cout, false);
00072       static RCP<FancyOStream> rtn = fancyOStream(os);
00073       static bool first = true;
00074       if (first)
00075       {
00076         rtn->setShowProcRank(true);
00077         first = false;
00078       }
00079       return *rtn;
00080     }
00081 
00082   static FancyOStream& root()
00083     {
00084       static bool isRoot = MPIComm::world().getRank()==0;
00085       static RCP<FancyOStream> blackHole
00086         = rcp(new FancyOStream(rcp(new oblackholestream())));
00087 
00088       if (isRoot)
00089       {
00090         return os();
00091       }
00092       else
00093       {
00094         return *blackHole;
00095       }
00096     }
00097 
00098   static bool& suppressStdout() {static bool rtn=false; return rtn;}
00099 
00100 private:
00101   static bool& hasLogFile() {static bool rtn=false; return rtn;}
00102   static RCP<std::ostream>& logFile() {static RCP<std::ostream> rtn; return rtn;}
00103       
00104 };
00105 
00106 
00107 /** */
00108 void writeTable(std::ostream& os, const Tabs& tab,
00109   const Array<double>& a, int cols);
00110 /** */
00111 void writeTable(std::ostream& os, const Tabs& tab, 
00112   const Array<int>& a, int cols);
00113 
00114 }
00115 
00116 #define SUNDANCE_OUT(test, msg) \
00117   { \
00118     if (test) \
00119     { \
00120       TeuchosOStringStream omsg; \
00121       omsg << msg; \
00122       Out::println(omsg.str());                 \
00123     } \
00124   }
00125 
00126 
00127 #define SUNDANCE_VERB_EXTREME(msg) SUNDANCE_MSG4(this->verb(), msg)
00128 #define SUNDANCE_VERB_HIGH(msg) SUNDANCE_MSG3(this->verb(), msg)
00129 #define SUNDANCE_VERB_MEDIUM(msg) SUNDANCE_MSG2(this->verb(), msg)
00130 #define SUNDANCE_VERB_LOW(msg) SUNDANCE_MSG1(this->verb(), msg)
00131 
00132 #define SUNDANCE_HEADER_LINE "\n------------------------------------------------------------------\n"
00133 
00134 #define SUNDANCE_MSG(context, level, msg) SUNDANCE_OUT(this->verbLevel(context) >= level, msg)
00135 
00136 #define SUNDANCE_LEVEL1(context, msg) SUNDANCE_MSG(context, 1, msg)
00137 
00138 #define SUNDANCE_LEVEL2(context, msg) SUNDANCE_MSG(context, 2, msg)
00139 
00140 #define SUNDANCE_LEVEL3(context, msg) SUNDANCE_MSG(context, 3, msg)
00141 
00142 #define SUNDANCE_LEVEL4(context, msg) SUNDANCE_MSG(context, 4, msg)
00143 
00144 #define SUNDANCE_LEVEL5(context, msg) SUNDANCE_MSG(context, 5, msg)
00145 
00146 
00147 #define SUNDANCE_MSG1(level, msg) SUNDANCE_OUT(level >= 1, msg)
00148 
00149 #define SUNDANCE_MSG2(level, msg) SUNDANCE_OUT(level >= 2, msg)
00150 
00151 #define SUNDANCE_MSG3(level, msg) SUNDANCE_OUT(level >= 3, msg)
00152 
00153 #define SUNDANCE_MSG4(level, msg) SUNDANCE_OUT(level >= 4, msg)
00154 
00155 #define SUNDANCE_MSG5(level, msg) SUNDANCE_OUT(level >= 5, msg)
00156 
00157 #define SUNDANCE_BANNER1(level, tab, msg) \
00158   SUNDANCE_MSG1(level, tab \
00159     << "===================================================================");\
00160   SUNDANCE_MSG1(level, tab << std::endl << tab \
00161     << "  " << msg); \
00162   SUNDANCE_MSG1(level, tab << std::endl << tab\
00163     << "===================================================================");
00164 
00165 
00166 #define SUNDANCE_BANNER2(level, tab, msg) \
00167   SUNDANCE_MSG2(level, tab \
00168     << "-------------------------------------------------------------------");\
00169   SUNDANCE_MSG2(level, tab << msg); \
00170   SUNDANCE_MSG2(level, tab\
00171     << "-------------------------------------------------------------------");
00172 
00173 
00174 
00175 #define SUNDANCE_BANNER3(level, tab, msg) \
00176   SUNDANCE_MSG3(level, tab \
00177     << "-------------------------------------------------------------------");\
00178   SUNDANCE_MSG3(level, tab << std::endl << tab \
00179     << msg); \
00180   SUNDANCE_MSG3(level, tab << std::endl << tab\
00181     << "-------------------------------------------------------------------");
00182 
00183 #endif

Site Contact