00001 #include <TSystem.h>
00002 #include <TApplication.h>
00003 #include <TGClient.h>
00004 #include <TCanvas.h>
00005 #include <TF1.h>
00006 #include <TH1D.h>
00007 #include <TRandom.h>
00008 #include <TGButton.h>
00009 #include <TGTextEntry.h>
00010 #include <TGMenu.h>
00011 #include <TGLabel.h>
00012 #include <TRootEmbeddedCanvas.h>
00013 #include <TGFSContainer.h>
00014 #include <iostream>
00015 #include <TLatex.h>
00016 #include "example2a.h"
00017
00018 #include <unistd.h>
00019 #include <TRandom.h>
00020 #include <iostream>
00021 #include <string>
00022
00023
00024
00025
00026
00027
00028
00029 MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h){
00030 ShMemory();
00031
00032
00033 fMain = new TGMainFrame(p,w,h);
00034
00035
00036 TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,200,40);
00037 TGHorizontalFrame *hframe2 = new TGHorizontalFrame(fMain,200,40);
00038 TGVerticalFrame *canvasFrame = new TGVerticalFrame(hframe,200,40);
00039 TGVerticalFrame *buttonFrame = new TGVerticalFrame(hframe,200,40);
00040 TGVerticalFrame *timeFrame = new TGVerticalFrame(hframe2,200,40);
00041 TGVerticalFrame *fileFrame = new TGVerticalFrame(hframe2,200,40);
00042
00043
00044
00045
00046 TGLayoutHints *hframeLayout = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
00047 TGLayoutHints *hframe2Layout = new TGLayoutHints(kLHintsExpandX);
00048 TGLayoutHints *canvasLayout = new TGLayoutHints(
00049 (kLHintsExpandX | kLHintsExpandY),25,10,40,10);
00050 TGLayoutHints *buttonLayout = new TGLayoutHints(kLHintsNoHints,15,15,10,10);
00051 TGLayoutHints *top_buttonLayout = new TGLayoutHints(kLHintsNoHints,15,15,40,10);
00052 TGLayoutHints *timeLayout = new TGLayoutHints(kLHintsExpandX,10,10,10,10);
00053 TGLayoutHints *logLayout = new TGLayoutHints((kLHintsRight),10,10,10,10);
00054 TGLayoutHints *saveasLayout = new TGLayoutHints(kLHintsExpandX,10,10,10,10);
00055 TGLayoutHints *saveLayout = new TGLayoutHints(kLHintsNoHints,40,10,10,10);
00056 TGLayoutHints *NoLayout = new TGLayoutHints(kLHintsNoHints);
00057
00058 resume = new TGTextButton(buttonFrame,"&Resume");
00059 suspend = new TGTextButton(buttonFrame,"&Suspend");
00060 terminate = new TGTextButton(buttonFrame,"&Terminate");
00061 TGCheckButton * logswc = new TGCheckButton(canvasFrame,"liner <-> log");
00062 fEcanvas = new TRootEmbeddedCanvas("Ecanvas",canvasFrame,200,200);
00063 char timelbl[100];
00064 sprintf(timelbl,"StartTime::%s ",param_ptr->StartTime);
00065
00066 TGLabel *time_label = new TGLabel (fMain,timelbl);
00067
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00086 resume->Connect("Clicked()","MyMainFrame",this,"DoResume()");
00087 suspend->Connect("Clicked()","MyMainFrame",this,"DoSuspend()");
00088 terminate->Connect("Clicked()","MyMainFrame",this,"DoTerminate()");
00089 logswc->Connect("Clicked()","MyMainFrame",this,"DoSwich()");
00090
00091 logswc->SetState(kButtonUp);
00092
00093
00094
00095 buttonFrame->AddFrame(resume,top_buttonLayout);
00096 buttonFrame->AddFrame(suspend,buttonLayout);
00097 buttonFrame->AddFrame(terminate,buttonLayout);
00098 canvasFrame->AddFrame(fEcanvas,canvasLayout);
00099 canvasFrame->AddFrame(logswc,logLayout);
00100
00101
00102 buttonFrame->Resize();
00103 hframe->Resize();
00104 hframe->AddFrame(canvasFrame,hframeLayout);
00105 hframe->AddFrame(buttonFrame,NoLayout);
00106 hframe2->AddFrame(timeFrame,timeLayout);
00107
00108
00109 fMain->AddFrame(hframe,hframeLayout);
00110 fMain->AddFrame(hframe2,hframe2Layout);
00111 fMain->AddFrame(time_label,timeLayout);
00112
00113
00114
00116 terminate->SetBackgroundColor(400);
00117 hframe->SetBackgroundColor(400);
00118 canvasFrame->SetBackgroundColor(400);
00119 buttonFrame->SetBackgroundColor(400);
00120
00121
00122
00123
00124
00125 fMain->SetWindowName("mesurement of muon lifetime!!");
00126 std::cout<<"**************"<<std::endl;
00127 std::cout<<fMain->GetWindowName()<<std::endl;
00128 std::cout<<"**************"<<std::endl;
00129
00130 fMain->MapSubwindows();
00131
00132 fMain->Resize(fMain->GetDefaultSize());
00133
00134 fMain->MapWindow();
00135
00136 logSW=false;
00137 DrawHist();
00138 }
00139
00140 void MyMainFrame::DrawHist() {
00141 delete hi;
00142
00143 hi = new TH1D("h1","decay time distribution",200,-0.05,19.95);
00144
00145 for(int ii=0;ii<200;ii++){
00146 hi->SetBinContent(ii,double(param_ptr->Hist[ii]));
00147 }
00148 hi->GetXaxis()->SetTitle("decay time [us]");
00149 hi->SetEntries(param_ptr->nEvent);
00150 if(logSW)gPad->SetLogy(1);
00151 else if(!logSW)gPad->SetLogy(0);
00152 hi->Draw();
00153
00154 SetLastEventTime();
00155 TLatex *t1 = new TLatex();
00156 TLatex *t2 = new TLatex();
00157 char txt[50];
00158 char txt2[50];
00159 sprintf(txt,"last event : %s",LastEvent);
00160
00161
00162 sprintf(txt2,"# of Over Flow : %d",param_ptr->nOverFlow);
00163 t1->SetNDC(kTRUE);
00164 t2->SetNDC(kTRUE);
00165 t1->DrawLatex(0.3,0.8,txt);
00166 t2->DrawLatex(0.3,0.7,txt2);
00167
00168
00169 TCanvas *fCanvas = fEcanvas->GetCanvas();
00170 fCanvas->cd();
00171 fCanvas->Update();
00172
00173
00174 if (gifOutputDir[0]) fCanvas->SaveAs(gifOutputDir);
00175
00176 }
00177
00178 void MyMainFrame::SetLastEventTime() {
00179 time_t t;
00180 time(&t);
00181 ltm = localtime(&t);
00182 sprintf(LastEvent,"%02d:%02d:%02d",ltm->tm_hour,ltm->tm_min,ltm->tm_sec);
00183
00184 }
00185 void MyMainFrame::Loop() {
00186
00187 EventNumber_old=param_ptr->nEvent;
00188 int ii=1;
00189 while(ii==1){
00190 if(EventNumber_old<param_ptr->nEvent){
00191 EventNumber_old=param_ptr->nEvent;
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 DrawHist();
00206 }
00207 gSystem->ProcessEvents();
00208 usleep(2000);
00209
00210 }
00211 }
00212 void MyMainFrame::DoSave(){
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 }
00230
00231 void example(char* gifOutputDir) {
00232
00233 MyMainFrame *mmf = new MyMainFrame(gClient->GetRoot(),200,200);
00234
00235 strncpy(mmf->gifOutputDir, gifOutputDir, 1024);
00236 mmf->Loop();
00237 }
00238
00239 int main(int argc, char **argv) {
00240 if (argc <= 1) {
00241 std::cerr << "You need to spcify the out location of GIF" << std::endl
00242 << "e.g. /home/daq/monitor_group2.gif"
00243 << std::endl;
00244 exit(-1);
00245 }
00246 std::cout << "Hello output GIF will be created at "
00247 << argv[1] << std::endl;
00248
00249
00250
00251 int AppArgc = 0;
00252 char** AppArgv;
00253
00254 TApplication theApp("App", &AppArgc, AppArgv);
00255 example(argv[1]);
00256
00257 return 0;
00258 }
00259
00260
00261 int MyMainFrame::ShMemory() {
00262
00263
00264 key = ftok(KEYFILE_PATH,PROJ_CHAR);
00265 if( key == -1 ) {
00266 perror("ftok()");
00267 return 1;
00268 }
00269 sm.shm_access(key,sizeof(struct SHM_PARAM),&shd_param_id,(int *)¶m_ptr);
00270 return 0;
00271 }
00272 MyMainFrame::~MyMainFrame() {
00273
00274 fMain->Cleanup();
00275 delete fMain;
00276 }
00277 void MyMainFrame::DoDraw() {
00278 DrawHist();
00279 }
00280
00281 void MyMainFrame::DoResume(){
00282
00283 param_ptr->status = RESTART;
00284
00285 }
00286 void MyMainFrame::DoSuspend(){
00287
00288 param_ptr->status = PAUSE;
00289 }
00290 void MyMainFrame::DoTerminate(){
00291
00292 param_ptr->status = FIN;
00293 gApplication->Terminate(0);
00294 }
00295
00296 void MyMainFrame::DoSwich(){
00297 if(logSW==false)logSW=true;
00298 else if(logSW==true)logSW=false;
00299
00300 DrawHist();
00301 }