Public Member Functions | Private Attributes | List of all members
TexBuilder Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-03-03/Calibration/calibana/TexBuilder.h"

Public Member Functions

 TexBuilder (std::string filename, std::string title, std::string authors, std::string abstract)
 
 ~TexBuilder ()
 
void AddText (std::string text)
 
void Section (std::string secname)
 
void SubSection (std::string subsecname)
 
void SectionNoNum (std::string secname)
 
void SubSectionNoNum (std::string subsecname)
 
void AddFigureRow (std::vector< std::string > figure, std::vector< std::string > caption, std::vector< std::string > label)
 
void WriteHeader ()
 
void NewPage ()
 
void AddTable (Table table, bool drawnow=false, bool makecsv=true)
 
void DrawTable (std::string tabname)
 
void Close ()
 

Private Attributes

std::string fFileName
 
std::string fTitle
 
std::string fAuthors
 
std::string fAbstract
 
std::ofstream fTex
 
std::map< std::string, TablefTables
 

Detailed Description

Definition at line 15 of file TexBuilder.h.

Constructor & Destructor Documentation

TexBuilder::TexBuilder ( std::string  filename,
std::string  title,
std::string  authors,
std::string  abstract 
)

Definition at line 56 of file TexBuilder.h.

References om::cout, allTimeWatchdog::endl, fTex, and WriteHeader().

61  , fTitle(title)
62  , fAuthors(authors)
63  , fAbstract(abstract)
64 {
65  fTex.open(filename);
66 
67  if(!fTex.is_open())
68  std::cout << "\nFailed to open " << filename << std::endl;
69  else
70  std::cout << "\nBuilding Tex in " << filename << std::endl;
71 
72  WriteHeader();
73 
74  fTex << "\n\\newpage\n";
75 }
void WriteHeader()
Definition: TexBuilder.h:173
std::string fAbstract
Definition: TexBuilder.h:48
string filename
Definition: shutoffs.py:106
std::string fAuthors
Definition: TexBuilder.h:47
std::ofstream fTex
Definition: TexBuilder.h:49
OStream cout
Definition: OStream.cxx:6
std::string fTitle
Definition: TexBuilder.h:46
std::string fFileName
Definition: TexBuilder.h:45
TexBuilder::~TexBuilder ( )

Definition at line 77 of file TexBuilder.h.

78 {
79  // doesn't always work here?
80  //fTex << "\\end{document}\n";
81  //fTex.close();
82 }

Member Function Documentation

void TexBuilder::AddFigureRow ( std::vector< std::string figure,
std::vector< std::string caption,
std::vector< std::string label 
)

Definition at line 98 of file TexBuilder.h.

References om::cout, allTimeWatchdog::endl, MakeMiniprodValidationCuts::f, fTex, and gen_hdf5record::size.

Referenced by ValidCalibPDF::DiblockTex(), MEUPerCell::DriftTex(), MEUPerFEB::DriftTex(), ValidCalibPDF::DriftTex(), and ValidCalibPDF::EssentialComparisonTex().

101 {
102  unsigned short nfig = figure.size();
103  if( nfig!= caption.size() ){
104  std::cout << "Bad number of captions, skipping " << figure[0] << std::endl; return; }
105  if( nfig!= label.size() ){
106  std::cout << "Bad number of labels, skipping " << figure[0] << std::endl; return; }
107 
108  float size;
109  if (nfig==1) size = 0.2; // height
110  else if(nfig==2) size = 0.49; // width
111  else if(nfig==3) size = 0.32; // width
112  else if(nfig==4) size = 0.24; // width
113 
114 
115  fTex << "\\begin{figure}[h!]\n";
116 
117  // set single figures by height
118  if(nfig==1){
119  fTex << "\\centering\n";
120  fTex << " \\includegraphics[height="<<size<<"\\linewidth]{" << figure[0] <<".pdf}\n";
121  if(caption[0]!="")
122  fTex << " \\caption{" << caption[0] << "}\n";
123  if(label[0]!="")
124  fTex << " \\label{fig:"<< label[0] << "}\n";
125  } else {
126 
127  // set multiple subfigures by width
128  for( unsigned short f=0; f<nfig; f++){
129  fTex << " \\begin{subfigure}{"<<size<<"\\textwidth}\n";
130  fTex << " \\includegraphics[width=\\linewidth]{" << figure[f] <<".pdf}\n";
131  if(caption[f]!="")
132  fTex << " \\caption{" << caption[f] << "}\n";
133  if(label[f]!="")
134  fTex << " \\label{fig:"<< label[f] << "}\n";
135  fTex << " \\end{subfigure}\n";
136  if(f<nfig-1)
137  fTex << " \\quad\n";
138 
139  } // each figure
140  }
141 
142  fTex << "\\end{figure}\n";
143 
144  return;
145 }
const char * label
std::ofstream fTex
Definition: TexBuilder.h:49
OStream cout
Definition: OStream.cxx:6
void TexBuilder::AddTable ( Table  table,
bool  drawnow = false,
bool  makecsv = true 
)

