diff --git a/.gitignore b/.gitignore index 0dd7233..c736719 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ read-set *.cxx *.pcm pixieDAQ + +script* diff --git a/pixieDAQ.cpp b/pixieDAQ.cpp index 7162ca7..05805ab 100644 --- a/pixieDAQ.cpp +++ b/pixieDAQ.cpp @@ -90,42 +90,42 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { chEntry = new TGNumberEntry(hframe1, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); chEntry->SetWidth(50); chEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, pixie->GetDigitizerNumChannel(0)); - hframe1->AddFrame(chEntry, new TGLayoutHints(kLHintsCenterX , 2, 2, 5, 0)); + hframe1->AddFrame(chEntry, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2, 2, 5, 0)); TGTextButton *bGetADCTrace = new TGTextButton(hframe1,"Get &ADC Trace"); bGetADCTrace->Connect("Clicked()","MainWindow",this,"GetADCTrace()"); - hframe1->AddFrame(bGetADCTrace, new TGLayoutHints(kLHintsCenterX, 2,2,5,0)); + hframe1->AddFrame(bGetADCTrace, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,0)); TGTextButton *bGetBaseLine = new TGTextButton(hframe1,"Get &BaseLine"); bGetBaseLine->Connect("Clicked()","MainWindow",this,"GetBaseLine()"); - hframe1->AddFrame(bGetBaseLine, new TGLayoutHints(kLHintsCenterX, 2,2,5,0)); + hframe1->AddFrame(bGetBaseLine, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,0)); TGTextButton *bScope = new TGTextButton(hframe1,"&Scope"); bScope->Connect("Clicked()","MainWindow",this,"Scope()"); - hframe1->AddFrame(bScope, new TGLayoutHints(kLHintsCenterX, 2,2,5,0)); + hframe1->AddFrame(bScope, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,0)); ///================= Start Run group TGGroupFrame * group2 = new TGGroupFrame(hframe, "Start run", kHorizontalFrame); - hframe->AddFrame(group2, new TGLayoutHints(kLHintsCenterX, 2,2,5,0) ); + hframe->AddFrame(group2, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,0) ); TGHorizontalFrame *hframe2 = new TGHorizontalFrame(group2,200,30); group2->AddFrame(hframe2); tePath = new TGTextEntry(hframe2, new TGTextBuffer(10)); tePath->SetText("haha.evt"); - hframe2->AddFrame(tePath, new TGLayoutHints(kLHintsCenterX, 2,2,5,0)); + hframe2->AddFrame(tePath, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,0)); TGTextButton *bStartRun = new TGTextButton(hframe2,"Start &Run"); bStartRun->Connect("Clicked()","MainWindow",this,"StartRun()"); - hframe2->AddFrame(bStartRun, new TGLayoutHints(kLHintsCenterX, 2,2,5,0)); + hframe2->AddFrame(bStartRun, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,0)); TGTextButton *bStopRun = new TGTextButton(hframe2,"Stop Run"); bStopRun->Connect("Clicked()","MainWindow",this,"StopRun()"); - hframe2->AddFrame(bStopRun, new TGLayoutHints(kLHintsCenterX, 2,2,5,0)); + hframe2->AddFrame(bStopRun, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,0)); TGTextButton *bScalar = new TGTextButton(hframe2,"Scalar"); - //bScalar->Connect("Clicked()","MainWindow",this,"getADCTrace()"); - hframe2->AddFrame(bScalar, new TGLayoutHints(kLHintsCenterX, 2,2,5,0)); + bScalar->Connect("Clicked()","MainWindow",this,"OpenScalar()"); + hframe2->AddFrame(bScalar, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,0)); ///================= Read evt group @@ -167,6 +167,8 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { /// setup thread thread = new TThread("hahaha", SaveData, (void *) 1); + mainSettings = NULL; + scalarPanel = NULL; ///HandleMenu(M_MAIN_CH_SETTINGS); @@ -192,7 +194,13 @@ void MainWindow::HandleMenu(Int_t id){ case M_EXIT: GoodBye(); break; case M_MAIN_CH_SETTINGS: { - mainSettings = new SettingsSummary(gClient->GetRoot(), 600, 600, pixie); + if( mainSettings == NULL ) { + mainSettings = new SettingsSummary(gClient->GetRoot(), 600, 600, pixie); + }else{ + if( !mainSettings->isOpened ) { + mainSettings = new SettingsSummary(gClient->GetRoot(), 600, 600, pixie); + } + } }break; } @@ -333,6 +341,8 @@ void MainWindow::StartRun(){ pixie->OpenFile(tePath->GetText(), false); + LogMsg(Form("Start Run. Save data at %s.\n", tePath->GetText())); + pixie->StartRun(1); //Emit("StartRun()"); @@ -353,7 +363,7 @@ void * MainWindow::SaveData(void* ptr){ while( pixie->IsRunning() ){ - usleep(500*1000); + usleep(500*1000); /// 500 msec pixie->ReadData(0); pixie->SaveData(); @@ -375,9 +385,21 @@ void MainWindow::StopRun(){ pixie->CloseFile(); + LogMsg("Stop Run"); + pixie->PrintStatistics(0); } + +void MainWindow::OpenScalar(){ + + if( scalarPanel == NULL ) { + scalarPanel = new ScalarPanel(gClient->GetRoot(), 600, 600, pixie); + }else{ + if( !scalarPanel->isOpened ) scalarPanel = new ScalarPanel(gClient->GetRoot(), 600, 600, pixie); + } +} + void MainWindow::LogMsg(TString msg){ teLog->AddLine(msg); teLog->LineDown(); diff --git a/pixieDAQ.h b/pixieDAQ.h index a632043..61303d2 100644 --- a/pixieDAQ.h +++ b/pixieDAQ.h @@ -10,6 +10,7 @@ #include "Pixie16Class.h" #include "settingsSummary.h" +#include "scalarPanel.h" class TGWindow; class TGMainFrame; @@ -31,6 +32,8 @@ private: SettingsSummary * mainSettings; + ScalarPanel * scalarPanel; + TThread * thread; @@ -48,11 +51,11 @@ public: void Scope(); void StartRun(); // *SIGNAL* - static void * SaveData(void* ptr ); /// thread - void StopRun(); + void OpenScalar(); + void LogMsg(TString msg); diff --git a/scalarPanel.cpp b/scalarPanel.cpp new file mode 100644 index 0000000..f7ad661 --- /dev/null +++ b/scalarPanel.cpp @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "scalarPanel.h" + + +Pixie16 * ScalarPanel::pixie = NULL; +bool ScalarPanel::updateFlag = true; +int ScalarPanel::nMod = 0; +TGTextEntry * ScalarPanel::teRate[][MAXCH] = {NULL}; + + +ScalarPanel::ScalarPanel(const TGWindow *p, UInt_t w, UInt_t h, Pixie16 * pixie){ + + this->pixie = pixie; + + nMod = pixie->GetNumModule(); + + fMain = new TGMainFrame(p,w,h); + fMain->SetWindowName("Scalar Panel"); + fMain->Connect("CloseWindow()", "ScalarPanel", this, "CloseWindow()"); + + ///Module choose + TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain, w, 50 ); + fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,2,2)); + + int width = 30; + + ///------ Channel labels + TGVerticalFrame * hChannelLabels = new TGVerticalFrame(hframe); + hframe->AddFrame(hChannelLabels, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,2,2)); + + TGLabel * labelCh[MAXCH]; + for( int ch = 0; ch < MAXCH; ch ++){ + labelCh[ch] = new TGLabel(hChannelLabels, Form("%02d", ch)); + labelCh[ch]->SetWidth(width); + labelCh[ch]->Resize(width, 50); + hChannelLabels->AddFrame(labelCh[ch], new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,5,5)); + } + + + TGVerticalFrame * hScalarMod[nMod]; + + for ( int mod = 0 ; mod < nMod ; mod ++){ + hScalarMod[mod] = new TGVerticalFrame(hframe); + hframe->AddFrame(hScalarMod[mod], new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,2,2)); + + for( int ch = 0 ; ch < MAXCH ; ch ++){ + teRate[mod][ch] = new TGTextEntry(hScalarMod[mod], new TGTextBuffer(10)); + teRate[mod][ch]->SetAlignment(kTextRight); + hScalarMod[mod]->AddFrame(teRate[mod][ch], new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2,2,2,2)); + } + + } + + + fMain->MapSubwindows(); + fMain->Resize(fMain->GetDefaultSize()); + fMain->MapWindow(); + + isOpened = true; + updateFlag = true; + thread = new TThread("kakaka", UpdateScalar, (void *) 0); + thread->Run(); +} + + +ScalarPanel::~ScalarPanel(){ + + updateFlag = false; + isOpened = false; + + for( int i = 0; i < MAXMOD; i++){ + for( int j = 0; j < MAXCH; j++ ){ + delete teRate[i][j]; + } + } + + /// fMain must be delete last; + fMain->Cleanup(); + delete fMain; + +} + +void * ScalarPanel::UpdateScalar(void * ptr){ + + while(updateFlag){ + + int ss = Pixie16GetStatisticsSize(); + unsigned int statistics[ss]; + + for( int mod = 0; mod < nMod; mod++){ + + Pixie16ReadStatisticsFromModule (statistics, mod); + + for( int ch = 0; ch < MAXCH ; ch ++){ + + double ICR = Pixie16ComputeInputCountRate (statistics, mod, ch); + double OCR = Pixie16ComputeOutputCountRate (statistics, mod, ch); + + teRate[mod][ch]->SetText(Form("%.2f[%.2f]", ICR, OCR)); + + } + + gSystem->Sleep(500); ///0.5 sec + + } + + } + + printf("quite Update Scalar\n"); + + return ptr; + +} diff --git a/scalarPanel.h b/scalarPanel.h new file mode 100644 index 0000000..e8c3518 --- /dev/null +++ b/scalarPanel.h @@ -0,0 +1,45 @@ +#ifndef SCALAR_PANEL_H +#define SCALAR_PANEL_H + +#include +#include +#include +#include +#include + +#include "Pixie16Class.h" + +class TGWindow; +class TGMainFrame; + +#define MAXCH 16 +#define MAXMOD 13 + +class ScalarPanel{ +private: + TGMainFrame * fMain; + + static int nMod; + static Pixie16 * pixie; + + static bool updateFlag; + + TThread * thread; + +public: + ScalarPanel(const TGWindow *p, UInt_t w, UInt_t h, Pixie16 * pixie); + virtual ~ScalarPanel(); + + static void * UpdateScalar(void * ptr); + + void CloseWindow() { printf("close window\n"); delete this; } + + bool isOpened; + + static TGTextEntry * teRate[MAXMOD][MAXCH]; + + +}; + + +#endif diff --git a/settingsSummary.cpp b/settingsSummary.cpp index 5256f5f..c902897 100644 --- a/settingsSummary.cpp +++ b/settingsSummary.cpp @@ -66,7 +66,7 @@ SettingsSummary::SettingsSummary(const TGWindow *p, UInt_t w, UInt_t h, Pixie16 TGHorizontalFrame * hframeLabel = new TGHorizontalFrame(hframeSettings, w, 50); hframeSettings->AddFrame(hframeLabel, new TGLayoutHints(kLHintsExpandX, 2,2,2,2)); - TGLabel ** labelItems = new TGLabel * [numItems]; + TGLabel * labelItems[numItems]; for(int i = 0; i < numItems; i++){ labelItems[i] = new TGLabel(hframeLabel, Form("%s", labelText[i].Data())); @@ -75,7 +75,7 @@ SettingsSummary::SettingsSummary(const TGWindow *p, UInt_t w, UInt_t h, Pixie16 hframeLabel->AddFrame(labelItems[i], new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5, 5, 3, 4)); } - TGHorizontalFrame ** hframeCh = new TGHorizontalFrame * [MAXCH]; + TGHorizontalFrame * hframeCh[MAXCH]; for( int i = 0; i < MAXCH ; i ++){ @@ -200,11 +200,15 @@ SettingsSummary::SettingsSummary(const TGWindow *p, UInt_t w, UInt_t h, Pixie16 fMain->MapSubwindows(); fMain->Resize(fMain->GetDefaultSize()); fMain->MapWindow(); + + isOpened = true; } SettingsSummary::~SettingsSummary(){ + isOpened = false; + for (int i = 0; i< MAXCH; i++) { delete lbCh[i]; delete cbOnOff[i] ; diff --git a/settingsSummary.h b/settingsSummary.h index 9f9576a..31c7363 100644 --- a/settingsSummary.h +++ b/settingsSummary.h @@ -46,9 +46,10 @@ private: Pixel_t red; Pixel_t black; - - + int maxCh; + + public: SettingsSummary(const TGWindow *p, UInt_t w, UInt_t h, Pixie16 * pixie); @@ -75,6 +76,8 @@ public: void OpenFile(); void SaveSetting(); + bool isOpened; + };