158 lines
5.8 KiB
C++
158 lines
5.8 KiB
C++
|
#include <TApplication.h>
|
||
|
#include <TGClient.h>
|
||
|
#include <TCanvas.h>
|
||
|
#include <TF1.h>
|
||
|
#include <TRandom.h>
|
||
|
#include <TRootEmbeddedCanvas.h>
|
||
|
#include <TGTableContainer.h>
|
||
|
#include <TGFileDialog.h>
|
||
|
|
||
|
#include "triggerSummary.h"
|
||
|
|
||
|
Digitizer ** TriggerSummary::digi = NULL;
|
||
|
int TriggerSummary::nDigi = 0;
|
||
|
bool TriggerSummary::updateFlag = true;
|
||
|
TGTextEntry * TriggerSummary::txtTrigger[MaxNBoards][MaxNChannels] = {NULL};
|
||
|
TGTextEntry * TriggerSummary::txtThreshold[MaxNBoards][MaxNChannels] = {NULL};
|
||
|
TGNumberEntry * TriggerSummary::numUpdateTime = NULL;
|
||
|
|
||
|
TriggerSummary::TriggerSummary(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** digi, int nBoard){
|
||
|
|
||
|
this->nDigi = nBoard;
|
||
|
this->digi = digi;
|
||
|
|
||
|
fMain = new TGMainFrame(p,w,h);
|
||
|
fMain->SetWindowName("Scalar Panel");
|
||
|
fMain->Connect("CloseWindow()", "TriggerSummary", this, "CloseWindow()");
|
||
|
|
||
|
TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain); fMain->AddFrame(hframe);
|
||
|
|
||
|
TGLayoutHints * kaka = new TGLayoutHints(kLHintsLeft, 0,0,0,0); /// left, right, top, bottom
|
||
|
|
||
|
TGGroupFrame * gBD[nDigi];
|
||
|
TGLabel * lbCh[nDigi][MaxNChannels];
|
||
|
|
||
|
for( int bd = 0; bd < nDigi; bd++){
|
||
|
|
||
|
gBD[bd] = new TGGroupFrame(hframe, Form("Board-%02d", bd), kHorizontalFrame); hframe->AddFrame(gBD[bd], new TGLayoutHints( kLHintsExpandY, 5, 0, 5, 5));
|
||
|
|
||
|
TGVerticalFrame * vframe0 = new TGVerticalFrame(gBD[bd]); gBD[bd]->AddFrame(vframe0, new TGLayoutHints(kLHintsCenterX, 0, 0, 0, 0));
|
||
|
TGVerticalFrame * vframe1 = new TGVerticalFrame(gBD[bd]); gBD[bd]->AddFrame(vframe1, new TGLayoutHints(kLHintsCenterX, 0, 0, 0, 0));
|
||
|
TGVerticalFrame * vframe2 = new TGVerticalFrame(gBD[bd]); gBD[bd]->AddFrame(vframe2, new TGLayoutHints(kLHintsCenterX, 0, 0, 0, 0));
|
||
|
|
||
|
TGLabel * lbCh0 = new TGLabel(vframe0, "ch"); vframe0->AddFrame(lbCh0, new TGLayoutHints(kLHintsCenterY, 0,5,3,2));
|
||
|
TGLabel * lbTrigger = new TGLabel(vframe1, "Trig.[Hz]"); vframe1->AddFrame(lbTrigger, new TGLayoutHints(kLHintsCenterY, 5,5,3,2));
|
||
|
TGLabel * lbThreshold = new TGLabel(vframe2, "Thres."); vframe2->AddFrame(lbThreshold, new TGLayoutHints(kLHintsCenterY, 5,5,3,2));
|
||
|
|
||
|
for( int ch = 0; ch < (digi == NULL ? MaxNChannels: digi[bd]->GetNChannel()); ch++){
|
||
|
lbCh[bd][ch] = new TGLabel(vframe0, Form("%02d", ch)); vframe0->AddFrame(lbCh[bd][ch], new TGLayoutHints(kLHintsCenterY, 0,5,3,2));
|
||
|
|
||
|
txtTrigger[bd][ch] = new TGTextEntry(vframe1, ""); vframe1->AddFrame(txtTrigger[bd][ch], kaka);
|
||
|
txtTrigger[bd][ch]->Resize(50,20);
|
||
|
txtTrigger[bd][ch]->SetEnabled(false);
|
||
|
txtTrigger[bd][ch]->SetAlignment(kTextRight);
|
||
|
|
||
|
txtThreshold[bd][ch] = new TGTextEntry(vframe2, ""); vframe2->AddFrame(txtThreshold[bd][ch], kaka);
|
||
|
txtThreshold[bd][ch]->Resize(50,20);
|
||
|
txtThreshold[bd][ch]->SetAlignment(kTextRight);
|
||
|
txtThreshold[bd][ch]->Connect("ReturnPressed()", "TriggerSummary", this, "SetThreshold()");
|
||
|
|
||
|
value[bd][ch] = 0;
|
||
|
|
||
|
if( digi != NULL ){
|
||
|
if( digi[bd]->GetDPPType() == V1730_DPP_PSD_CODE ) value[bd][ch] = digi[bd]->ReadRegister(Register::DPP::PSD::TriggerThreshold, ch);
|
||
|
if( digi[bd]->GetDPPType() == V1730_DPP_PHA_CODE ) value[bd][ch] = digi[bd]->ReadRegister(Register::DPP::PHA::TriggerThreshold, ch);
|
||
|
}
|
||
|
txtThreshold[bd][ch]->SetText(Form("%d", value[bd][ch]), false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TGHorizontalFrame * hframeSetting = new TGHorizontalFrame(fMain); fMain->AddFrame(hframeSetting, new TGLayoutHints(kLHintsExpandX));
|
||
|
|
||
|
TGLabel * lbUpDateTime = new TGLabel(hframeSetting, "Update Period [msec]:");
|
||
|
hframeSetting->AddFrame(lbUpDateTime, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3));
|
||
|
|
||
|
numUpdateTime = new TGNumberEntry(hframeSetting, 500, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative);
|
||
|
hframeSetting->AddFrame(numUpdateTime, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3));
|
||
|
numUpdateTime->Resize(50, 20);
|
||
|
|
||
|
fMain->MapSubwindows();
|
||
|
fMain->Resize(fMain->GetDefaultSize());
|
||
|
fMain->MapWindow();
|
||
|
|
||
|
updateFlag = true;
|
||
|
|
||
|
if( digi != NULL ){
|
||
|
printf("-------- %s thread\n", __func__);
|
||
|
thread = new TThread("hahaha", UpdateTriggerRate, (void *) 0);
|
||
|
thread->Run();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TriggerSummary::~TriggerSummary(){
|
||
|
|
||
|
printf("Close %s \n", __func__);
|
||
|
|
||
|
for(int i = 0; i < nDigi; i++){
|
||
|
for(int j = 0; j < MaxNChannels; j++){
|
||
|
delete txtTrigger[i][j];
|
||
|
delete txtThreshold[i][j];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
delete numUpdateTime;
|
||
|
|
||
|
updateFlag = false;
|
||
|
usleep(1000 * 1000);
|
||
|
|
||
|
///delete thread; /// Don;t delete the thread, otherwise, thread will not run after close and reopen.
|
||
|
|
||
|
fMain->Cleanup();
|
||
|
delete fMain;
|
||
|
}
|
||
|
|
||
|
void * TriggerSummary::UpdateTriggerRate(void * ptr){
|
||
|
|
||
|
while( updateFlag){
|
||
|
|
||
|
for( int bd = 0; bd < nDigi; bd++){
|
||
|
for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){
|
||
|
txtTrigger[bd][ch]->SetText(Form("%.2f", digi[bd]->GetData()->TriggerRate[ch]));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
usleep(numUpdateTime->GetNumber() * 1000);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void TriggerSummary::SetThreshold(){
|
||
|
if( digi == NULL ) return;
|
||
|
|
||
|
for( int bd = 0; bd < nDigi; bd++){
|
||
|
for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){
|
||
|
|
||
|
unsigned short haha = atoi( txtThreshold[bd][ch]->GetText());
|
||
|
|
||
|
if( value[bd][ch] != haha ){
|
||
|
if( digi[bd]->GetDPPType() == V1730_DPP_PSD_CODE ) {
|
||
|
|
||
|
|
||
|
digi[bd]->WriteRegister(Register::DPP::PSD::TriggerThreshold, haha, ch);
|
||
|
|
||
|
value[bd][ch] = digi[bd]->ReadRegister(Register::DPP::PSD::TriggerThreshold, ch);
|
||
|
|
||
|
}
|
||
|
if( digi[bd]->GetDPPType() == V1730_DPP_PHA_CODE ) {
|
||
|
digi[bd]->WriteRegister(Register::DPP::PHA::TriggerThreshold, haha, ch);
|
||
|
|
||
|
value[bd][ch] = digi[bd]->ReadRegister(Register::DPP::PHA::TriggerThreshold, ch);
|
||
|
|
||
|
}
|
||
|
|
||
|
txtThreshold[bd][ch]->SetText(Form("%d", value[bd][ch]), false);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|