Definition at line 237 of file TexBuilder.h.

References plot_validation_datamc::c, om::cout, Table::csvdir, Table::csvname, DrawTable(), allTimeWatchdog::endl, fTables, Table::header, MECModelEnuComparisons::i, Table::name, check_grl::row, Table::rows, and getGoodRuns4SAM::table.

Referenced by ValidCalibPDF::AbsoluteCalibration(), generic.views.Pages.ComparisonTablePage::AddContent(), and ValidCalibPDF::CalibSummaryTable().

238 {
239  if(fTables.count(table.name)){
240  std::cout << "Table " << table.name << " already exists, skip" << std::endl;
241  return;
242  }
243  // Rester the new table
244  fTables[table.name] = table;
245 
246  // Immediately make CSV
247  if(makecsv){
248  ofstream csv (Form("%s/%s",
249  table.csvdir.c_str(),
250  table.csvname.c_str()) );
251  if(!csv.is_open()) std::cout << "File not found" << std::endl;
252 
253  csv << "#";
254  for(size_t i=0; i<table.header.size(); i++){
255  csv << table.header[i];
256  if(i!=table.header.size()-1) csv << ",";
257  }
258  csv << std::endl;
259 
260  for( auto& row: table.rows ){
261  for( size_t c=0; c<row.size(); c++ ){
262  csv << row[c];
263  if(c!=row.size()-1) csv << ",";
264  }
265  csv << std::endl;
266  }
267  csv.close();
268  }
269 
270  // Maybe add to Tex now
271  if(addnow) DrawTable(table.name);
272 }
std::vector< std::string > header
Definition: TexBuilder.h:7
void DrawTable(std::string tabname)
Definition: TexBuilder.h:276
std::string name
Definition: TexBuilder.h:4
std::vector< std::vector< std::string > > rows
Definition: TexBuilder.h:8
std::map< std::string, Table > fTables
Definition: TexBuilder.h:51
std::string csvdir
Definition: TexBuilder.h:11
OStream cout
Definition: OStream.cxx:6
std::string csvname
Definition: TexBuilder.h:10
void TexBuilder::AddText ( std::string  text)

Definition at line 92 of file TexBuilder.h.

References fTex, and MakeMiniprodValidationCuts::text.

Referenced by ValidCalibPDF::MakeTex().

93 {
94  fTex << text;
95 }
std::ofstream fTex
Definition: TexBuilder.h:49
void TexBuilder::Close ( )

Definition at line 85 of file TexBuilder.h.

References fTex.

Referenced by ValidCalibPDF::MakeTex().

86 {
87  fTex << "\\end{document}\n";
88  fTex.close();
89 }
std::ofstream fTex
Definition: TexBuilder.h:49
void TexBuilder::DrawTable ( std::string  tabname)

Definition at line 276 of file TexBuilder.h.

References plot_validation_datamc::c, Table::caption, getBrightness::cell, om::cout, allTimeWatchdog::endl, fTables, fTex, stan::math::head(), Table::header, Table::name, check_grl::row, Table::rows, string, and confusionMatrixTree::t.

Referenced by AddTable(), and ValidCalibPDF::MakeTex().

