CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MakeDeanHTML.cc
Go to the documentation of this file.
1 //
3 // Dean Andrew Hidas <dhidas@fnal.gov>
4 //
5 // Created on: Thu Aug 27 11:57:16 CEST 2009
6 //
7 // Usage:
8 // MakeDeanHTML [InFile] [OutFile.html]
9 //
10 // Input Format:
11 // The input file format has the following formatting:
12 // line 1: specify col widths (the number of widths specified also
13 // indicates the number of columns
14 // The next lines if beginning with a "#' are printed directly
15 // After any '#'s:
16 // All lines are of the format: PlotName: Caption
17 // There must be exactly the number of entries corresponding
18 // to the number of cols followed by a blank line. Lines can be
19 // blank where you don't want a plot (for formatting reasons)
20 //
21 // Example of valid input file:
22 // 320 320 320
23 // #<h1>MyTitle</h1>
24 // #<p>maybe some links here or whatever</p>
25 // fig1a.gif: This is cap1a
26 // fig1b.gif: This is cap1b
27 // fig1c.gif: This is cap1c
28 //
29 // fig2a.gif: This is cap2a
30 //
31 // fig2c.gif: This is cap2c
32 //
33 // fig3a.gif: This is cap3a
34 // fig3b.gif: This is cap3b
35 // fig3c.gif: This is cap3c
36 //
37 //
39 
40 
41 #include <iostream>
42 #include <fstream>
43 #include <string>
44 #include <sstream>
45 #include <vector>
46 
47 
48 
49 
50 
51 int MakeDeanHTML (std::string const& InFileName, std::string const& OutFileName)
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 }
120 
121 
122 int main (int argc, char* argv[])
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:38