CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
MakeDeanHTML.cc File Reference
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 
int MakeDeanHTML (std::string const &InFileName, std::string const &OutFileName)
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 122 of file MakeDeanHTML.cc.

References dtNoiseDBValidation_cfg::cerr, and MakeDeanHTML().

123 {
124  if (argc != 3) {
125  std::cerr << "Usage: " << argv[0] << " [InFile] [OutFile]" << std::endl;
126  return 1;
127  }
128 
129  MakeDeanHTML(argv[1], argv[2]);
130 
131  return 0;
132 }
int MakeDeanHTML(std::string const &InFileName, std::string const &OutFileName)
Definition: MakeDeanHTML.cc:51
tuple argc
Definition: dir2webdir.py:41
int MakeDeanHTML ( std::string const &  InFileName,
std::string const &  OutFileName 
)

Definition at line 51 of file MakeDeanHTML.cc.

References dtNoiseDBValidation_cfg::cerr.

Referenced by main().

52 {
53  // open the input file
54  std::ifstream InFile(InFileName.c_str());
55  if (!InFile.is_open()) {
56  std::cerr << "ERROR: cannot open input file" << std::endl;
57  return 1;
58  }
59 
60  // open the output file
61  std::ofstream OutFile(OutFileName.c_str());
62  if (!OutFile.is_open()) {
63  std::cerr << "ERROR: cannot open output file" << std::endl;
64  return 1;
65  }
66 
67  // print header
68  OutFile << "<html>\n<body>\n\n";
69 
70  // Read first 3 line which contains widths (and is the number of cols)
71  std::string FirstLine;
72  std::getline(InFile, FirstLine);
73  std::istringstream LineStream;
74  LineStream.str(FirstLine);
75  std::string Width;
76  std::vector<std::string> Widths;
77  while (LineStream >> Width) {
78  Widths.push_back(Width);
79  }
80  while (InFile.peek() == '#') {
81  std::getline(InFile, FirstLine);
82  OutFile << std::string(FirstLine.begin()+1, FirstLine.end()) << std::endl;
83  }
84 
85  OutFile << "<hr>\n<table>\n\n";
86 
87  while (!InFile.eof()) {
88  OutFile << " <tr>\n";
89  std::string OneLine;
90  for (size_t iCol = 0; iCol != Widths.size(); ++iCol) {
91  std::getline(InFile, OneLine);
92  bool const BlankLine = OneLine == "" ? true : false;
93 
94  OutFile << " <td width=\"" << Widths[iCol] << "\">\n";
95  if (!BlankLine) {
96  std::string const PlotName(OneLine.begin(), OneLine.begin()+OneLine.find(":"));
97  std::string const ThumbName = std::string(PlotName.begin(), PlotName.begin() + PlotName.find(".gif")) + "_small.gif";
98  std::string const Caption(OneLine.begin()+OneLine.find(":")+1, OneLine.end());
99  OutFile << " <center>\n";
100  OutFile << " <a href=\"" << PlotName << "\">\n";
101  OutFile << " <img src=\"" << ThumbName << "\">\n";
102  OutFile << " </a><br>\n";
103  OutFile << " " << Caption << "\n";
104  OutFile << " </center>\n";
105  }
106  OutFile << " </td>\n";
107  }
108  OutFile << " </tr>\n\n";
109  // Get a blank line
110  std::getline(InFile, OneLine);
111  }
112 
113  OutFile << "</table>\n\n</body>\n</html>";
114 
115  OutFile.close();
116  InFile.close();
117 
118  return 0;
119 }