#include "pximon_main.h" PXIMonMainFrame *gui; void * DoPlottingWrapper(void *id){ gui->DoPlotting(id); } void * HistThreadsWrapper(void *id){ gui->HistThreads(id); } PXIMonMainFrame::PXIMonMainFrame(const TGWindow *p,UInt_t w,UInt_t h) { // Create a main frame fMain = new TGMainFrame(p,w,h); // Create canvas widget fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain,w,h); fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY, 10,10,10,1)); // Create a horizontal frame widget with buttons TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,800,40); TGTextButton *startthreads = new TGTextButton(hframe,"&Startthreds"); startthreads->Connect("Clicked()","PXIMonMainFrame",this,"StartThreads()"); hframe->AddFrame(startthreads, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); TGTextButton *stopallthreads = new TGTextButton(hframe,"&Stopallthreads"); stopallthreads->Connect("Clicked()","PXIMonMainFrame",this,"StopAllThreads()"); hframe->AddFrame(stopallthreads, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); TGButtonGroup *bgr = new TGButtonGroup(hframe,"Mag. Coils", kHorizontalFrame); TGRadioButton *rbs[4]; rbs[0] = new TGRadioButton(bgr, new TGHotString("&Coil1")); rbs[1] = new TGRadioButton(bgr, new TGHotString("&Coil2")); rbs[2] = new TGRadioButton(bgr, new TGHotString("&Coil3")); rbs[3] = new TGRadioButton(bgr, new TGHotString("&Coil4")); rbs[0]->SetState(kButtonDown); CoilToView = 1; bgr->Connect("Clicked(Int_t)", "PXIMonMainFrame", this, "SetCoilSelect(Int_t)"); bgr->Show(); hframe->AddFrame(bgr, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); //TGTextButton *exit = new TGTextButton(hframe,"&Exit","gApplication->Terminate(0)"); TGTextButton *exit = new TGTextButton(hframe,"&Quit", "gApplication->Terminate(0)"); hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2)); // Set a name to the main frame fMain->SetWindowName("Simple Example"); // Map all subwindows of main frame fMain->MapSubwindows(); // Initialize the layout algorithm fMain->Resize(fMain->GetDefaultSize()); // Map main frame fMain->MapWindow(); char hnam[128]; char htit[128]; for (int k=0;k<8;k++){ sprintf(hnam,"TheHist%d",k); sprintf(htit,"Knock Sensors Coil %d",(k+2)/2); TheHist[k] = new TH1F (hnam, htit ,10000, 0., 10000.); TheHist[k]->SetLineColor(k+1); OFFSETS[k] = 0; } FirstTime = 1; StopThreads = 1; // open file for saving potential trigger times std::time_t result = std::time(NULL); sprintf(TriggerFileName, "trigger_timings%d.dat",result); OUTFTrig.open(TriggerFileName); ThreshHold = 0.005; } void PXIMonMainFrame::SetCoilSelect(int id){ CoilToView = id; //cout<<"CoilToView: "<Terminate(0); } void PXIMonMainFrame::StopAllThreads() { StopThreads = 1; sleep(1); } void PXIMonMainFrame::StartThreads() { StopThreads = 0; // start threads int rc; for (int k=0;k<9;k++){ cout<<"main(): creating thread "<GetBinContent(i); } OFFSETS[k] = sum/200.; } } gStyle->SetOptStat(0); int idx = (CoilToView-1)*2; TheHist[idx]->GetYaxis()->SetRangeUser(-0.001, 0.001); TheHist[idx]->Draw(); TheHist[idx+1]->Draw("same"); TCanvas *fCanvas = fEcanvas->GetCanvas(); fCanvas->cd(); fCanvas->SetGrid(); fCanvas->Update(); return; } PXIMonMainFrame::~PXIMonMainFrame() { // Clean up used widgets: frames, buttons, layouthints fMain->Cleanup(); delete fMain; } void * PXIMonMainFrame::DoPlotting( void *id){ while(!StopThreads){ sleep(1); int idx = (CoilToView-1)*2; TheHist[idx]->GetYaxis()->SetRangeUser(-0.001, 0.001); TheHist[idx]->Draw(); TheHist[idx+1]->Draw("same"); TCanvas *fCanvas = fEcanvas->GetCanvas(); fCanvas->cd(); fCanvas->SetGrid(); fCanvas->Update(); OUTFTrig.flush(); // flush every second } } void PXIMonMainFrame::FillHistogram(int id){ FILE *FPipe = popen(cmds[id],"r"); size_t NB = 0; fgets(Buffer[id], sizeof(Buffer[id]),FPipe); stringstream ss(Buffer[id]); int ArraySize; int cnt = 0; float Array[10000]; char VarName[128]; ss>>VarName; ss>>ArraySize; //TheHist[id]->Clear(); //TheHist[id]->Reset(); while ( ss>>Array[cnt]){ //TheHist[id]->Fill((float)cnt, Array[cnt]-OFFSETS[id]); TheHist[id]->SetBinContent(cnt+1, Array[cnt]-OFFSETS[id]); cnt++; } pclose(FPipe); float max = TheHist[id]->GetMaximum(); if ((max>ThreshHold) && (OFFSETS[id]!=0)){ std::time_t result = std::time(NULL); const std::time_t * pt; pt = &result; OUTFTrig<GetRoot(), 1000, 800); theApp.SetReturnFromRun(true); theApp.Run(); return 1; }