277 {
278  if(!fTables.count(tabname)){
279  std::cout << "no table for " << tabname << ", skip" << std::endl;
280  for(auto& t : fTables) std::cout << " " << t.first << std::endl;
281  return;
282  }
283  const Table &tab = fTables[tabname];
284 
285  // center all for now
286  std::string tabulararg = "|";
287  for(auto& cell : tab.header) tabulararg += "c|";
288 
289  fTex << "\\begin{center}\n";
290  fTex << "\\begin{table}[h!]\n";
291  fTex << "\\begin{tabular}{ " << tabulararg << "}\n\n";
292 
293  fTex << "\\hline" << std::endl;
294  for( size_t c=0; c<tab.header.size(); c++ ){
295  std::string head = tab.header[c];
296  std::replace( head.begin(), head.end(), '_', ' ');
297  if( c<tab.header.size()-1 )
298  fTex << head << " & ";
299  else
300  fTex << head << "\\\\ \\hline" << std::endl;
301  }
302 
303  for( auto& row: tab.rows ){
304  for( size_t c=0; c<row.size(); c++ ){
305  std::string cell = row[c];
306  std::replace( cell.begin(), cell.end(), '_', ' ');
307  if( c<row.size()-1 )
308  fTex << cell << " & ";
309  else
310  fTex << cell;
311  }
312  fTex << "\\\\ \\hline" << std::endl;
313  }
314 
315  fTex << "\\end{tabular}\n";
316  if( tab.caption!="" )
317  fTex << "\\caption{" << tab.caption << "}\n";
318  fTex << "\\label{tab:" << tab.name << "}\n";
319  fTex << "\\end{table}\n";
320  fTex << "\\end{center}\n\n";
321 
322 }
std::vector< std::string > header
Definition: TexBuilder.h:7
std::string caption
Definition: TexBuilder.h:6
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Definition: head.hpp:24
std::string name
Definition: TexBuilder.h:4
std::vector< std::vector< std::string > > rows
Definition: TexBuilder.h:8
std::map< std::string, Table > fTables
Definition: TexBuilder.h:51
std::ofstream fTex
Definition: TexBuilder.h:49
OStream cout
Definition: OStream.cxx:6
enum BeamMode string
void TexBuilder::NewPage ( )

Definition at line 165 of file TexBuilder.h.

References fTex.

Referenced by ValidCalibPDF::DiblockTex(), MEUPerCell::DriftTex(), MEUPerFEB::DriftTex(), ValidCalibPDF::DriftTex(), ValidCalibPDF::EssentialComparisonTex(), and ValidCalibPDF::MakeTex().

166 {
167  fTex << "\n\\newpage\n";
168 }
std::ofstream fTex
Definition: TexBuilder.h:49
void TexBuilder::Section ( std::string  secname)

Definition at line 149 of file TexBuilder.h.

References fTex.

Referenced by ValidCalibPDF::MakeTex().

150 {
151  fTex << "\\section{"+name+"}\n\n";
152 }
const XML_Char * name
Definition: expat.h:151
std::ofstream fTex
Definition: TexBuilder.h:49
void TexBuilder::SectionNoNum ( std::string  secname)

Definition at line 153 of file TexBuilder.h.

References fTex.

Referenced by MEUPerCell::DriftTex(), and MEUPerFEB::DriftTex().

154 {
155  fTex << "\\section*{"+name+"}\n\n";
156 }
const XML_Char * name
Definition: expat.h:151
std::ofstream fTex
Definition: TexBuilder.h:49
void TexBuilder::SubSection ( std::string  subsecname)

Definition at line 157 of file TexBuilder.h.

References fTex.

Referenced by ValidCalibPDF::MakeTex().

158 {
159  fTex << "\\subsection{"+name+"}\n\n";
160 }
const XML_Char * name
Definition: expat.h:151
std::ofstream fTex
Definition: TexBuilder.h:49
void TexBuilder::SubSectionNoNum ( std::string  subsecname)

Definition at line 161 of file TexBuilder.h.

References fTex.

Referenced by MEUPerCell::DriftTex().

162 {
163  fTex << "\\subsection*{"+name+"}\n\n";
164 }
const XML_Char * name
Definition: expat.h:151
std::ofstream fTex
Definition: TexBuilder.h:49
void TexBuilder::WriteHeader ( )

Definition at line 173 of file TexBuilder.h.

References allTimeWatchdog::endl, fAbstract, fAuthors, fTex, and fTitle.

Referenced by TexBuilder().

