1313// /
1414// / \author Kostas Alexopoulos ([email protected] )1515
16+ #include < fstream>
1617#include < iostream>
1718#include " Cru/Common.h"
1819#include " Cru/Constants.h"
@@ -40,6 +41,10 @@ class ProgramStatus: public Program
4041 virtual void addOptions (boost::program_options::options_description& options)
4142 {
4243 Options::addOptionCardId (options);
44+ options.add_options ()
45+ (" csv-out" ,
46+ po::value<std::string>(&mOptions .csvOut ),
47+ " Target CSV file to write output to" );
4348 }
4449
4550 virtual void run (const boost::program_options::variables_map& map)
@@ -64,21 +69,34 @@ class ProgramStatus: public Program
6469
6570 Cru::ReportInfo reportInfo = cruBar2->report ();
6671
67- std::ostringstream table;
72+ if (mOptions .csvOut != " " ) {
73+ mOutputToCsv = true ;
74+ }
6875
76+ std::ofstream csvOut;
77+
78+ std::ostringstream table;
6979 auto formatHeader = " %-9s %-16s %-10s %-14s %-15s %-10s %-14s %-14s %-8s %-19s\n " ;
7080 auto formatRow = " %-9s %-16s %-10s %-14s %-15s %-10s %-14.2f %-14.2f %-8s %-19.1f\n " ;
7181 auto header = (boost::format (formatHeader)
7282 % " Link ID" % " GBT Mode Tx/Rx" % " Loopback" % " GBT MUX" % " Datapath Mode" % " Datapath" % " RX freq(MHz)" % " TX freq(MHz)" % " Status" % " Optical power(uW)" ).str ();
7383 auto lineFat = std::string (header.length (), ' =' ) + ' \n ' ;
7484 auto lineThin = std::string (header.length (), ' -' ) + ' \n ' ;
7585
76- table << lineFat << header << lineThin;
86+ if (mOutputToCsv ) {
87+ csvOut.open (mOptions .csvOut );
88+ auto csvHeader = " Link ID,GBT Mode,Loopback,GBT Mux,Datapath Mode,Datapath,RX Freq(MHz),TX Freq(MHz),Status,Optical Power(uW)\n " ;
89+ csvOut << csvHeader;
90+ } else {
91+ table << lineFat << header << lineThin;
92+ }
7793
78- std::string clock = (reportInfo.ttcClock == 0 ? " TTC" : " Local" );;
79- std::cout << " ------------" << std::endl;
80- std::cout << clock << " clock" << std::endl;
81- std::cout << " ------------" << std::endl;
94+ if (!mOutputToCsv ) {
95+ std::string clock = (reportInfo.ttcClock == 0 ? " TTC" : " Local" );;
96+ std::cout << " ------------" << std::endl;
97+ std::cout << clock << " clock" << std::endl;
98+ std::cout << " ------------" << std::endl;
99+ }
82100
83101 for (const auto & el : reportInfo.linkMap ) {
84102 auto link = el.second ;
@@ -120,14 +138,33 @@ class ProgramStatus: public Program
120138
121139 float opticalPower = link.opticalPower ;
122140
123- auto format = boost::format (formatRow) % globalId % gbtTxRxMode % loopback % gbtMux % datapathMode % enabled % rxFreq % txFreq % linkStatus % opticalPower;
141+ if (mOutputToCsv ) {
142+ auto csvLine = std::to_string (globalId) + " ," + gbtTxRxMode + " ," + loopback + " ," + gbtMux + " ," + datapathMode + " ," + enabled + " ," +
143+ std::to_string (rxFreq) + " ," + std::to_string (txFreq) + " ," + linkStatus + " ," + std::to_string (opticalPower) + " \n " ;
144+ csvOut << csvLine;
145+ } else {
146+ auto format = boost::format (formatRow) % globalId % gbtTxRxMode % loopback % gbtMux % datapathMode % enabled % rxFreq % txFreq % linkStatus % opticalPower;
147+ table << format;
148+ }
124149
125- table << format;
126150 }
127151
128- table << lineFat;
129- std::cout << table.str ();
152+ if (mOutputToCsv ) {
153+ csvOut.close ();
154+ } else {
155+ auto lineFat = std::string (header.length (), ' =' ) + ' \n ' ;
156+ table << lineFat;
157+ std::cout << table.str ();
158+ }
130159 }
160+
161+ private:
162+
163+ struct OptionsStruct {
164+ std::string csvOut = " " ;
165+ } mOptions ;
166+
167+ bool mOutputToCsv = false ;
131168};
132169
133170int main (int argc, char ** argv)
0 commit comments