PT-Cooling-Log 1.0
PTCoolingLogViewer
|
00001 #include "PtEventView.hh" 00002 #include "LogViewer.hh" 00003 00004 #include <TVirtualPad.h> 00005 #include <TH1.h> 00006 #include <TAxis.h> 00007 #include <TLegend.h> 00008 #include <TLatex.h> 00009 00010 00011 #include <sqlite3.h> 00012 #include <cstdlib> 00013 #include <cstring> 00014 #include <iostream> 00015 #include <fstream> 00016 #include <sstream> 00017 #include <iomanip> 00018 00019 using namespace std; 00020 00021 map< double, std::string > PtEventView::events; 00022 00023 int PtEventView::parseEventLog( void *NotUsed, 00024 int argc, char **argv, char **azColName ){ 00025 if( argc != 5 ) return 1; 00026 PtEventView::events[ atof( argv[ 0 ] ) / 1000.0 ] = argv[ 1 ]; 00027 return 0; 00028 } 00029 00030 PtEventView::PtEventView() : 00031 PtView( "ptlog" ), latex_( NULL ) 00032 { 00033 this->title() = "Event"; 00034 latex_ = new TLatex; 00035 } 00036 00037 PtEventView::~PtEventView(){ 00038 } 00039 00040 void PtEventView::setRange(){ 00041 ymin_ = 0.0; 00042 ymax_ = 1.0; 00043 } 00044 00045 void PtEventView::drawGraph(){ 00046 string output = lv_->output() + "_event.dat"; 00047 cout << "Opening: " << output << endl; 00048 ofstream ofs( output.c_str() ); 00049 00050 double toff = lv_->toffset(); 00051 00052 latex_->SetTextAngle( 60.0 ); 00053 latex_->SetTextColor( kBlack ); 00054 latex_->SetTextSize( 0.8 * lv_->titleSize() ); 00055 00056 for( map< double, string >::iterator itr = PtEventView::events.begin(); 00057 itr != PtEventView::events.end(); 00058 itr++ ){ 00059 00060 double t = itr->first - toff; 00061 latex_->DrawLatex( t, 0.05, itr->second.c_str() ); 00062 ofs << setw(12) << (int) t 00063 << " " 00064 << itr->second << endl; 00065 } 00066 } 00067 00068 void PtEventView::drawLegend(){ 00069 00070 latex_->SetTextAngle( 0.0 ); 00071 latex_->SetTextColor( kGray ); 00072 latex_->SetTextSize( 0.8 * lv_->titleSize() ); 00073 latex_->DrawLatex( lv_->tmin() + 0.1 * ( lv_->tmax() - lv_->tmin() ), 0.9, 00074 string( lv_->startTime() + " - " + 00075 lv_->endTime() ).c_str() ); 00076 00077 } 00078 00079 void PtEventView::query( LogViewer *lv ){ 00080 00081 lv_ = lv; 00082 00083 // open event log file 00084 char *zErrMsg = 0; 00085 sqlite3 *ppDp; 00086 if( sqlite3_open( lv_->eventLog().c_str(), &ppDp ) != SQLITE_OK ) { 00087 cerr << "Failed to open and connect DB: " 00088 << lv_->eventLog() 00089 << endl; 00090 return; 00091 } 00092 00093 ostringstream ostr; 00094 ostr << "select * from " << this->name() << " " 00095 << "where datetime > " << 1000 * ( lv_->tmin() + lv_->toffset() ) 00096 << " and datetime < " << 1000 * ( lv_->tmax() + lv_->toffset() ); 00097 00098 if( sqlite3_exec( ppDp, ostr.str().c_str(), 00099 PtEventView::parseEventLog, 00100 0, 00101 &zErrMsg ) != SQLITE_OK ){ 00102 cerr << "Failed to exec SQL to event log file" << endl; 00103 } 00104 00105 // close log file 00106 if( sqlite3_close( ppDp ) != SQLITE_OK ){ 00107 cerr << "Failed to close DB file" << endl; 00108 } 00109 00110 }