Functions | Variables
HtmlCosmic.C File Reference
#include <iostream>
#include <string.h>
#include "Riostream.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TImage.h"
#include "TKey.h"
#include "TString.h"
#include "TSystem.h"

Go to the source code of this file.

Functions

void InitializeHtml (char *file)
 Write the initial portion of the html file and set up top level directory. More...
 
void WriteDirectoryStruct (TString inPath, TFile *inFile)
 Set up subdirectory structure of html file and local area. More...
 
void GetPOTInfo (TString inPath, TFile *inFile)
 Get the amount of POT from input file. More...
 
void ScanRootfile (TString inPath, TFile *inFile)
 Recursively look for each histogram in the inPath directory. More...
 
void Finalize ()
 Write the final lines of the html file. More...
 
void HtmlCosmic (char *file)
 

Variables

TString htmlpath
 Path to html page and local location of saved images. More...
 
TString subDir
 Name of current subdirectory. More...
 
ofstream * histhtml
 Stream to send html code/text/commands to html file. More...
 
double NormPOTCurrent
 Amount of POT used to generate input file. More...
 

Function Documentation

void Finalize ( )

Write the final lines of the html file.

Definition at line 230 of file HtmlCosmic.C.

References allTimeWatchdog::endl, and histhtml.

Referenced by HtmlCosmic().

231 {
232  *histhtml << "</body></html>" << std::endl;
233  histhtml->close();
234 
235  return;
236 }
ofstream * histhtml
Stream to send html code/text/commands to html file.
Definition: HtmlCosmic.C:24
void GetPOTInfo ( TString  inPath,
TFile *  inFile 
)

Get the amount of POT from input file.

Definition at line 123 of file HtmlCosmic.C.

References om::cout, allTimeWatchdog::endl, NormPOTCurrent, and string.

Referenced by HtmlCosmic().

124 {
125  // Name of the histogram to get POT information from
126  std::string histPOT = "fSampleTime";
127 
128  if(inFile->cd(inPath)) {
129  TKey* keyPOT = (TKey*)gDirectory->GetListOfKeys()->FindObject(histPOT.c_str());
130 
131  if(keyPOT) {
132  TH1* hPOT = (TH1*)keyPOT->ReadObj();
133  NormPOTCurrent = hPOT->Integral();
134  std::cout << "Total sample time in current release " << NormPOTCurrent << std::endl;
135  }
136  else {
137  NormPOTCurrent = 1.;
138  }
139  }
140  else {
141  std::cout << "POT info not available!" << std::endl;
142  NormPOTCurrent = 1.;
143  }
144 
145  return;
146 }
double NormPOTCurrent
Amount of POT used to generate input file.
Definition: HtmlCosmic.C:26
ifstream inFile
Definition: AnaPlotMaker.h:34
OStream cout
Definition: OStream.cxx:6
enum BeamMode string
void HtmlCosmic ( char *  file)

Definition at line 44 of file HtmlCosmic.C.

References Finalize(), GetPOTInfo(), inFile, InitializeHtml(), ScanRootfile(), string, and WriteDirectoryStruct().

45 {
46  TString topPath = "/"; // Path to top directory of histogram locations/subdirectories
47 
48  // Open the file
49  TFile* inFile = new TFile(file);
50 
51  // Get the base file name
52  std::string baseFile(file);
53  baseFile.erase(0, baseFile.rfind("/"));
54 
55  InitializeHtml((char*)baseFile.c_str());
56  WriteDirectoryStruct(topPath, inFile);
57  GetPOTInfo("cosmicana", inFile);
58  ScanRootfile(topPath, inFile);
59  Finalize();
60 
61  return;
62 }
ifstream inFile
Definition: AnaPlotMaker.h:34
void WriteDirectoryStruct(TString inPath, TFile *inFile)
Set up subdirectory structure of html file and local area.
Definition: HtmlCosmic.C:93
void GetPOTInfo(TString inPath, TFile *inFile)
Get the amount of POT from input file.
Definition: HtmlCosmic.C:123
void Finalize()
Write the final lines of the html file.
Definition: HtmlCosmic.C:230
TFile * file
Definition: cellShifts.C:17
void InitializeHtml(char *file)
Write the initial portion of the html file and set up top level directory.
Definition: HtmlCosmic.C:65
void ScanRootfile(TString inPath, TFile *inFile)
Recursively look for each histogram in the inPath directory.
Definition: HtmlCosmic.C:149
enum BeamMode string
void InitializeHtml ( char *  file)