174 {
175 
176  fTex << "\\documentclass[12pt]{article}\n";
177 
178  fTex << "\\usepackage[utf8]{inputenc}\n";
179  fTex << "\\usepackage{graphicx}\n";
180  fTex << "\\usepackage{caption}\n";
181  fTex << "\\usepackage{subcaption}\n";
182  fTex << "\\usepackage[dvipsnames,table]{xcolor}\n";
183  fTex << "\\usepackage[a4paper, margin=1.5cm]{geometry}\n";
184  fTex << "\\usepackage{fancyhdr}\n";
185  fTex << "\\usepackage[colorlinks=true]{hyperref}\n";
186 
187  fTex << "\\newcommand{\\mycolor}{WildStrawberry}\n";
188  fTex << "\\newcommand{\\myhighlightA}{Goldenrod!30!white}\n";
189  fTex << "\\newcommand{\\myhighlightB}{Apricot!50!white}\n";
190  fTex << "\\newcommand{\\myhighlightC}{Rhodamine!30!white}\n";
191 
192  fTex << "\\pagestyle{fancy}\n";
193  fTex << "\\rhead{\\nouppercase{\\leftmark}}\n";
194 
195  fTex << "\\usepackage{etoolbox}\n";
196  fTex << "\\renewcommand{\\headrulewidth}{1pt}\n";
197  fTex << "\\fancyhead[CO,CE]{\\hyperlink{toc}{Back To Top}}\n";
198  fTex << "%\\fancyhead[LO,LE]{\\hyperlink{sec}{Section Top}}\n";
199 
200  fTex << "\\makeatletter";
201  fTex << "\\patchcmd{\\@fancyhead}{\\rlap}{\\color{\\mycolor!60!white}\\rlap}{}{}\n";
202  fTex << "\\patchcmd{\\headrule}{\\hrule}{\\color{\\mycolor!60!white}\\hrule}{}{}\n";
203  fTex << "\\patchcmd{\\@fancyfoot}{\\rlap}{\\color{\\mycolor!60!white}\\rlap}{}{}\n";
204  fTex << "\\patchcmd{\\footrule}{\\hrule}{\\color{\\mycolor!60!white}\\hrule}{}{}\n";
205  fTex << "\\makeatother";
206  fTex << "\\usepackage{sectsty}\n";
207  fTex << "\\allsectionsfont{\\color{\\mycolor}\\bfseries}\n";
208  fTex << "\\usepackage{longtable}\n";
209 
210  fTex << "\\hypersetup{linkcolor=black}\n";
211 
212  fTex << "\\usepackage{geometry}\n";
213  fTex << "\\geometry{headheight=15pt}\n";
214 
215  fTex << "\\setlength{\\intextsep}{0.005\\textheight}\n";
216 
217  fTex << std::endl;
218  fTex << "\\begin{document}\n\n";
219  fTex << std::endl;
220 
221  fTex << "\\title{\\textcolor{\\mycolor}{\\bf " << fTitle << "}}\n";
222  fTex << "\\author{" << fAuthors << "}\n";
223  fTex << "\\date{\\today}\n\n";
224 
225  fTex << "\\maketitle\n\n";
226 
227  fTex << "\\begin{abstract}\n";
228  fTex << fAbstract;
229  fTex << "\\end{abstract}\n\n";
230 
231  fTex << "\\tableofcontents\n\n";
232 
233 } // WriteHeader()
std::string fAbstract
Definition: TexBuilder.h:48
std::string fAuthors
Definition: TexBuilder.h:47
std::ofstream fTex
Definition: TexBuilder.h:49
std::string fTitle
Definition: TexBuilder.h:46

Member Data Documentation

std::string TexBuilder::fAbstract
private

Definition at line 48 of file TexBuilder.h.

Referenced by WriteHeader().

std::string TexBuilder::fAuthors
private

Definition at line 47 of file TexBuilder.h.

Referenced by WriteHeader().

std::string TexBuilder::fFileName
private

Definition at line 45 of file TexBuilder.h.

std::map< std::string, Table > TexBuilder::fTables
private

Definition at line 51 of file TexBuilder.h.

Referenced by AddTable(), and DrawTable().

std::ofstream TexBuilder::fTex
private
std::string TexBuilder::fTitle
private

Definition at line 46 of file TexBuilder.h.

Referenced by WriteHeader().


The documentation for this class was generated from the following file: