FSUDAQ/channelSetting.cpp

238 lines
11 KiB
C++

#include <TApplication.h>
#include <TGClient.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TRootEmbeddedCanvas.h>
#include <TGTableContainer.h>
#include <TGFileDialog.h>
#include "channelSetting.h"
//TODO set MAX
///------------------------------------------------ NAME, DIGI, unit ... MAX
TString settingName[NUM_CHANNEL_SETTING][3] = {{"Record Length", "3", "us"},
{"Events / Aggregate", "4", ""},
{"Pre-Trigger Length", "3", "us"},
{"Trigger Threshold", "5", "LSD"},
{"Trigger Holdoff Width", "3", "us"},
{"DPP Algorithm Control", "8", ""},
{"Channel DC offset", "2", "%"},
{"Temperature", "2", "C"},
{"Veto Width", "3", "us"},
{"Trigger Filter Smoothing", "3", "smp"},
{"Input Rising Time", "3", "ns"},
{"Trapezoid Rise Time", "4", "ns"},
{"Trapezoid Flat Top", "4", "ns"},
{"Peaking Time", "4", "ns"},
{"Decay Time", "4", "us"},
{"Rise Time Valid. Win.", "4", "us"},
{"Peak Holdoff", "4", "ns"},
{"Shaped Trigger Width", "4", "us"},
{"DPP Algorithm Control 2", "8", ""},
{"Fine Gain", "3", ""}
};
///const uint32_t RecordLength_G = 0x1020; /// R/W
///const uint32_t InputDynamicRange = 0x1028; /// R/W
///const uint32_t NumberEventsPerAggregate_G = 0x1034; /// R/W
///const uint32_t PreTrigger = 0x1038; /// R/W
///const uint32_t TriggerThreshold = 0x106C; /// R/W
///const uint32_t TriggerHoldOffWidth = 0x1074; /// R/W
///const uint32_t DPPAlgorithmControl = 0x1080; /// R/W
///const uint32_t ChannelDCOffset = 0x1098; /// R/W
///const uint32_t ChannelADCTemperature = 0x10A8; /// R
///const uint32_t VetoWidth = 0x10D4; /// R/W
/// const uint32_t RCCR2SmoothingFactor = 0x1054; /// R/W Trigger Filter smoothing, triggerSmoothingFactor
/// const uint32_t InputRiseTime = 0x1058; /// R/W OK
/// const uint32_t TrapezoidRiseTime = 0x105C; /// R/W OK
/// const uint32_t TrapezoidFlatTop = 0x1060; /// R/W OK
/// const uint32_t PeakingTime = 0x1064; /// R/W OK
/// const uint32_t DecayTime = 0x1068; /// R/W OK
/// const uint32_t RiseTimeValidationWindow = 0x1070; /// R/W OK
/// const uint32_t PeakHoldOff = 0x1078; /// R/W OK
/// const uint32_t ShapedTriggerWidth = 0x1084; /// R/W not sure
/// const uint32_t DPPAlgorithmControl2_G = 0x10A0; /// R/W OK
/// const uint32_t FineGain = 0x10C4; /// R/W OK
ChannelSetting::ChannelSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** digi, int nDigi){
this->digi = digi;
fMain = new TGMainFrame(p,w,h);
fMain->SetWindowName("Channel Settings ");
fMain->Connect("CloseWindow()", "ChannelSetting", this, "CloseWindow()");
TGLayoutHints * layoutHints = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5,5,3,3); /// left, right, top, bottom
TGVerticalFrame * vframe = new TGVerticalFrame(fMain);
fMain->AddFrame(vframe, new TGLayoutHints(kLHintsCenterX, 2,2,2,2));
///==========Board choose
TGHorizontalFrame *hframe0 = new TGHorizontalFrame(vframe, w, 50 );
vframe->AddFrame(hframe0, new TGLayoutHints(kLHintsCenterX, 2,2,2,2));
TGLabel * lb0 = new TGLabel(hframe0, "Module ID :");
hframe0->AddFrame(lb0, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5, 5, 3, 4));
boardIDEntry = new TGNumberEntry(hframe0, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative);
boardIDEntry->SetWidth(50);
boardIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, nDigi);
boardIDEntry->Connect("Modified()", "ChannelSetting", this, "ChangeBoard()");
if( nDigi <= 1 ) boardIDEntry->SetState(false);
NChannel = 16 ;// digi[0]->GetNChannel();
hframe0->AddFrame(boardIDEntry, new TGLayoutHints(kLHintsCenterX , 5, 5, 3, 4));
TGLabel * lb1 = new TGLabel(hframe0, "Channel :");
hframe0->AddFrame(lb1, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5, 5, 3, 4));
chIDEntry = new TGNumberEntry(hframe0, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative);
chIDEntry->SetWidth(50);
chIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, NChannel-1);
chIDEntry->Connect("Modified()", "ChannelSetting", this, "ChangeCh()");
hframe0->AddFrame(chIDEntry, new TGLayoutHints(kLHintsCenterX , 5, 5, 3, 4));
int boardID = boardIDEntry->GetNumber();
int ch = chIDEntry->GetNumber();
int width = 80;
TGGroupFrame * gfInput = new TGGroupFrame(vframe, "Input / Trigger", kHorizontalFrame); vframe->AddFrame(gfInput, new TGLayoutHints(kLHintsExpandX));
TGVerticalFrame * vfInput = new TGVerticalFrame(gfInput); gfInput->AddFrame(vfInput);
TGHorizontalFrame * hfInput1 = new TGHorizontalFrame(vfInput); vfInput->AddFrame(hfInput1, layoutHints);
///----------- on/off
TGLabel * lbOnOff = new TGLabel(hfInput1, "On/Off"); hfInput1->AddFrame(lbOnOff, new TGLayoutHints( kLHintsCenterY, 5, 5, 3, 4));
cbOnOff = new TGComboBox(hfInput1); hfInput1->AddFrame(cbOnOff, new TGLayoutHints(kLHintsCenterY, 5,5,3,4));
cbOnOff->AddEntry("ON", 1);
cbOnOff->AddEntry("off", 0);
cbOnOff->Resize(width, 20);
//pixie->GetChannelOnOff(boardID, ch) ? cbOnOff->Select(1) : cbOnOff->Select(0);
cbOnOff->Connect("Selected(Int_t, Int_t)", "ChannelSetting", this, "ChangeOnOff()");
///----------- Polarity
TGLabel * lbPol = new TGLabel(hfInput1, "Polarity");hfInput1->AddFrame(lbPol, new TGLayoutHints( kLHintsCenterY, 5, 5, 3, 4));
cbPolarity = new TGComboBox(hfInput1); hfInput1->AddFrame(cbPolarity, new TGLayoutHints(kLHintsCenterY, 5,5,3,4));
cbPolarity->AddEntry("Positive +", 1);
cbPolarity->AddEntry("Negative -", 0);
cbPolarity->Resize(width, 20);
//pixie->GetChannelPolarity(boardID, ch) ? cbPolarity->Select(1) : cbPolarity->Select(0);
cbPolarity->Connect("Selected(Int_t, Int_t)", "ChannelSetting", this, "ChangeOnOff()");
///---------- Input Dynamic Range
TGLabel * lbInputDynamicRange = new TGLabel(hfInput1, "Input Range");hfInput1->AddFrame(lbInputDynamicRange, new TGLayoutHints( kLHintsCenterY, 5, 5, 3, 4));
cbInputDynamicRange = new TGComboBox(hfInput1); hfInput1->AddFrame(cbInputDynamicRange, new TGLayoutHints(kLHintsCenterY, 5,5,3,4));
cbInputDynamicRange->AddEntry("2.0 Vpp", 0);
cbInputDynamicRange->AddEntry("0.5 Vpp", 1);
cbInputDynamicRange->Resize(width, 20);
cbInputDynamicRange->Select(0);
///---------- Record Length
TGLabel * lbRecordLength = new TGLabel(hfInput1, "Record Length");hfInput1->AddFrame(lbRecordLength, new TGLayoutHints( kLHintsCenterY, 5, 5, 3, 4));
//TGNumberEntry* entry = new TGNumberEntry(hfInput1, temp, 0, 0, digi, TGNumberFormat::kNEANonNegative);
// entry[i]->Resize(width, 20);
///----- all other
TGHorizontalFrame *hframe[NUM_CHANNEL_SETTING];
TGLabel * lb[NUM_CHANNEL_SETTING];
for( int i = 0 ; i < NUM_CHANNEL_SETTING; i++){
hframe[i] = new TGHorizontalFrame(vframe, 50, 50 );
vframe->AddFrame(hframe[i], new TGLayoutHints(kLHintsRight, 2,2,2,2));
double temp = 0; // pixie->GetChannelSetting(settingName[i][0].Data(), boardID, ch, false);
TGNumberFormat::EStyle digi = TGNumberFormat::kNESInteger;
if( settingName[i][1] == "0" ) digi = TGNumberFormat::kNESInteger;
if( settingName[i][1] == "1" ) digi = TGNumberFormat::kNESRealOne;
if( settingName[i][1] == "2" ) digi = TGNumberFormat::kNESRealTwo;
if( settingName[i][1] == "3" ) digi = TGNumberFormat::kNESRealThree;
entry[i] = new TGNumberEntry(hframe[i], temp, 0, 0, digi, TGNumberFormat::kNEANonNegative);
entry[i]->Resize(width, 20);
if( i >= NUM_CHANNEL_SETTING - 3 ) {
entry[i]->SetState(false);
}else{
entry[i]->Connect("Modified()", "ChannelSetting", this, Form("ChangeID(=%d)", i));
}
hframe[i]->AddFrame(entry[i], new TGLayoutHints(kLHintsRight, 5,5,3,4));
lb[i] = new TGLabel(hframe[i], settingName[i][0] + (settingName[i][2] != "" ? " [" + settingName[i][2] + "]" : ""));
hframe[i]->AddFrame(lb[i], new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5, 5, 3, 4));
}
fMain->MapSubwindows();
fMain->Resize(fMain->GetDefaultSize());
fMain->MapWindow();
isOpened = true;
}
ChannelSetting::~ChannelSetting(){
isOpened = false;
delete boardIDEntry;
delete cbOnOff;
delete cbInputDynamicRange;
delete cbPolarity;
for ( int i = 0; i < NUM_CHANNEL_SETTING; i++){
delete entry[i];
}
/// fMain must be delete last;
fMain->Cleanup();
delete fMain;
}
void ChannelSetting::ChangeBoard(){
ChangeCh();
}
void ChannelSetting::ChangeCh(){
int boardID = boardIDEntry->GetNumber();
int ch = chIDEntry->GetNumber();
//pixie->GetChannelOnOff(boardID, ch) ? cbOnOff->Select(1) : cbOnOff->Select(0);
//pixie->GetChannelPolarity(boardID, ch) ? cbPolarity->Select(1) : cbPolarity->Select(0);
//pixie->GetChannelTraceOnOff(boardID, ch) ? cbTraceOnOff->Select(1) : cbTraceOnOff->Select(0);
for( int i = 0 ; i < NUM_CHANNEL_SETTING; i++){
double temp = 0 ;//pixie->GetChannelSetting(settingName[i][0].Data(), boardID, ch, false);
entry[i]->SetNumber(temp );
}
}
void ChannelSetting::ChangeOnOff(){
short boardID = boardIDEntry->GetNumber();
short ch = chIDEntry->GetNumber();
int val = cbOnOff->GetSelected();
//pixie->SetChannelOnOff(val, boardID, ch);
//pixie->SaveSettings(pixie->GetSettingFile(boardIDEntry->GetNumber()));
}
void ChannelSetting::ChangePolarity(){
short boardID = boardIDEntry->GetNumber();
short ch = chIDEntry->GetNumber();
int val = cbPolarity->GetSelected();
//pixie->SetChannelPositivePolarity(val, boardID, ch);
//pixie->SaveSettings(pixie->GetSettingFile(boardIDEntry->GetNumber()));
}
void ChannelSetting::ChangeID(int id){
short boardID = boardIDEntry->GetNumber();
short ch = chIDEntry->GetNumber();
double val = entry[id]->GetNumber();
//pixie->SetChannelSetting(settingName[id][0].Data(), val, boardID, ch, 1);
//pixie->SaveSettings(pixie->GetSettingFile(boardIDEntry->GetNumber()));
}