Write the initial portion of the html file and set up top level directory.

Definition at line 65 of file HtmlCosmic.C.

References allTimeWatchdog::endl, histhtml, htmlpath, and confusionMatrixTree::out.

Referenced by HtmlCosmic().

66 {
67  // Set up html files for ease of image viewing
68  gSystem->Exec("mkdir html_out/");
69 
70  char commandHelper[256];
71  sprintf(commandHelper, "mkdir html_out/%s/", file);
72  gSystem->Exec(commandHelper);
73 
74  sprintf(commandHelper, "html_out/%s/", file);
75  htmlpath = commandHelper;
76  histhtml = new ofstream(htmlpath + "index.html", ios::out);
77 
78  *histhtml << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
79  << "<html>\n <head>\n"
80  << "<title>" << file << "</title>\n"
81  << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n"
82  << "</head>\n<body>\n" << std::endl;
83 
84  *histhtml << "<a name=\"pagetop\" ></a>\n"
85  << "<h1>" << file << "</h1>\n" << std::endl;
86 
87  *histhtml << "Skip to:\n" << std::endl;
88 
89  return;
90 }
ofstream * histhtml
Stream to send html code/text/commands to html file.
Definition: HtmlCosmic.C:24
TString htmlpath
Path to html page and local location of saved images.
Definition: HtmlCosmic.C:21
TFile * file
Definition: cellShifts.C:17
void ScanRootfile ( TString  inPath,
TFile *  inFile 
)

Recursively look for each histogram in the inPath directory.

Definition at line 149 of file HtmlCosmic.C.

References plot_validation_datamc::c, om::cout, allTimeWatchdog::endl, analysePickle::hist, histhtml, htmlpath, HTMLTools::img(), findDuplicateFiles::key, NormPOTCurrent, and subDir.

Referenced by HtmlCosmic().

150 {
151  TString saveName;
152 
153  inFile->cd(inPath);
154  TDirectory* current_sourcedir = gDirectory;
155 
156  // Loop over all keys in this directory and save all histos found as PNG images
157  TIter nextkey(current_sourcedir->GetListOfKeys());
158  TKey* key;
159  TKey* oldkey = 0;
160 
161  while((key = (TKey*)nextkey())) {
162  // Keep only the highest cycle number for each key
163  if(oldkey && !strcmp(oldkey->GetName(),key->GetName())) { continue; }
164 
165  // Read object from the input file
166  inFile->cd(inPath);
167  TObject* obj = key->ReadObj();
168 
169  if(obj->IsA()->InheritsFrom(TH1::Class())) { // Could be TH1, TH2, or TH3
170  std::cout << "Exporting histogram " << obj->GetName() << std::endl;
171  TH1* hist = (TH1*)obj;
172 
173  TCanvas* c = new TCanvas("c", "c", 800, 600);
174  saveName = subDir + "/";
175 
176  TImage* img = TImage::Create();
177 
178  // Add POT scale to energy histogram axis label
179  if(strstr(hist->GetName(), "Enu")) {
180  char yAxisLabel[256];
181  sprintf(yAxisLabel, "Events / %.2E POT", NormPOTCurrent);
182  hist->GetYaxis()->SetTitle(yAxisLabel);
183  }
184 
185  // Use colz option for TH2 objects
186  if(obj->IsA()->InheritsFrom(TH2::Class())) {
187  hist->Draw("colz");
188  }
189  else {
190  hist->Draw();
191  }
192 
193  img->FromPad(c);
194  img->WriteImage(htmlpath + saveName + hist->GetName() + ".png");
195 
196  *histhtml << "<p>" << subDir << "-"<< hist->GetName() << std::endl;
197  *histhtml << "<p><p><img src=\"" << saveName + hist->GetName() << ".png\">" << std::endl;
198  *histhtml << "<a href=\"#pagetop\" >Back to top</a>\n" << std::endl;
199 
200  delete c;
201  delete img;
202  } // end of conditonal if object is TH1
203  else if(obj->IsA()->InheritsFrom(TDirectory::Class())) { // It's a subdirectory
204  subDir = obj->GetName();
205  std::cout << "Found subdirectory " << subDir << std::endl;
206 
207  // Make local directories for the images
208  gSystem->Exec("mkdir " + htmlpath + subDir);
209 
210  *histhtml << "<a name=\"" << subDir << "\">\n"
211  << "<h2>" << subDir << "</h2>\n" << std::endl;
212 
213  // Create a new subdirectory
214  TString newDir = obj->GetName();
215 
216  ScanRootfile(newDir, inFile);
217  }
218  else { // Object is of no type that this macro can handle
219  std::cout << "Unknown object type, name: " << obj->GetName()
220  << " title: " << obj->GetTitle() << std::endl;
221  }
222 
223  delete obj;
224  } // end of while loop over TKeys
225 
226  return;
227 }
ofstream * histhtml
Stream to send html code/text/commands to html file.
Definition: HtmlCosmic.C:24
double NormPOTCurrent
Amount of POT used to generate input file.
Definition: HtmlCosmic.C:26
TString subDir
Name of current subdirectory.
Definition: HtmlCosmic.C:22
ifstream inFile
Definition: AnaPlotMaker.h:34
def img(path, mouseover="")
Definition: HTMLTools.py:36
TString htmlpath
Path to html page and local location of saved images.
Definition: HtmlCosmic.C:21
OStream cout
Definition: OStream.cxx:6
void ScanRootfile(TString inPath, TFile *inFile)
Recursively look for each histogram in the inPath directory.
Definition: HtmlCosmic.C:149
void WriteDirectoryStruct ( TString  inPath,
TFile *  inFile 
)

