#include #include #include "TROOT.h" #include "TGClient.h" #include "TCanvas.h" #include "TF1.h" #include "TRandom.h" #include "TGButton.h" #include "TGFrame.h" #include "TGTab.h" #include "TFile.h" #include "TH1F.h" #include "TDatime.h" #include "TRootEmbeddedCanvas.h" #include "TThread.h" #include "RQ_OBJECT.h" #include "TGFileDialog.h" using namespace std; class MyMainFrame { RQ_OBJECT("MyMainFrame") private: TGMainFrame *fMain; TGTab *fTab; TRootEmbeddedCanvas *fEcanvas; TGTextButton *draw; TGTextButton *exit, *start, *stop; TCanvas * CDCCanvas[7]; TCanvas * FDCCanvas[4]; TThread * RunThread; public: MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h); virtual ~MyMainFrame(); Int_t DoDraw(); void* StartRun(void*); Int_t StartThread(); Int_t StopThread(); }; MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) { RunThread = 0; // Create a main frame fMain = new TGMainFrame(p,w,h); // Prompt for file selection on opening TGHorizontalFrame *hframeFile = new TGHorizontalFrame(fMain,200,200); TGFileInfo fileInfo; static TString dir("/gluonraid1/"); fileInfo.fIniDir = StrDup(dir); const char * fileTypes[] = {"EVIO Files", "*.evio", 0, 0}; fileInfo.fFileTypes = fileTypes; TGFileDialog *fileDialog = new TGFileDialog(gClient->GetRoot(),hframeFile, kFDOpen, &fileInfo); fMain->AddFrame(hframeFile, new TGLayoutHints(kLHintsCenterX,2,2,2,2)); // Create canvas widget TGHorizontalFrame *hframe2 = new TGHorizontalFrame(fMain,200,200); fTab = new TGTab(hframe2); // Create 7 CDC Tabs for (int i = 1; i < 8; i++){ // container of Tab TGCompositeFrame *fCompositeFrame1; fCompositeFrame1 = fTab->AddTab(Form("CDC%i",i)); fCompositeFrame1->SetLayoutManager(new TGVerticalLayout(fCompositeFrame1)); // embedded canvas TRootEmbeddedCanvas *fRootEmbeddedCanvas1 = new TRootEmbeddedCanvas(Form("EmbedCanvasCDC%i",i),fCompositeFrame1,800,600); Int_t windowID = fRootEmbeddedCanvas1->GetCanvasWindowId(); TCanvas *c = new TCanvas(Form("CanvasCDC%i", i), 10, 10, windowID); CDCCanvas[i-1] = c; c->Divide(2,2); fRootEmbeddedCanvas1->AdoptCanvas(c); fCompositeFrame1->AddFrame(fRootEmbeddedCanvas1, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY,2,2,2,2)); } // Create 4 FDC Tabs for (int i = 1; i < 5; i++){ // container of Tab TGCompositeFrame *fCompositeFrame1; fCompositeFrame1 = fTab->AddTab(Form("FDC%i",i)); fCompositeFrame1->SetLayoutManager(new TGVerticalLayout(fCompositeFrame1)); // embedded canvas TRootEmbeddedCanvas *fRootEmbeddedCanvas1 = new TRootEmbeddedCanvas(Form("EmbedCanvasFDC%i",i),fCompositeFrame1,800,600); Int_t windowID = fRootEmbeddedCanvas1->GetCanvasWindowId(); TCanvas *c = new TCanvas(Form("CanvasFDC%i", i), 10, 10, windowID); FDCCanvas[i-1] = c; c->Divide(3,4); fRootEmbeddedCanvas1->AdoptCanvas(c); fCompositeFrame1->AddFrame(fRootEmbeddedCanvas1, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY,2,2,2,2)); } fTab->SetTab(0); fTab->Resize(fTab->GetDefaultSize()); hframe2->AddFrame(fTab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2)); fMain->AddFrame(hframe2, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY, 10,10,10,1)); // Create a horizontal frame widget with buttons TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,200,40); //draw = new TGTextButton(hframe,"&Get Latest Data"); //draw->Connect("Clicked()","MyMainFrame",this,"DoDraw()"); //hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); start = new TGTextButton(hframe,"Star&t"); start->Connect("Clicked()","MyMainFrame",this,"StartThread()"); hframe->AddFrame(start, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); stop = new TGTextButton(hframe,"Sto&p"); stop->SetEnabled(kFALSE); stop->Connect("Clicked()","MyMainFrame",this,"StopThread()"); hframe->AddFrame(stop, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); exit = new TGTextButton(hframe,"&Exit","gApplication->Terminate(0)"); hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,15,5,3,4)); fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2)); // Set a name to the main frame fMain->SetWindowName("CDC/FDC RawData Viewer"); // Map all subwindows of main frame fMain->MapSubwindows(); // Initialize the layout algorithm fMain->Resize(fMain->GetDefaultSize()); // Map main frame fMain->MapWindow(); } Int_t MyMainFrame::DoDraw() { //Open the ROOT file with the output and plot to the correct canvas TFile *rootfile = new TFile("archive/allChannels.root"); if (rootfile->IsZombie()){ // Constructor failed in some way cout << " Root File Not Ready" << endl; return 0; } rootfile->GetListOfKeys(); //rootfile->ls(); for (int i=1;i<29;i++){ TCanvas *myc = CDCCanvas[(i-1)/4]; //myc->Clear(); TPad *p1; if (i % 4) p1 = (TPad*)myc->cd(i % 4); else p1 = (TPad*) myc->cd(4); TH1F *hpt = (TH1F*)rootfile->Get(Form("CDC/CDCRing%i", i)); TH1F *h = (TH1F*) hpt->Clone(); p1->SetLogy(); h->Draw("E"); if(!(i%4)){ myc->Modified(); myc->Update(); gSystem->ProcessEvents(); cout<<"updated CDC canvas "<< i/4 <= 4) iPad += 3; // Skip the Three Upstream p1 = (TPad*)myc->cd(iPad); } else { // Upstream int iPad = ((i/2) % 6) + 1; iPad += 3; // Downstream Below Upstream if (iPad >= 7) iPad += 3; // Skip the Three Downstream p1 = (TPad*)myc->cd(iPad); } TH1F *hpt = (TH1F*)rootfile->Get(histoName); TH1F *h = (TH1F*) hpt->Clone(); p1->SetLogy(); h->Draw("E"); if(!((i+1)%12)){ myc->Modified(); myc->Update(); gSystem->ProcessEvents(); cout<<"updated FDC canvas "<< (i+1)/12 <SetEnabled(kFALSE); start->SetEnabled(kFALSE); cout << "Starting Run " << RunCounter << endl; RunCounter++; system("~/Standalone/CheckRawDatas.csh"); //TThread::CancelPoint(); char *path = gSystem->ExpandPathName("~/Standalone/archive/allChannels.root"); while(true){ Long_t *id,*size,*flags,*modtime; int status = gSystem->GetPathInfo(path,id,size,flags,modtime); if (status == 1) { // Could not stat file cout << "File Not yet found" << endl; TThread::CancelPoint(); sleep(3); } else if (status == 0) // File exists break; } Int_t drawSuccess = DoDraw(); start->SetEnabled(kTRUE); exit->SetEnabled(kTRUE); if(!drawSuccess) break; TThread::CancelPoint(); } return this; } Int_t MyMainFrame::StartThread(){ if (!RunThread){ //draw->SetEnabled(kFALSE); exit->SetEnabled(kFALSE); start->SetEnabled(kFALSE); stop->SetEnabled(kTRUE); RunThread = new TThread("RunThread", (void(*) (void *))&MyMainFrame::StartRun ,(void*) this); cout << endl << "Thread Initialized" << endl; RunThread->Run(); return 0; } return 1; } Int_t MyMainFrame::StopThread(){ if(RunThread){ TThread::Delete(RunThread); delete RunThread; RunThread=0; cout << "Data Taking Stopped " << endl; stop->SetEnabled(kFALSE); //draw->SetEnabled(kTRUE); //exit->SetEnabled(kTRUE); return 0; } return 1; } MyMainFrame::~MyMainFrame() { // Clean up used widgets: frames, buttons, layouthints fMain->Cleanup(); delete fMain; } void RawDataViewer() { new MyMainFrame(gClient->GetRoot(),200,200); }