CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DQMServices/Diagnostic/bin/MakeDeanHTML.cc

Go to the documentation of this file.
00001 
00002 //
00003 // Dean Andrew Hidas <dhidas@fnal.gov>
00004 //
00005 // Created on: Thu Aug 27 11:57:16 CEST 2009
00006 //
00007 // Usage:
00008 //   MakeDeanHTML [InFile] [OutFile.html]
00009 //
00010 // Input Format:
00011 //  The input file format has the following formatting:
00012 //    line 1: specify col widths (the number of widths specified also
00013 //            indicates the number of columns
00014 //    The next lines if beginning with a "#' are printed directly
00015 //    After any '#'s:
00016 //      All lines are of the format: PlotName: Caption
00017 //      There must be exactly the number of entries corresponding
00018 //      to the number of cols followed by a blank line.  Lines can be
00019 //      blank where you don't want a plot (for formatting reasons)
00020 //
00021 //    Example of valid input file:
00022 //      320 320 320
00023 //      #<h1>MyTitle</h1>
00024 //      #<p>maybe some links here or whatever</p>
00025 //      fig1a.gif: This is cap1a
00026 //      fig1b.gif: This is cap1b
00027 //      fig1c.gif: This is cap1c
00028 //     
00029 //      fig2a.gif: This is cap2a
00030 //     
00031 //      fig2c.gif: This is cap2c
00032 //     
00033 //      fig3a.gif: This is cap3a
00034 //      fig3b.gif: This is cap3b
00035 //      fig3c.gif: This is cap3c
00036 //
00037 //
00039 
00040 
00041 #include <iostream>
00042 #include <fstream>
00043 #include <string>
00044 #include <sstream>
00045 #include <vector>
00046 
00047 
00048 
00049 
00050 
00051 int MakeDeanHTML (std::string const& InFileName, std::string const& OutFileName)
00052 {
00053   // open the input file
00054   std::ifstream InFile(InFileName.c_str());
00055   if (!InFile.is_open()) {
00056     std::cerr << "ERROR: cannot open input file" << std::endl;
00057     return 1;
00058   }
00059 
00060   // open the output file
00061   std::ofstream OutFile(OutFileName.c_str());
00062   if (!OutFile.is_open()) {
00063     std::cerr << "ERROR: cannot open output file" << std::endl;
00064     return 1;
00065   }
00066 
00067   // print header
00068   OutFile << "<html>\n<body>\n\n";
00069 
00070   // Read first 3 line which contains widths (and is the number of cols)
00071   std::string FirstLine;
00072   std::getline(InFile, FirstLine);
00073   std::istringstream LineStream;
00074   LineStream.str(FirstLine);
00075   std::string Width;
00076   std::vector<std::string> Widths;
00077   while (LineStream >> Width) {
00078     Widths.push_back(Width);
00079   }
00080   while (InFile.peek() == '#') {
00081     std::getline(InFile, FirstLine);
00082     OutFile << std::string(FirstLine.begin()+1, FirstLine.end()) << std::endl;
00083   }
00084 
00085   OutFile << "<hr>\n<table>\n\n";
00086 
00087   while (!InFile.eof()) {
00088     OutFile << "  <tr>\n";
00089     std::string OneLine;
00090     for (size_t iCol = 0; iCol != Widths.size(); ++iCol) {
00091       std::getline(InFile, OneLine);
00092       bool const BlankLine = OneLine == "" ? true : false;
00093 
00094       OutFile << "    <td width=\"" << Widths[iCol] << "\">\n";
00095       if (!BlankLine) {
00096         std::string const PlotName(OneLine.begin(), OneLine.begin()+OneLine.find(":"));
00097         std::string const ThumbName = std::string(PlotName.begin(), PlotName.begin() + PlotName.find(".gif")) + "_small.gif";
00098         std::string const Caption(OneLine.begin()+OneLine.find(":")+1, OneLine.end());
00099         OutFile << "      <center>\n";
00100         OutFile << "        <a href=\"" << PlotName << "\">\n";
00101         OutFile << "        <img src=\"" << ThumbName << "\">\n";
00102         OutFile << "        </a><br>\n";
00103         OutFile << "        " << Caption << "\n";
00104         OutFile << "      </center>\n";
00105       }
00106       OutFile << "    </td>\n";
00107     }
00108     OutFile << "  </tr>\n\n";
00109     // Get a blank line
00110     std::getline(InFile, OneLine);
00111   }
00112 
00113   OutFile << "</table>\n\n</body>\n</html>";
00114 
00115   OutFile.close();
00116   InFile.close();
00117 
00118   return 0;
00119 }
00120 
00121 
00122 int main (int argc, char* argv[])
00123 {
00124   if (argc != 3) {
00125     std::cerr << "Usage: " << argv[0] << " [InFile] [OutFile]" << std::endl;
00126     return 1;
00127   }
00128 
00129   MakeDeanHTML(argv[1], argv[2]);
00130 
00131   return 0;
00132 }