Set up subdirectory structure of html file and local area.

Definition at line 93 of file HtmlCosmic.C.

References allTimeWatchdog::endl, histhtml, findDuplicateFiles::key, and subDir.

Referenced by HtmlCosmic().

94 {
95  inFile->cd(inPath);
96  TDirectory* current_sourcedir = gDirectory;
97 
98  // Loop over all keys in this directory and write the subdir index on the html file
99  TIter nextkey(current_sourcedir->GetListOfKeys());
100  TKey* key;
101  TKey* oldkey = 0;
102 
103  while((key = (TKey*)nextkey())) {
104  // Keep only the highest cycle number for each key
105  if(oldkey && !strcmp(oldkey->GetName(),key->GetName())) { continue; }
106 
107  // Read object from the input file
108  inFile->cd(inPath);
109  TObject* obj = key->ReadObj();
110 
111  if(obj->IsA()->InheritsFrom(TDirectory::Class())) { // It's a subdirectory
112  subDir = obj->GetName();
113  *histhtml << "<li><a href=\"#" << subDir << "\">" << subDir << "</a></li>\n" << std::endl;
114  }
115 
116  delete obj;
117  } // end of while loop over TKeys
118 
119  return;
120 }
ofstream * histhtml
Stream to send html code/text/commands to html file.
Definition: HtmlCosmic.C:24
TString subDir
Name of current subdirectory.
Definition: HtmlCosmic.C:22
ifstream inFile
Definition: AnaPlotMaker.h:34

Variable Documentation

ofstream* histhtml

Stream to send html code/text/commands to html file.

Definition at line 24 of file HtmlCosmic.C.

Referenced by Finalize(), InitializeHtml(), ScanRootfile(), and WriteDirectoryStruct().

TString htmlpath

Path to html page and local location of saved images.

Macro to export histogram content of a ROOT file to a html page Based on $ROOTSYS/bin/hadd.C Raphael Schroeter, May 2011

Definition at line 21 of file HtmlCosmic.C.

Referenced by InitializeHtml(), and ScanRootfile().

double NormPOTCurrent

Amount of POT used to generate input file.

Definition at line 26 of file HtmlCosmic.C.

Referenced by GetPOTInfo(), and ScanRootfile().

TString subDir

Name of current subdirectory.

Definition at line 22 of file HtmlCosmic.C.

Referenced by ScanRootfile(), and WriteDirectoryStruct().