diff --git a/.clang-tidy b/.clang-tidy index c70b40d30..ed80138ee 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,10 +23,10 @@ AnalyzeTemporaryDtors: false FormatStyle: none CheckOptions: - { key: readability-identifier-naming.NamespaceCase, value: lower_case } - - { key: readability-identifier-naming.FunctionCase, value: lower_case } + # - { key: readability-identifier-naming.FunctionCase, value: lower_case } - { key: readability-identifier-naming.ClassCase, value: CamelCase } - - { key: readability-identifier-naming.MethodCase, value: CamelCase } - - { key: readability-identifier-naming.StructCase, value: CamelCase } - - { key: readability-identifier-naming.VariableCase, value: lower_case } + # - { key: readability-identifier-naming.MethodCase, value: CamelCase } + # - { key: readability-identifier-naming.StructCase, value: CamelCase } + # - { key: readability-identifier-naming.VariableCase, value: lower_case } - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } ... diff --git a/.travis.yml b/.travis.yml index 0bbc8d6bf..81b60efea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,8 @@ install: - conda config --add channels slsdetectorgroup - conda update conda - conda update --all - - conda install conda-build anaconda-client + - conda install conda-build=3.17 + - conda install anaconda-client - conda install conda-verify # Useful for debugging any issues with conda diff --git a/CMakeLists.txt b/CMakeLists.txt index f6e49c817..c9c394baa 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,11 +35,12 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) endif() option (SLS_USE_HDF5 "HDF5 File format" OFF) -option (SLS_USE_TEXTCLIENT "Text Client" OFF) -option (SLS_USE_RECEIVER "Receiver" OFF) +option (SLS_USE_TEXTCLIENT "Text Client" ON) +option (SLS_USE_RECEIVER "Receiver" ON) option (SLS_USE_GUI "GUI" OFF) -option (SLS_USE_TESTS "TESTS" ON) -option (SLS_USE_INTEGRATION_TESTS "Integration Tests" ON) +option (SLS_USE_SIMULATOR "Simulator" OFF) +option (SLS_USE_TESTS "TESTS" OFF) +option (SLS_USE_INTEGRATION_TESTS "Integration Tests" OFF) option(SLS_USE_SANITIZER "Sanitizers for debugging" OFF) option(SLS_USE_PYTHON "Python bindings" OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -106,11 +107,10 @@ if(SLS_USE_SANITIZER) target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined) # target_compile_options(slsProjectOptions INTERFACE -fsanitize=thread) # target_link_libraries(slsProjectOptions INTERFACE -fsanitize=thread) - - endif() +endif() -# Install fake the library +# Install fake the libraries install(TARGETS slsProjectOptions slsProjectWarnings EXPORT "${TARGETS_EXPORT_NAME}" LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -132,8 +132,7 @@ if (SLS_USE_TESTS) add_subdirectory(tests) endif(SLS_USE_TESTS) -# Support library containing functionallity common to -# detector and receiver +# Common functionallity to detector and receiver add_subdirectory(slsSupportLib) if (SLS_USE_TEXTCLIENT) @@ -157,7 +156,9 @@ if (SLS_USE_GUI) endif() endif (SLS_USE_GUI) - +if (SLS_USE_SIMULATOR) + add_subdirectory(slsDetectorServers) +endif (SLS_USE_SIMULATOR) if (SLS_USE_INTEGRATION_TESTS) add_subdirectory(integrationTests) diff --git a/cmk.sh b/cmk.sh index 661d6c526..964e55b1a 100755 --- a/cmk.sh +++ b/cmk.sh @@ -8,6 +8,8 @@ RECEIVER=0 GUI=0 DEBUG=0 PYTHON=0 +TESTS=0 +SIMULATOR=0 CLEAN=0 @@ -16,7 +18,7 @@ CMAKE_PRE="" CMAKE_POST="" usage() { echo -e " -Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [-h] [-d ] [-j] +Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [s] [i] [-h] [-d ] [-j] -[no option]: only make -c: Clean -b: Builds/Rebuilds CMake files normal mode @@ -26,8 +28,10 @@ Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [-h] [-d ] [-j] +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + +#include "ctbAcquisition.h" +#include "multiSlsDetector.h" +#include "sls_detector_defs.h" +#include "ctbMain.h" +#include "moench03CtbData.h" +#include "moench03TCtbData.h" +#include "moench03T1CtbData.h" +#include "moench03CommonMode.h" +#include "moench02CtbData.h" +//#include "jungfrau10ModuleData.h" +#include "moenchCommonMode.h" +#include "singlePhotonDetector.h" +#include "Mythen3_01_jctbData.h" +#include "Mythen3_02_jctbData.h" +#include "adcSar2_jctbData.h" +#include "moench04CtbReceiverData.h" +#include "deserializer.h" +#include "detectorData.h" + +using namespace std; + + + + +ctbAcquisition::ctbAcquisition(TGVerticalFrame *page, multiSlsDetector *det) : TGGroupFrame(page,"Acquisition",kVerticalFrame), myDet(det), myCanvas(NULL), globalPlot(0), nAnalogSamples(1), nDigitalSamples(1), dataStructure(NULL), photonFinder(NULL), cmSub(0), dBitMask(0xffffffffffffffff), deserializer(0) { + + adcFit=NULL; + bitPlot=NULL; + countsFit=NULL; + + page->AddFrame(this,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + MapWindow(); + + TGHorizontalFrame *hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + char tit[100]; + + cout << "outfile "<< endl; + + cFileSave= new TGCheckButton(hframe, "Output file: "); + hframe->AddFrame(cFileSave,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); + cFileSave->MapWindow(); + cFileSave->SetTextJustify(kTextRight); + cFileSave->Connect("Toggled(Bool_t)","ctbAcquisition",this,"setFsave(Bool_t)"); + + + eFname = new TGTextEntry(hframe, (myDet->getFileName()).c_str()); + + hframe->AddFrame(eFname,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5)); + eFname->MapWindow(); + eFname->Resize(150,30); + + eFname->Connect("ReturnPressed()","ctbAcquisition",this,"setFname()"); + + + TGLabel *label=new TGLabel(hframe,"index: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + eFindex = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + hframe->AddFrame( eFindex,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eFindex->MapWindow(); + eFindex->Resize(150,30); + TGTextEntry *e= eFindex->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbAcquisition",this,"setFindex()"); + + + + + cout << "outdir "<< endl; + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + label=new TGLabel(hframe,"Output directory: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + + eOutdir = new TGTextEntry(hframe, (myDet->getFilePath()).c_str()); + + hframe->AddFrame(eOutdir,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5)); + eOutdir->MapWindow(); + eOutdir->Resize(150,30); + + + eOutdir->Connect("ReturnPressed()","ctbAcquisition",this,"setOutdir()"); + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + cout << "meas "<< endl; +label=new TGLabel(hframe,"Number of Measurements (fake): "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + eMeasurements = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + hframe->AddFrame( eMeasurements,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eMeasurements->MapWindow(); + eMeasurements->Resize(150,30); + eMeasurements->SetNumber(1); + e= eMeasurements->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbAcquisition",this,"setMeasurements()"); + + + + +hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + + + cout << "pattern "<< endl; + + + + + cCompile= new TGCheckButton(hframe, "Compile"); + hframe->AddFrame(cCompile,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); + cCompile->MapWindow(); + cCompile->SetOn(); + // cCompile->Connect("Toggled(Bool_t)","ctbAcquisition",this,"setFsave(Bool_t)"); + + + cLoad= new TGTextButton(hframe, "Load"); + hframe->AddFrame(cLoad,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); + cLoad->MapWindow(); + cLoad->Connect("Clicked()","ctbAcquisition",this,"loadPattern()"); + + +// cRun= new TGCheckButton(hframe, "Run"); +// hframe->AddFrame(cRun,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); +// cRun->MapWindow(); +// // cCompile->Connect("Toggled(Bool_t)","ctbAcquisition",this,"setFsave(Bool_t)"); + + + + + + + bStatus=new TGTextButton(hframe, "Start"); + hframe->AddFrame(bStatus,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5)); + bStatus->MapWindow(); + bStatus->Connect("Clicked()","ctbAcquisition",this,"toggleAcquisition()"); + + + + + + cout << "plot "<< endl; + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + + + label=new TGLabel(hframe,"Plot: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + + + + + TGButtonGroup *bgPlot = new TGButtonGroup(hframe); + // horizontal->SetTitlePos(TGGroupFrame::kCenter); + rbPlotOff=new TGRadioButton(hframe, "No plot"); + rbWaveform=new TGRadioButton(hframe, "Waveform"); + rbDistribution=new TGRadioButton(hframe, "Distribution"); + rb2D=new TGRadioButton(hframe, "Image"); + // rbScan=new TGRadioButton(hframe, "Scan"); + + cbDetType=new TGComboBox(hframe); + // enum {DESERIALIZER, MOENCH04, MOENCH02, ADCSAR2, MYTHEN301, MYTHEN302, MAXDET}; + cbDetType->AddEntry("Deserializer", DESERIALIZER); + cbDetType->AddEntry("MOENCH02", MOENCH02); + cbDetType->AddEntry("MOENCH04", MOENCH04); + // cbDetType->AddEntry("JUNGFRAU1.0", 2); + //cbDetType->AddEntry("MOENCH03 T", iiii++); + //cbDetType->AddEntry("MOENCH03", iiii++); + // cbDetType->AddEntry("MYTHEN3 0.1", MYTHEN301); + // cbDetType->AddEntry("ADCSAR2", ADCSAR2); + // cbDetType->AddEntry("MYTHEN3 0.2", MYTHEN302); + + cbDetType->SetHeight(20); + cbDetType->Select(0); + + bgPlot->Insert(rbPlotOff,0); + bgPlot->Insert(rbWaveform,1); + bgPlot->Insert(rbDistribution,2); + bgPlot->Insert(rb2D,3); + // bgPlot->Insert(rbScan,4); + + bgPlot->Connect("Clicked(Int_t)", "ctbAcquisition", this, "changePlot(Int_t)"); + // hframe->AddFrame(bgPlot, new TGLayoutHints(kLHintsExpandX)); + + cbDetType->Connect("Selected(Int_t)", "ctbAcquisition",this, "changeDetector(Int_t)"); + hframe->AddFrame(rbPlotOff, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); + hframe->AddFrame(rbWaveform, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); + hframe->AddFrame(rbDistribution, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); + hframe->AddFrame(rb2D, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); + // hframe->AddFrame(rbScan, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); + hframe->AddFrame(cbDetType, new TGLayoutHints(kLHintsTop | kLHintsExpandX| kLHintsExpandY)); + + + bgPlot->SetExclusive(kTRUE); + rbWaveform->SetOn(); + rbPlotOff->MapWindow(); + rbWaveform->MapWindow(); + rbDistribution->MapWindow(); + rb2D->MapWindow(); + // rbScan->MapWindow(); + cbDetType->MapWindow(); + + + + + cout << "off "<< endl; + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + + label=new TGLabel(hframe,"Serial offset:"); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + eSerOff=new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax,0,16535); + hframe->AddFrame(eSerOff,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eSerOff->MapWindow();; + eSerOff->SetNumber(5); + e= eSerOff->TGNumberEntry::GetNumberEntry(); + eSerOff->Connect("ValueSet(Long_t)","ctbAcquisition",this,"ChangeSerialOffset(Long_t)"); + e->Connect("ReturnPressed()","ctbAcquisition",this,"ChangeSerialOffset()"); + + + label=new TGLabel(hframe,"N counters:"); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + eNumCount=new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax,0,16535); + hframe->AddFrame(eNumCount,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eNumCount->MapWindow();; + eNumCount->SetNumber(64*3); + e= eNumCount->TGNumberEntry::GetNumberEntry(); + eNumCount->Connect("ValueSet(Long_t)","ctbAcquisition",this,"ChangeNumberOfChannels(Long_t)"); + e->Connect("ReturnPressed()","ctbAcquisition",this,"ChangeNumberOfChannels()"); + + + + cout << "dr "<< endl; + + label=new TGLabel(hframe,"Dynamic Range:"); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + eDynRange=new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax,0,16535); + hframe->AddFrame(eDynRange,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eDynRange->MapWindow();; + eDynRange->SetNumber(24); + e= eDynRange->TGNumberEntry::GetNumberEntry(); + eDynRange->Connect("ValueSet(Long_t)","ctbAcquisition",this,"ChangeDynamicRange(Long_t)"); + e->Connect("ReturnPressed()","ctbAcquisition",this,"ChangeDynamicRange()"); + + + + + + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + + label=new TGLabel(hframe,"Pedestal "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + + cbGetPedestal= new TGCheckButton(hframe, "Acquire"); + hframe->AddFrame(cbGetPedestal,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + cbGetPedestal->MapWindow(); + + cbSubtractPedestal= new TGCheckButton(hframe, "Subtract"); + hframe->AddFrame(cbSubtractPedestal,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + cbSubtractPedestal->MapWindow(); + + + cbSubtractPedestal->Connect("Toggled(Bool_t)","ctbAcquisition",this,"TogglePedSub(Bool_t)"); + + cbCommonMode= new TGCheckButton(hframe, "Common Mode"); + hframe->AddFrame(cbCommonMode,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + cbCommonMode->MapWindow(); + + + cbCommonMode->Connect("Toggled(Bool_t)","ctbAcquisition",this,"ToggleCommonMode(Bool_t)"); + + + bResetPedestal= new TGTextButton(hframe, "Reset"); + hframe->AddFrame(bResetPedestal,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + bResetPedestal->MapWindow(); + + + bResetPedestal->Connect("Clicked()","ctbAcquisition",this,"resetPedestal()"); + + + + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + cMinMaxRaw=new TGCheckButton(hframe,"Raw data "); + hframe->AddFrame(cMinMaxRaw,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + cMinMaxRaw->MapWindow(); + cMinMaxRaw->Connect("Toggled(Bool_t)","ctbAcquisition",this,"ChangeHistoLimitsRaw(Bool_t)"); + + + + + label=new TGLabel(hframe,"Min: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + eMinRaw=new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax,0,16535); + hframe->AddFrame(eMinRaw,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eMinRaw->MapWindow();; + eMinRaw->SetNumber(0); + e= eMinRaw->TGNumberEntry::GetNumberEntry(); + eMinRaw->Connect("ValueSet(Long_t)","ctbAcquisition",this,"ChangeHistoLimitsRaw(Long_t)"); + e->Connect("ReturnPressed()","ctbAcquisition",this,"ChangeHistoLimitsRaw()"); + + + label=new TGLabel(hframe,"Max: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + + + eMaxRaw=new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax,0,16535); + hframe->AddFrame(eMaxRaw,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eMaxRaw->MapWindow();; + eMaxRaw->SetNumber(16535); + + e= eMaxRaw->TGNumberEntry::GetNumberEntry(); + eMaxRaw->Connect("ValueSet(Long_t)","ctbAcquisition",this,"ChangeHistoLimitsRaw(Long_t)"); + e->Connect("ReturnPressed()","ctbAcquisition",this,"ChangeHistoLimitsRaw()"); + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + + cMinMaxPedSub=new TGCheckButton(hframe,"Pedestal Subtracted "); + hframe->AddFrame(cMinMaxPedSub,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + cMinMaxPedSub->MapWindow(); + cMinMaxPedSub->Connect("Toggled(Bool_t)","ctbAcquisition",this,"ChangeHistoLimitsPedSub(Bool_t)"); + + + label=new TGLabel(hframe,"Min: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + eMinPedSub=new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEAAnyNumber, + TGNumberFormat::kNELLimitMinMax,-16535,16535); + hframe->AddFrame(eMinPedSub,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eMinPedSub->MapWindow();; + eMinPedSub->SetNumber(-100); + + e= eMinPedSub->TGNumberEntry::GetNumberEntry(); + + eMinPedSub->Connect("ValueSet(Long_t)","ctbAcquisition",this,"ChangeHistoLimitsPedSub(Long_t)"); + e->Connect("ReturnPressed()","ctbAcquisition",this,"ChangeHistoLimitsPedSub()"); + + + label=new TGLabel(hframe,"Max: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + eMaxPedSub=new TGNumberEntry(hframe,0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEAAnyNumber, + TGNumberFormat::kNELLimitMinMax,-16535,16535); + hframe->AddFrame(eMaxPedSub,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eMaxPedSub->MapWindow();; + eMaxPedSub->SetNumber(100); + + + e= eMaxPedSub->TGNumberEntry::GetNumberEntry(); + eMaxPedSub->Connect("ValueSet(Long_t)","ctbAcquisition",this,"ChangeHistoLimitsPedSub(Long_t)"); + e->Connect("ReturnPressed()","ctbAcquisition",this,"ChangeHistoLimitsPedSub()"); + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + + + + TGTextButton *b= new TGTextButton(hframe, "Fit Panel ADC:"); + hframe->AddFrame(b,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + b->MapWindow(); + + + b->Connect("Clicked()","ctbAcquisition",this,"FitADC()"); + + + eFitADC=new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax,0,31); + hframe->AddFrame( eFitADC,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eFitADC->MapWindow();; + + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + + + + b= new TGTextButton(hframe, "Plot bit:"); + hframe->AddFrame(b,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + b->MapWindow(); + + + b->Connect("Clicked()","ctbAcquisition",this,"plotBit()"); + + + eBitPlot=new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax,0,64); + hframe->AddFrame( eBitPlot,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eBitPlot->MapWindow();; + + + + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 10,10,10,10)); + hframe->MapWindow(); + + + + label=new TGLabel(hframe,"X "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + label=new TGLabel(hframe," "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + lClickX=label; + + + + label=new TGLabel(hframe,"Y "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + + label=new TGLabel(hframe," "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + lClickY=label; + + + label=new TGLabel(hframe,"Value "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextRight); + + + + + + label=new TGLabel(hframe," "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + lClickValue=label; + + + + + + + + b= new TGTextButton(hframe, "Refresh"); + hframe->AddFrame(b,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + b->MapWindow(); + + + b->Connect("Clicked()","ctbAcquisition",this,"Draw()"); + + + + + + + + + + + acqThread = new TThread("acqThread", + ctbAcquisition::ThreadHandle,(void*)this); + // acqThread->Run(); + cout <<"Registering progress callback" << endl; + try { + myDet->registerProgressCallback(&progressCallback,(void*)this); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + + cout <<"Registering data callback" << endl; + try{ + myDet->registerDataCallback(&dataCallback, (void*)this); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + + cout <<"Done" << endl; + + // mgAdcs=new TMultiGraph(); + adcStack=new THStack(); + TH1F *h; + int nSamples=nAnalogSamples; + + for (int i=0; iSetLineColor(i+1); + h->SetLineWidth(2); + adcStack->Add(h); + adcHisto[i]=h; + plotFlag[i]=0; + // h->SetMinimum(-1); + // h->SetMaximum(16385); + } + + + // mgAdcs=new TMultiGraph(); + // bitStack=new THStack(); + bitStack=adcStack; + TH1F *hb; + for (int i=0; iSetLineColor(i+1); + hb->SetLineWidth(2); + bitStack->Add(hb); + bitHisto[i]=hb; + bitOffset[i]=0; + bitPlotFlag[i]=0; + // h->SetMinimum(-1); + // h->SetMaximum(16385); + } + + + countsStack=new THStack(); + TH1F *h1; + for (int i=0; iSetLineColor(i+1); + h1->SetFillColor(i+1); + h1->SetLineWidth(2); + countsStack->Add(h1); + countsHisto[i]=h1; + } + + int nx,ny; + int csize=3; + int nsigma=5; + + dataStructure=NULL; + commonMode=NULL; + photonFinder=NULL; + h2DMap=NULL; + //h2Scan=NULL; + h1DMap=NULL; + + changeDetector(cbDetType->GetSelected()); + + + + // display could be updated with TTimer instead of with histogramfillthread: + // plotTimer= new TTimer("ctbAcquisition::Draw()",100); + + + // plotTimer->Connect("TurnOff()", "ctbAcquisition", this, "Draw()"); +} + + + + +void ctbAcquisition::canvasClicked() { + int event = gPad->GetEvent(); + if (event != 11) return; + TObject *select = gPad->GetSelected(); + if (!select) return; + + if (select->InheritsFrom("TH2")) { + TH2* hh=(TH2*)select; + + + + + int px = gPad->GetEventX(); + int py = gPad->GetEventY(); + Float_t upy = gPad->AbsPixeltoY(py); + Float_t y = gPad->PadtoY(upy); + Float_t upx = gPad->AbsPixeltoX(px); + Float_t x = gPad->PadtoY(upx); + + + // cout << "x: " << x << " y: " << y << " " << hh->GetBinContent(hh->GetXaxis()->FindBin(x), hh->GetYaxis()->FindBin(y)) << endl; + + + lClickX->SetText(hh->GetXaxis()->FindBin(x)-1); + lClickY->SetText( hh->GetYaxis()->FindBin(y)-1); + lClickValue->SetText(hh->GetBinContent(hh->GetXaxis()->FindBin(x), hh->GetYaxis()->FindBin(y))); + + + + + + + } else if (select->InheritsFrom("TH1")) { + + TH1* h1=(TH1*)select; + int px = gPad->GetEventX(); + Float_t upx = gPad->AbsPixeltoX(px); + Float_t x = gPad->PadtoY(upx); + + + // cout << "x: " << x << " y: " << y << " " << hh->GetBinContent(hh->GetXaxis()->FindBin(x), hh->GetYaxis()->FindBin(y)) << endl; + + + lClickX->SetText(h1->GetXaxis()->FindBin(x)-1); + lClickY->SetText(" "); + lClickValue->SetText(h1->GetBinContent(h1->GetXaxis()->FindBin(x))); + + + + + + } else// if ((select->ClassName())=="THStack") { + { + + + int px = gPad->GetEventX(); + int py = gPad->GetEventY(); + Float_t upy = gPad->AbsPixeltoY(py); + Float_t y = gPad->PadtoY(upy); + Float_t upx = gPad->AbsPixeltoX(px); + Float_t x = gPad->PadtoY(upx); + + + lClickX->SetText(x); + lClickY->SetText(y); + lClickValue->SetText(""); + + + + } + +} + + + + + + +void ctbAcquisition::setCanvas(TCanvas* c) { + myCanvas=c; + myCanvas->cd(); + myCanvas->AddExec("dynamic",Form("((ctbAcquisition*)0x%x)->canvasClicked()",this)); + // myCanvas->AddExec("ex","canvasClicked()"); +} +int ctbAcquisition::dataCallback(detectorData *data, int index, int dum, void* pArgs) { + + return ((ctbAcquisition*)pArgs)->plotData(data,index); +} + + +int ctbAcquisition::plotData(detectorData *data, int index) { + + /* +****************************************************************** +When selecting dbit +amount of data is nadc * nasamples * 16 bit + ndbitlist * ndsamples (bits) +order of data +analog: +sample0 (adc0 + adc1 +...) +sample1 (adc0 + adc1 +...) +digital: +dbit0 (sample0 + sample1 ...) +dbit1 (sample0 + sample1..) + +when setting dbit to all +amount of data: nadc * nasamples * 16 bit + 8 * ndsamples * 64 bit +what you had before.. +except analog first, then digital +analog: +sample0 (adc0 + adc1 +...) +sample1 (adc0 + adc1 +...) +digital: +sample0 (dbit0 + dbit1 +...) +sample1 (dbit0 + dbit1 +...)if (cmd == "rx_dbitlist") { + + myDet->setReceiverOnline(ONLINE_FLAG, detPos); + + if (action == PUT_ACTION) { + std::vector dbitlist; + + // if not all digital bits enabled + if (std::string(args[1]) != "all") { + for (int i = 1; i < narg; ++i) { + int temp = 0; + if (!sscanf(args[i], "%d", &temp)) + return std::string("Could not scan dbitlist value ") + + std::string(args[i]); + if (temp < 0 || temp > 63) + return std::string("dbitlist value should be between 0 and 63 ") + + std::string(args[i]); + dbitlist.push_back(temp); + } + if (dbitlist.size() > 64) { + return std::string("Max number of values for dbitlist is 64 "); + } + } + + myDet->setReceiverDbitList(dbitlist, detPos); + } + +****************************************************************** +*/ + + // cout << "plot data" << endl; + + + // cout <<"global plot is " << globalPlot << endl; + cout << "*******************************************" <progressIndex << " npoints:" << data->npoints << " npy: " << data->npy << " " << data->fileName << " bytes: " << data->databytes << " dr:"<< data->dynamicRange << " fi: " << data ->fileIndex << endl; + if (globalPlot || cbGetPedestal->IsOn()) { + //#ifdef TESTADC + // cout <<"------"<< index << " " << ip << " " << data->npoints << endl; + //#endif + int ig=0; + int i, ii, ich=0, ib, vv; + // TList *l= adcStack->GetHists(); + // TList *l1= countsStack->GetHists(); + TH1F *h; + TH1F *h1; + TH1F *hb; + int nb, x,y; + double ped=0; + int vv1,vv2; + int dsize=-1; + int *val=NULL; + int nx=1, ny=1, jj; + short unsigned int *va; + if (dataStructure) { + dataStructure->getDetectorSize(nx,ny); + cout << "Data structure: " << dataStructure << " size " << nx << " " << ny << endl; + } + int dr=24, soff=2; + if (deserializer) { + nx=eNumCount->GetIntNumber(); + dr=eDynRange->GetIntNumber(); + soff=eSerOff->GetIntNumber(); + } + + i=0; + int nadc; + int ndbit; + + + + + + + if (adclist.empty()) + nadc=32; + else + nadc=adclist.size(); + + std::vector plotlist; + if (dbitlist.empty()) { + ndbit=64; + dBitOffset=0; + for (ib=0; ib<64; ib++){ + if (bitPlotFlag[ib]) { + plotlist.push_back(ib); + } + } + } else + ndbit=dbitlist.size(); + + dsize=nadc*2*nAnalogSamples+ndbit*(nDigitalSamples-dBitOffset/8)/8; + + cout << "dataBytes is " << data->databytes << " expected " << dsize << endl; + + cout << "*******************************************" <getChannel(i);//*((uint16_t*)(data->cvalues+i*2));// + + // cout << "asample " << ip << " adc " << ig << " " << i << " " << aval << endl; + + ped=0; + + + + if (dataStructure) { + dataStructure->getPixel(i,x,y); + + + + if (cbGetPedestal->IsOn()) { + if (photonFinder) { + photonFinder->addToPedestal(aval,x,y); + } + } + + if (plotFlag[ig]) { + + if (cbSubtractPedestal->IsOn()) { + if (photonFinder) { + ped=photonFinder->getPedestal(x,y,cmSub); + } + } + + + //normal filling except when deserializer + if (h2DMap) + h2DMap->SetBinContent(x+1,y+1,aval-ped); + if (h1DMap){ + h1DMap->SetBinContent(x+1,aval-ped); + // cout << "plotting 1D " << endl; + } + // if (h2Scan) { + // //cout << "plotting Scan " << endl; + // h2Scan->SetBinContent((x+1)+y*nx,iScanStep+1,data->getChannel(i)-ped); + // } else + // cout << "No scan (analog)" << endl; + } + } + + + + + //if (enableFlag[ig]) { + h=adcHisto[ig]; + h1=countsHisto[ig]; + //} + + if (plotFlag[ig]) { + // cout << data->getChannel(i) << endl; + h->SetBinContent(ip+1,aval-ped); + h1->Fill(aval-ped); + } + + i++; + } + + } + + char *d_data= data->cvalues+2*nadc*nAnalogSamples; + char dval; + + + /**** Digital Samples ****/ + + + + if (deserializer) { + if (dbitlist.empty()) + val=deserializer::deserializeAll(d_data,plotlist,dr,nx,soff);//dataStructure->getData(d_data); + else + val=deserializer::deserializeList(d_data,dbitlist,dr,nx,soff);//dataStructure->getData(d_data); + + + if (val) { + // if (h2DMap) { + // for (x=0; xSetBinContent(x+1,y+1,val[y][x]); + // } + // } + // } + if (h1DMap){ + for (x=0; xSetBinContent(x+1,val[x]); + // cout << dec << x << " " << val[0][x] << endl; + } + } + // if (h2Scan) { + // for (x=0; xSetBinContent((x+1)+y*nx,iScanStep+1,val[y][x]); + // } + // } + // } else + // cout << "No scan (digital)" << endl; + + + delete [] val; + } else + cout << "get val did not succeed"<GetHists()->Contains(hb)==0) cout << "ERROR!" << endl; + //#define ADCSAR2 +// #ifdef ADCSAR2 +// if (ib==0) vv1=dval; +// if (ib==16) vv2=dval; +// cout << ib << " " << hex << vv << dec << endl; +// #endif + if (dval&(1<<(ib%8))) + hb->SetBinContent(ip+1,1+bitOffset[ib]); + else + hb->SetBinContent(ip+1,bitOffset[ib]); + } + } + +// #ifdef ADCSAR2 +// //this is a deserializer similar to MYTHEN! +// hb=bitHisto[0]; +// int adcvalue=0; +// // int startbit= ig; +// for (int jj=0;jj<8;jj++){ +// adcvalue=adcvalue+ (((vv1>>(jj*2)) & 0x1)<<(jj)); +// } +// for (int jj=0;jj<4;jj++){ +// adcvalue=adcvalue+ (((vv2>>(jj*2)) & 0x1)<<(jj+8)); +// } +// hb->SetBinContent(ip+1, adcvalue); +// printf(" %d 0x%x 0x%x adc=%d \n", i, vv1, vv2, adcvalue); +// #endif + } + } + } else { + ii=0; + int iii=0; + int nb=dbitlist.size(); + for (const auto &value : dbitlist) { + ib=value; + hb=bitHisto[ib]; + cout << dec <SetBinContent(iii,1+bitOffset[ib]); + else + hb->SetBinContent(iii,bitOffset[ib]); + iii++; + } + } + } + ii++; + } + } + + Draw(); + // iScanStep++; + if (photonFinder) + photonFinder->newFrame(); + return i; +} + return 0; + +} + +void ctbAcquisition::Draw(){ + if (globalPlot) { + // TThread::Lock(); + cout << "Draw" << endl; + if (myCanvas && globalPlot!=0) { + myCanvas->cd(); + myCanvas->Modified(); + myCanvas->Update(); + } + // TThread::UnLock(); + } + +} + + + +void ctbAcquisition::changePlot(){ + if (rbPlotOff->IsOn()) { + globalPlot=0; + } else { + globalPlot=0; + for (int ii=0; iiIsOn()) + if (adcStack) + adcStack->Draw("NOSTACK"); + else + cout << "adcStack is NULL" << endl; + else if (rbDistribution->IsOn()) + if (countsStack) + countsStack->Draw("NOSTACK"); + else + cout << "countsStack is NULL" << endl; + else if (rb2D->IsOn()) { + if (h2DMap) + h2DMap->Draw("colz"); + else if (h1DMap) + h1DMap->Draw(); + else + cout << "h2DMap and h1DMap are NULL" << endl; + } // else if (rbScan->IsOn()) { + // if (h2Scan) + // h2Scan->Draw("colz"); + // else + // cout << "h2Scan is NULL" << endl; + // } + } + Draw(); + +} + + + + + +void ctbAcquisition::changeDetector(){ + // cout << "change detector " << i << " old " << cbDetType->GetSelected() << endl; + + if (dataStructure) delete dataStructure; + if (commonMode) delete commonMode; + if (photonFinder) delete photonFinder; + if (h2DMap) delete h2DMap; + if (h1DMap) delete h1DMap; + // if (h2Scan) delete h2Scan; + h2DMap=NULL; + h1DMap=NULL; + // h2Scan=NULL; + photonFinder=NULL; + dataStructure=NULL; + commonMode=NULL; + TH2F *h2DMapOld=h2DMap; + // TH2F *h2ScanOld=h2Scan; + TH1F *h1DMapOld=h1DMap; + int dim=2; + int nx,ny; + int csize=3; + int nsigma=5; + commonModeSubtraction* cm=0; + eNumCount->SetState(kFALSE); + eDynRange->SetState(kFALSE); + eSerOff->SetState(kFALSE); + deserializer=0; + if (rb2D->IsOn() ) {//|| rbScan->IsOn() + switch (cbDetType->GetSelected()) { + case DESERIALIZER: + deserializer=1; + // cout << "DESERIALIZER!" << endl; + // dataStructure=new moench03T1CtbData(); + // commonMode=new moench03CommonMode(); + break; + case MOENCH04: + dataStructure=new moench04CtbReceiverData(); + cout << "MOENCH 0.4!" << endl; + commonMode=new moench03CommonMode(); + break; + + // case 1: + // cout << "************** T!!!!!!!!!!" << endl; + // dataStructure=new moench03TCtbData(); + // commonMode=new moench03CommonMode(); + // break; + case MOENCH02: + cout << "MOENCH 0.2" << endl; + dataStructure=new moench02CtbData(); + commonMode=new moenchCommonMode(); + break; + // case 2: + // dataStructure=new jungfrau10ModuleData(); + // commonMode=new commonModeSubtraction(); + // break; + // case 3: + // cout << "************** Flat!!!!!!!!!!" << endl; + // dataStructure=new moench03CtbData(); + // commonMode=new moench03CommonMode(); + // break; + // case MYTHEN301: + // deserializer=1; + // cout << "MYTHEN 3 0.1" << endl; + // dataStructure=new mythen3_01_jctbData(eNumCount->GetIntNumber(),eDynRange->GetIntNumber(),eSerOff->GetIntNumber()); + // //( int nch=64*3,int dr=24, int off=5) + // eNumCount->SetState(kTRUE); + // eDynRange->SetState(kTRUE); + // eSerOff->SetState(kTRUE); + // commonMode=NULL; + // dim=1; + // break; + // case ADCSAR2: + // deserializer=1; + // //adcsar2 + // dataStructure=new adcSar2_jctbData(); + // //need to use configurable number of counters, offset or dynamic range? + // commonMode=NULL; + // dim=1; + // break; + + // case MYTHEN302: + // deserializer=1; + // cout << "MYTHEN 3 0.2" << endl; + // dataStructure=new mythen3_02_jctbData(eNumCount->GetIntNumber(),eDynRange->GetIntNumber(),eSerOff->GetIntNumber()); + // //( int nch=64*3,int dr=24, int off=5) + // eNumCount->SetState(kTRUE); + // eDynRange->SetState(kTRUE); + // eSerOff->SetState(kTRUE); + // commonMode=NULL; + // dim=1; + // break; + default: + dataStructure=NULL; + commonMode=NULL; + } + if (cbCommonMode->IsOn()) cm=commonMode; + } + + if (dataStructure || deserializer) { + if (dataStructure) { + photonFinder=new singlePhotonDetector(dataStructure,csize,nsigma,1,cm); //sign is positive - should correct with ADC mask, no common mode + //photonFinder=new singlePhotonDetector(dataStructure,csize,nsigma,1,cm); //sign is positive - should correct with ADC mask, no common mode + dataStructure->getDetectorSize(nx,ny); + } + if (deserializer) { + ny=1; + nx=eNumCount->GetIntNumber(); + } + // cout << "h size is " << nx << " " << ny << endl; + int ymax=ny, xmax=nx; + // if (ny>500) {ny=ny/2;} + // if (nx>500) {nx=nx/2;} + cout << "*** " << nx << " " << ny << endl; + if (rb2D->IsOn()) { + if (ny>1) { + h2DMap=new TH2F("h2dmap","",nx,0,xmax,ny,0,ymax); + h2DMap->SetStats(kFALSE); + cout << "Created h2DMap"<< endl; + } else { + h1DMap=new TH1F("h1dmap","",nx,0,xmax); + h1DMap->SetStats(kFALSE); + cout << "Created h1DMap"<< endl; + } + } // else if (rbScan->IsOn()) { + // int nsteps=0;//myDet->getScanSteps(0); + // double stepmin=0, stepmax=1; + // if (nsteps>0) { + // stepmin=myDet->getScanStep(0,0); + // stepmax=myDet->getScanStep(0,nsteps-1); + // } + // cout << "************ creating scan histogram " << nx*ny << " " << nsteps << " " << stepmin << " " << stepmax << endl; + // if (nsteps<1) nsteps=1; + // double hmin=stepmin, hmax=stepmax; + // if (stepmin>stepmax) { + // hmin=stepmax; + // hmax=stepmin; + // } + // h2Scan=new TH2F("h2scan","",nx*ny,0,nx*ny,nsteps,hmin,hmax); + // } + + } + + + cout << "done " << endl; +} + + + +void ctbAcquisition::changeDetector(int i){ + changePlot(); + changeDetector(); +} + +void ctbAcquisition::changePlot(int i){ + changePlot(); + changeDetector(); +} + + + +void ctbAcquisition::setGraph(int i ,int en, Pixel_t col) { + char name[100]; + // TList *l= mgAdcs->GetListOfGraphs(); + sprintf(name,"adc%d",i); + + // TList *l= adcStack->GetHists(); + TH1F *h=adcHisto[i];//(TH1F*)l->At(i);; + TH1F *h1=countsHisto[i];//(TH1F*)(countsStack->GetHists()->At(i)); + if (en) { + plotFlag[i]=1; + h->SetLineColor(TColor::GetColor(col)); + h1->SetLineColor(TColor::GetColor(col)); + h1->SetFillColor(TColor::GetColor(col)); + + if (adcStack->GetHists()) + // if (adcStack->GetHists()->GetEntries()) + if (adcStack->GetHists()->Contains(h)==0) + adcStack->Add(h); + + if (countsStack->GetHists()) + if (countsStack->GetHists()->Contains(h1)==0) + countsStack->Add(h1); + + cout << "Enable plot " << i << " color " << col << endl; + } else { + cout << "Disable plot " << i << endl; + plotFlag[i]=0; + if (adcStack->GetHists()) + // if (adcStack->GetHists()->GetEntries()) + if (adcStack->GetHists()->Contains(h)) + adcStack->RecursiveRemove(h); + if (countsStack->GetHists()) + if (countsStack->GetHists()->Contains(h1)) + countsStack->RecursiveRemove(h1); + } + cout << countsStack->GetHists()->GetEntries() << endl; + + cout << "Number of histos " << adcStack->GetHists()->GetEntries() << endl; + + changePlot(); + + // globalPlot=0; + // for (int ii=0; iiGetListOfGraphs(); + sprintf(name,"bit%d",i); + // TList *l= adcStack->GetHists(); + TH1F *h=bitHisto[i];//(TH1F*)l->At(i);; + if (en) { + //cout<< "enabling plot of bit "<SetLineColor(TColor::GetColor(col)); + if (bitStack->GetHists()) + //if (bitStack->GetHists()->GetEntries()) + if (bitStack->GetHists()->Contains(h)==0) + bitStack->Add(h); + + + cout << "Enable bit plot " << i << " color " << col << endl; + } else { + cout << "Disable bit plot " << i << endl; + bitPlotFlag[i]=0; + if (bitStack->GetHists()) + // if (bitStack->GetHists()->GetEntries()) + if (bitStack->GetHists()->Contains(h)) + bitStack->RecursiveRemove(h); + } + cout << "Number of histos " << bitStack->GetHists()->GetEntries() << endl; + + changePlot(); + + float off=0; + for (int ii=0; iisetFilePath(eOutdir->GetText()); + } catch (...) { + cout << "Do nothing for this error" << endl; + } +// // cout << "setting dac! "<< id << endl; + +// myDet->setDAC(dacsEntry->GetIntNumber(), (slsDetectorDefs::dacIndex)id, dacsUnit->IsOn()); + +// getValue(); + +} + +void ctbAcquisition::setFname() { + try { + myDet->setFileName(eFname->GetText()); + } catch (...) { + cout << "Do nothing for this error" << endl; + } +// int val=myDet->setDAC(-1, (slsDetectorDefs::dacIndex)id, dacsUnit->IsOn()); +// char s[100]; + +// sprintf(s,"%d",val); + +// dacsValue->SetText(s); + + +// return val; + +} + +void ctbAcquisition::setFindex() { + + try { + myDet->setFileIndex(eFindex->GetNumber()); +} catch (...) { + cout << "Do nothing for this error" << endl; + } + +} + + +void ctbAcquisition::setFsave(Bool_t b) { + try { + myDet->setFileWrite(b); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + eFname->SetState(b); + eOutdir->SetState(b); + +} + +void ctbAcquisition::update() { + + + eFname->SetText((myDet->getFileName()).c_str()); + eOutdir->SetText((myDet->getFilePath()).c_str()); + eFindex->SetNumber(myDet->getFileIndex()); + cFileSave->SetOn(myDet->getFileWrite()); + eFname->SetState(cFileSave->IsOn()); + eOutdir->SetState(cFileSave->IsOn()); + eFindex->SetState(cFileSave->IsOn()); + // eMeasurements->SetNumber(myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1)); + setAnalogSamples(myDet->setTimer(slsDetectorDefs::ANALOG_SAMPLES,-1)); + setDigitalSamples(myDet->setTimer(slsDetectorDefs::DIGITAL_SAMPLES,-1)); + roMode=myDet->setReadOutFlags(); + setReadoutMode(roMode); + //nChannels=myDet->getTotalNumberOfChannels(); + updateChans(); + + if (dataStructure) { + cout << cbDetType->GetSelected()<< endl; + if (cbDetType->GetSelected()==MYTHEN301 || cbDetType->GetSelected()==MYTHEN302){ + cout << "settings deserialiation parameters for MYTHEN" << endl; + mythen3_01_jctbData* ms=(mythen3_01_jctbData*)dataStructure; + eSerOff->SetNumber( ms->setSerialOffset(-1)); + eDynRange->SetNumber( ms->setDynamicRange(-1)); + eNumCount->SetNumber( ms->setNumberOfCounters(-1)); + } + + } + dBitOffset=myDet->getReceiverDbitOffset(); + + // char aargs[10][100]; + // char *args[10]; + // for (int i=0; i<10; i++) + // args[i]=aargs[i]; + + // string retval; + // sprintf(args[0],"adcdisable"); + // slsDetectorCommand *cmd=new slsDetectorCommand(myDet); + // retval=cmd->executeLine(1,args,slsDetectorDefs::GET_ACTION); + // delete cmd; + // int mask; + // sscanf(retval.c_str(),"adcdisable %d",&mask); + // for (int i=0; iGetState()==1 || acqThread->GetState()==6) { + + + if (cCompile->IsOn()) { + sprintf(fname,"%s %s",patternCompiler,patternFile); + cout << "Compile: " << fname << endl; + strcpy(currdir,gSystem->pwd()); + + std::size_t found = string(patternCompiler).rfind('/'); + if (found!=std::string::npos) + gSystem->cd(string(patternCompiler).substr(0,found).c_str()); + + gSystem->cd(cdir); + system(fname); + gSystem->cd(currdir); + } + + if (string(patternCompiler).rfind(".pat")!=std::string::npos) + strcpy(fname,patternFile); + else if (string(patternCompiler).rfind(".npat")!=std::string::npos) + strcpy(fname,patternFile); + else + sprintf(fname,"%sat",patternFile); + + cout << "Load: " << fname << endl; + try { + myDet->retrieveDetectorSetup(fname); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + } +} + + +void ctbAcquisition::toggleAcquisition() { + + + if (acqThread->GetState()==1 || acqThread->GetState()==6) { + /** update all infos useful for the acquisition! */ + + setAnalogSamples(myDet->setTimer(slsDetectorDefs::ANALOG_SAMPLES,-1)); + setDigitalSamples(myDet->setTimer(slsDetectorDefs::DIGITAL_SAMPLES,-1)); + dBitOffset=myDet->getReceiverDbitOffset(); + roMode=myDet->setReadOutFlags(); + setReadoutMode(roMode); + + + + // iScanStep=0; + + cout << "Run" << endl; + bStatus->SetText("Stop"); + ip=0; + for (int i=0; iGetListOfFunctions()) + adcHisto[i]->GetListOfFunctions()->Delete(); + + adcHisto[i]->Reset(); + + if (countsHisto[i]->GetListOfFunctions()) + countsHisto[i]->GetListOfFunctions()->Delete(); + countsHisto[i]->Reset(); + // ((TH1F*)adcStack->GetHists()->At(i))->Reset(); + // ((TH1F*)countsStack->GetHists()->At(i))->Reset(); + } + for (int i=0; iReset(); + } + cout << "reset 2d" << endl;; + if (h2DMap) h2DMap->Reset(); + cout << "reset 1d" << endl;; + if (h1DMap) h1DMap->Reset(); + cout << "done" << endl;; + // if (h2Scan) h2Scan->Reset(); + // cout << "reset 1d" << endl;; + // if (rbWaveform->IsOn()) +// adcStack->Draw("NOSTACK"); +// else if (rbDistribution->IsOn()) +// countsStack->Draw("NOSTACK"); +// else if (rb2D->IsOn()) +// h2DMap->Draw("colz"); + + // cout << "timer" << endl; + changePlot(); + + // plotTimer->TurnOn(); + // cout << "thread" << endl; + acqThread->Run(); + StopFlag=0; + + + + + + } else { + StopFlag=1; + try { + myDet->stopAcquisition(); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + stop=1; + bStatus->SetText("Start"); + // acqThread->Kill(); + } +} + +void ctbAcquisition::acquisitionFinished() { + bStatus->SetText("Start"); + cout << "finished " << endl; + // plotTimer->TurnOff(); + Draw(); +} + +void ctbAcquisition::startAcquisition(){ + cout << "Detector started " <GetNumber()<< endl; + stop=0; + for (int im=0; imGetNumber(); im++) { + try { + myDet->acquire(); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + cout << im << endl; + if (stop) break; + } + +} + +void* ctbAcquisition::ThreadHandle(void *arg) +{ + ctbAcquisition *acq = static_cast(arg); + int i=0; + + acq->startAcquisition(); + acq->acquisitionFinished(); + + +} + + int ctbAcquisition::progressCallback(double f,void* arg) { + + + // ctbAcquisition *acq = static_cast(arg); + + + cout << "*********" << f << "*******" << endl; + + + + + } + +void ctbAcquisition::setPatternFile(const char* t) { + + + cout << "New pattern is " << t << endl; + + strcpy(patternFile,t); + } + +void ctbAcquisition::setPatternCompiler(const char* t) { + + + cout << "New compiler is " << t << endl; + strcpy(patternCompiler,t); + + } +void ctbAcquisition::setMeasurements() { + + + + // myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,eMeasurements->GetNumber()); + + + +} + +void ctbAcquisition::setAnalogSamples(int n) { + + + cout<< "Set number of analog samples to " << dec<< n << endl; + if (n>0 && n<8192) + nAnalogSamples=n; + + // TList *l= adcStack->GetHists(); + TH1 *h; + // if (l) { + for (int i=0; iAt(i); + if (h) { + + h->SetBins(nAnalogSamples,0,nAnalogSamples); + } + } + + h=adcStack->GetHistogram(); + if (h) + h->SetBins(nAnalogSamples,0,nAnalogSamples); +} + + + +void ctbAcquisition::setDigitalSamples(int n) { + + + cout<< "Set number of digital samples to " << dec<< n << endl; + if (n>0 && n<8192) + nDigitalSamples=n; + + TH1 *h; + for (int i=0; iAt(i); + if (h) { + + h->SetBins(nDigitalSamples,0,nDigitalSamples); + } + + } + // cout<< "histos resized " << dec<< h->GetNbinsX() << endl; + + h=bitStack->GetHistogram(); + if (h) + h->SetBins(nDigitalSamples,0,nDigitalSamples); + +} + +void ctbAcquisition::setReadoutMode(int f) { + + roMode=f; + slsDetectorDefs::readOutFlags flags=(slsDetectorDefs::readOutFlags)f; + if (flags&slsDetectorDefs::DIGITAL_ONLY) { + nAnalogSamples=0; + adclist.clear(); + } else if (flags&slsDetectorDefs::ANALOG_AND_DIGITAL) { + ; + } + else { + nDigitalSamples=0; + dbitlist.clear(); + } + + // for (int i=0; i dbl; + try { + dbl = myDet->getReceiverDbitList(); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + dbitlist.clear(); + if (dbl.empty()) + ; + else { + for (const auto &value : dbl) + dbitlist.push_back(value); + } + uint32_t reg; + try { + reg=myDet->getADCEnableMask(); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + /* adc updated */ + adclist.clear(); + // // updateChans(); + if (reg!=0xffffffff) { + for (int i=0; inewDataSet(); + }; + +} + +void ctbAcquisition::ToggleCommonMode(Bool_t b) { + if (photonFinder) { + if (b) { + photonFinder->setCommonModeSubtraction(commonMode); + cmSub=1; + cout << "Enable common mode" << endl; + } else { + photonFinder->setCommonModeSubtraction(NULL); + cmSub=0; + cout << "Disable common mode" << endl; + } + } + +} + + +void ctbAcquisition::TogglePedSub(Bool_t b) { + if (b) { + ChangeHistoLimitsPedSub(); + } else { + ChangeHistoLimitsRaw(); + } + +} + + +void ctbAcquisition::FitADC() { + int iadc=eFitADC->GetNumber(); + if (iadc<0 || iadc>=NADCS) return; + cout << "fit panel for adc " << eFitADC->GetNumber() << endl; + if (rbWaveform->IsOn()) { + if (adcHisto[iadc]==NULL) return; + new TCanvas("Cadcfit"); + if (adcFit) { + delete adcFit; + adcFit=NULL; + } + adcFit=(TH1F*)(adcHisto[iadc]->Clone("adcfit")); + adcFit->Draw(); + adcFit->FitPanel(); + + } else if (rbDistribution->IsOn()) { + if (countsHisto[iadc]==NULL) return; + new TCanvas("Ccountsfit"); + + if (countsFit) { + delete countsFit; + countsFit=NULL; + } + + countsFit=(TH1F*)(countsHisto[iadc]->Clone("countsfit")); + countsFit->Draw(); + countsFit->FitPanel(); + } +} + + +void ctbAcquisition::plotBit() { + int iadc=eBitPlot->GetNumber(); + if (iadc<0 || iadc>=NSIGNALS) return; + cout << "plot panel for bit " << eBitPlot->GetNumber() << endl; + if (bitHisto[iadc]==NULL) return; + new TCanvas("Cbitplot"); + if (bitPlot) { + delete bitPlot; + bitPlot=NULL; + } + bitPlot=(TH1F*)(bitHisto[iadc]->Clone("bitplot")); + bitPlot->Draw(); +} + + + + + + + + + + +void ctbAcquisition::ChangeSerialOffset(Long_t a){ + ChangeSerialOffset(); +}; + + +void ctbAcquisition::ChangeDynamicRange(Long_t a){ + ChangeDynamicRange(); +}; + +void ctbAcquisition::ChangeNumberOfChannels(Long_t a){ + ChangeNumberOfChannels(); +}; + + + +void ctbAcquisition::ChangeSerialOffset(){ + if (dataStructure) { + + cout << cbDetType->GetSelected()<< endl; + if (cbDetType->GetSelected()==MYTHEN301 || cbDetType->GetSelected()==MYTHEN302 ){ + cout << "settings offsets for MYTHEN" << endl; + mythen3_01_jctbData* ms=(mythen3_01_jctbData*)dataStructure; + ms->setSerialOffset(eSerOff->GetIntNumber()); + + } + } +}; + + +void ctbAcquisition::ChangeDynamicRange(){ + if (dataStructure) { + + cout << cbDetType->GetSelected()<< endl; + if (cbDetType->GetSelected()==MYTHEN301 || cbDetType->GetSelected()==MYTHEN302){ + cout << "settings dynamic range for MYTHEN" << endl; + mythen3_01_jctbData* ms=(mythen3_01_jctbData*)dataStructure; + ms->setDynamicRange(eDynRange->GetIntNumber()); + + } + } +}; + +void ctbAcquisition::ChangeNumberOfChannels(){ + if (dataStructure) { + cout << cbDetType->GetSelected()<< endl; + if (cbDetType->GetSelected()==MYTHEN301 || cbDetType->GetSelected()==MYTHEN302){ + cout << "settings number of channels for MYTHEN" << endl; + mythen3_01_jctbData* ms=(mythen3_01_jctbData*)dataStructure; + ms->setNumberOfCounters(eNumCount->GetIntNumber()); + + } + } +}; + + + +void ctbAcquisition::ChangeHistoLimitsPedSub(Long_t a){ + ChangeHistoLimitsPedSub(); +}; + + +void ctbAcquisition::ChangeHistoLimitsRaw(Long_t a){ + ChangeHistoLimitsRaw(); +} + +void ctbAcquisition::ChangeHistoLimitsPedSub(Bool_t a){ + ChangeHistoLimitsPedSub(); +}; + + +void ctbAcquisition::ChangeHistoLimitsRaw(Bool_t a){ + ChangeHistoLimitsRaw(); +} + + +void ctbAcquisition::ChangeHistoLimitsPedSub(){ + + cout << "set Limits ped sub hist " << eMinPedSub->GetNumber() << " " << eMaxPedSub->GetNumber() << endl; + + if (eMinPedSub->GetNumber()>eMaxPedSub->GetNumber()) + return; + + if (cbSubtractPedestal->IsOn()) { + if (cMinMaxPedSub->IsOn()) { + adcStack->SetMaximum( eMaxPedSub->GetNumber()); + adcStack->SetMinimum( eMinPedSub->GetNumber()); + if (h2DMap) { + h2DMap->SetMaximum( eMaxPedSub->GetNumber()); + h2DMap->SetMinimum( eMinPedSub->GetNumber()); + } + if (h1DMap) { + h1DMap->SetMaximum( eMaxPedSub->GetNumber()); + h1DMap->SetMinimum( eMinPedSub->GetNumber()); + } + if (countsStack->GetHistogram()) + countsStack->GetHistogram()->GetXaxis()->SetRangeUser(eMinPedSub->GetNumber(), eMaxPedSub->GetNumber()); + } else { + if (adcStack->GetHistogram()) + adcStack->GetHistogram()->GetYaxis()->UnZoom(); + if (h2DMap) { + h2DMap->GetZaxis()->UnZoom(); + } + if (h1DMap) { + h1DMap->GetYaxis()->UnZoom(); + } + if (countsStack->GetHistogram()) + countsStack->GetHistogram()->GetXaxis()->UnZoom(); + } + } + + +}; + + +void ctbAcquisition::ChangeHistoLimitsRaw(){ + + cout << "set Limits raw hist " << eMinRaw->GetNumber() << " " << eMaxRaw->GetNumber() << endl; + if (eMinRaw->GetNumber()>eMaxRaw->GetNumber()) + return; + + if (cbSubtractPedestal->IsOn()==0) { + if (cMinMaxRaw->IsOn()) { + adcStack->SetMaximum( eMaxRaw->GetNumber()); + adcStack->SetMinimum( eMinRaw->GetNumber()); + if (h2DMap) { + h2DMap->SetMaximum( eMaxRaw->GetNumber()); + h2DMap->SetMinimum( eMinRaw->GetNumber()); + } + if (h1DMap) { + h1DMap->SetMaximum( eMaxRaw->GetNumber()); + h1DMap->SetMinimum( eMinRaw->GetNumber()); + } + if (countsStack->GetHistogram()) + countsStack->GetHistogram()->GetXaxis()->SetRangeUser(eMinRaw->GetNumber(), eMaxRaw->GetNumber()); + } else { + + if (adcStack->GetHistogram()) + adcStack->GetHistogram()->GetYaxis()->UnZoom(); + if (h2DMap) { + h2DMap->GetZaxis()->UnZoom(); + } + + if (h1DMap) { + h1DMap->GetYaxis()->UnZoom(); + } + if (countsStack->GetHistogram()) + countsStack->GetHistogram()->GetXaxis()->UnZoom(); + + } + } + +} diff --git a/ctbGui/ctbAcquisition.h b/ctbGui/ctbAcquisition.h new file mode 100755 index 000000000..9821d9c58 --- /dev/null +++ b/ctbGui/ctbAcquisition.h @@ -0,0 +1,235 @@ +#ifndef CTBACQUISITION_H +#define CTBACQUISITION_H +#include + +#include "ctbAdcs.h" +#include "ctbSignals.h" +#include "ctbPattern.h" +class TGTextEntry; +class TGLabel; +class TGNumberEntry; +class TGCheckButton; +class TThread; +class TGraph; +class TMultiGraph; +class THStack; +class TGButtonGroup; +class TGRadioButton; +class TGComboBox; +class TTimer; +class TCanvas; +class TH2F; +class TH1F; +class TGLabel; +class TGTextButton; + +class multiSlsDetector; +class detectorData; + +template class slsDetectorData; + +class singlePhotonDetector; +//class singlePhotonDetector; +class commonModeSubtraction; + +#include +#include +using namespace std; + +class ctbAcquisition : public TGGroupFrame { + + + enum {DESERIALIZER, MOENCH04, MOENCH02, ADCSAR2, MYTHEN301, MYTHEN302}; + + + private: + TGTextEntry *eOutdir; + TGTextEntry *eFname; + TGNumberEntry *eFindex; + TGCheckButton *cFileSave; + + + TGNumberEntry *eSerOff; + TGNumberEntry *eDynRange; + TGNumberEntry *eNumCount; + + + TGNumberEntry *eFitADC; + TGNumberEntry *eBitPlot; + TGNumberEntry *eMinRaw; + TGNumberEntry *eMaxRaw; + TGNumberEntry *eMinPedSub; + TGNumberEntry *eMaxPedSub; + TGCheckButton *cMinMaxRaw; + TGCheckButton *cMinMaxPedSub; + + + + + TGNumberEntry *eMeasurements; + + + + TGTextButton *bStatus; + // TGTextButton + TGCheckButton *cCompile; + TGTextButton *cLoad; + // TGCheckButton *cRun; + + TThread *acqThread; + + + THStack *adcStack; + THStack *bitStack; + THStack *countsStack; + + + TH1F *adcHisto[NADCS]; + TH1F *countsHisto[NADCS]; + + TH1F *bitHisto[NSIGNALS]; + float bitOffset[NSIGNALS]; + + // int enableFlag[NADCS+4]; + int roMode; + + int dBitOffset; + + + + TH1F *adcFit; + TH1F *bitPlot; + TH1F *countsFit; + + + + TH2F *h2DMap; // for 2D detectors + TH1F *h1DMap; //for 1D detectors + + // TH2F *h2Scan; // for 2D detectors + // TMultiGraph *mgAdcs; + // TH1I *plotAdc[NADCS]; + + + multiSlsDetector* myDet; + + int plotFlag[NADCS]; + int bitPlotFlag[NSIGNALS]; + + int ip; + // int nChannels; + // int chanEnable; + //int nADCs; + + std::vector dbitlist; + std::vector adclist; + + TGButtonGroup *bgPlot;// = new TGVButtonGroup(main_frame); + TGRadioButton *rbPlotOff; + TGRadioButton *rbWaveform; + TGRadioButton *rbDistribution; + TGRadioButton *rb2D; + // TGRadioButton *rbScan; + TGComboBox *cbDetType; + TGCheckButton *cbGetPedestal; + TGCheckButton *cbSubtractPedestal; + TGCheckButton *cbCommonMode; + TGTextButton *bResetPedestal; + + TGLabel *lClickX; + TGLabel *lClickY; + TGLabel *lClickValue; + + + TCanvas *myCanvas; + TTimer *plotTimer; + + char patternFile[10000]; + char patternCompiler[10000]; + + int globalPlot; + + int nAnalogSamples, nDigitalSamples; + // int iScanStep; + + slsDetectorData *dataStructure; + singlePhotonDetector *photonFinder; + //singlePhotonDetector *photonFinder; + commonModeSubtraction *commonMode; + int cmSub; + + int stop; + + uint64_t dBitMask; + + int deserializer; + + public: + ctbAcquisition(TGVerticalFrame*, multiSlsDetector*); + void setOutdir(); + void setFname(); + void setMeasurements(); + void setFsave(Bool_t); + void changePlot(Int_t); + void changeDetector(Int_t); + void changePlot(); + void changeDetector(); + void setFindex(); + void Draw(); + void setCanvas(TCanvas*); + + void toggleAcquisition(); + void loadPattern(); + static void* ThreadHandle(void *arg); + void update(); + void acquisitionFinished(); + // string getParameters(); + + void setGraph (int i ,int en, Pixel_t col); + void setBitGraph (int i ,int en, Pixel_t col); + void startAcquisition(); + static int progressCallback(double,void*); + static int dataCallback(detectorData*, int,int, void*); + int StopFlag; + + int plotData(detectorData*, int); + + void setPatternFile(const char* t); + + void setPatternCompiler(const char* t); + + void setAnalogSamples(int); + void setDigitalSamples(int); + + void setADCEnable(Int_t); + void setDbitEnable(Int_t); + void setReadoutMode(int); + void updateChans(); + + void resetPedestal(); + + void ToggleCommonMode(Bool_t); + void TogglePedSub(Bool_t); + void ChangeHistoLimitsPedSub(Long_t ); + void ChangeHistoLimitsRaw(Long_t); + void ChangeHistoLimitsPedSub( ); + void ChangeHistoLimitsRaw(); + void ChangeHistoLimitsPedSub(Bool_t ); + void ChangeHistoLimitsRaw(Bool_t); + + + void ChangeSerialOffset(); + void ChangeSerialOffset(Long_t); + void ChangeNumberOfChannels(); + void ChangeNumberOfChannels(Long_t); + void ChangeDynamicRange(); + void ChangeDynamicRange(Long_t); + + + void canvasClicked(); + void FitADC(); + void plotBit(); + ClassDef(ctbAcquisition,0) +}; + +#endif diff --git a/ctbGui/ctbAdcs.cpp b/ctbGui/ctbAdcs.cpp new file mode 100755 index 000000000..927b8de3a --- /dev/null +++ b/ctbGui/ctbAdcs.cpp @@ -0,0 +1,710 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "ctbAdcs.h" +#include "multiSlsDetector.h" +#include "slsDetectorCommand.h" + +using namespace std; + + + +ctbAdc::ctbAdc(TGVerticalFrame *page, int i, multiSlsDetector *det) + : TGHorizontalFrame(page, 800,800), id(i), myDet(det) { + + TGHorizontalFrame *hframe=this; + char tit[100]; + + page->AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + + + + sprintf(tit, "ADC%d", id); + + sAdcLabel= new TGLabel(hframe, tit); + hframe->AddFrame(sAdcLabel,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + sAdcLabel->MapWindow(); + sAdcLabel->SetTextJustify(kTextLeft); + + + + + + + sAdcInvert= new TGCheckButton(hframe, "Inv"); + hframe->AddFrame( sAdcInvert,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + sAdcInvert->MapWindow(); + sAdcInvert->Connect("Toggled(Bool_t)","ctbAdc",this,"ToggledInvert(Bool_t)"); + + + sAdcEnable= new TGCheckButton(hframe, "En"); + hframe->AddFrame( sAdcEnable,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + sAdcEnable->MapWindow(); + // sAdcEnable->SetOn(kTRUE); + // sAdcEnable->SetEnabled(kFALSE); + sAdcEnable->Connect("Toggled(Bool_t)","ctbAdc",this,"ToggledEnable(Bool_t)"); + + + + sAdcPlot= new TGCheckButton(hframe, "Plot"); + hframe->AddFrame( sAdcPlot,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + sAdcPlot->MapWindow(); + + + sAdcPlot->Connect("Toggled(Bool_t)","ctbAdc",this,"ToggledPlot(Bool_t)"); + + + + fColorSel = new TGColorSelect(hframe, id+1, 0); + + fColorSel->Connect("ColorSelected(Pixel_t)","ctbAdc",this,"ColorChanged(Pixel_t)"); + hframe->AddFrame(fColorSel, new TGLayoutHints(kLHintsTop | + kLHintsLeft, 2, 0, 2, 2)); + + + fColorSel->SetColor(TColor::Number2Pixel(id+1)); + // sprintf(tit,"adc%d",id); +// gADC=new TGraph(); +// gADC->SetName(tit); +// gADC->SetLineColor(id+1); +// gADC->SetMarkerColor(id+1); + + + +}; +Pixel_t ctbAdc::getColor(){ + return fColorSel->GetColor(); +} +Bool_t ctbAdc::getEnabled(){ + return getPlot(); +} +Bool_t ctbAdc::getPlot(){ + return sAdcPlot->IsOn(); +} +Bool_t ctbAdc::getInverted(){ + return sAdcInvert->IsOn(); +} + +Bool_t ctbAdc::getEnable(){ + return sAdcEnable->IsOn(); +} + + + +void ctbAdc::setInverted(Bool_t b){ + // cout << id << "set enabled " << b << endl; + if (b) + sAdcInvert->SetOn(kTRUE,kTRUE); + else + sAdcInvert->SetOn(kFALSE,kTRUE); + +} + + +void ctbAdc::setEnable(Bool_t b){ + // cout << id << "set enabled " << b << endl; + if (b) + sAdcEnable->SetOn(kTRUE,kFALSE); + else + sAdcEnable->SetOn(kFALSE,kFALSE); + +} + + + + + +void ctbAdc::setAdcAlias(char *tit, int plot, int color) { + if (tit) + sAdcLabel->SetText(tit); + if (plot>0) + sAdcPlot->SetOn(kTRUE,kTRUE); + else if (plot==0) + sAdcPlot->SetOn(kFALSE,kTRUE); + if (color>=0) + fColorSel->SetColor(color); + fColorSel->SetEnabled(sAdcPlot->IsOn()); +} + + +string ctbAdc::getAdcAlias() { + + char line[1000]; + sprintf(line,"ADC%d %s %d %x\n",id,sAdcLabel->GetText()->Data(),sAdcPlot->IsOn(),fColorSel->GetColor()); + return string(line); +} + +void ctbAdc::update() { + + + //Emit("ToggledAdcEnable(Int_t)", id); + +} + + +void ctbAdc::ToggledPlot(Bool_t b){ + + // Long_t mask=b<SetEnabled(kTRUE); + else + fColorSel->SetEnabled(kFALSE); + + // fColorSel->SetEnabled(sAdcPlot->IsOn()); + Emit("ToggledAdcPlot(Int_t)", id); + +} + + + +void ctbAdc::ToggledInvert(Bool_t b){ + + + // fColorSel->SetEnabled(sAdcPlot->IsOn()); + Emit("ToggledAdcInvert(Int_t)", id); + +} + + + +void ctbAdc::ToggledEnable(Bool_t b){ + + + fColorSel->SetEnabled(sAdcPlot->IsOn()); + Emit("ToggledAdcEnable(Int_t)", id); + +} + + + + + + +void ctbAdc::ColorChanged(Pixel_t) { + + Emit("ToggledAdcPlot(Int_t)", id); + +} + +void ctbAdc::ToggledAdcPlot(Int_t b){ + + + Emit("ToggledAdcPlot(Int_t)", id); + +} + +void ctbAdc::ToggledAdcInvert(Int_t b){ + + + Emit("ToggledAdcInvert(Int_t)", id); + +} + +void ctbAdc::ToggledAdcEnable(Int_t b){ + + + Emit("ToggledAdcEnable(Int_t)", id); + +} + + + + +void ctbAdc::setEnabled(Bool_t b){ + // cout << id << "set enabled " << b << endl; + if (b) + sAdcPlot->SetOn(kTRUE,kFALSE); + else + sAdcPlot->SetOn(kFALSE,kFALSE); + +} + + + + + + + + + + +ctbAdcs::ctbAdcs(TGVerticalFrame *page, multiSlsDetector *det) + : TGGroupFrame(page,"Adcs",kVerticalFrame), myDet(det) { + + + SetTitlePos(TGGroupFrame::kLeft); + page->AddFrame(this,new TGLayoutHints( kLHintsTop | kLHintsExpandX , 10,10,10,10)); + MapWindow(); + + char tit[100]; + + + TGHorizontalFrame* hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + + + int idac=0; + + + + + + TGHorizontalFrame* hhframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hhframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hhframe->MapWindow(); + + TGVerticalFrame *vframe; + + + + + for (idac=0; idacAddFrame(vframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + vframe->MapWindow(); + + + + } + + sAdc[idac]=new ctbAdc(vframe,idac,myDet); + + + sAdc[idac]->Connect("ToggledAdcPlot(Int_t)","ctbAdcs",this,"ToggledAdcPlot(Int_t)"); + sAdc[idac]->Connect("ToggledAdcInvert(Int_t)","ctbAdcs",this,"ToggledAdcInvert(Int_t)"); + sAdc[idac]->Connect("ToggledAdcEnable(Int_t)","ctbAdcs",this,"ToggledAdcEnable(Int_t)"); + + } + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + bCheckHalf[0]=new TGTextButton(hframe, "All 0-15"); + hframe->AddFrame(bCheckHalf[0],new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5)); + bCheckHalf[0]->MapWindow(); + bCheckHalf[0]->Connect("Clicked()","ctbAdcs",this,"CheckHalf0()"); + + + bRemoveHalf[0]=new TGTextButton(hframe, "None 0-15"); + hframe->AddFrame(bRemoveHalf[0],new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 5, 5, 5, 5)); + bRemoveHalf[0]->MapWindow(); + bRemoveHalf[0]->Connect("Clicked()","ctbAdcs",this,"RemoveHalf0()"); + + + bCheckHalf[1]=new TGTextButton(hframe, "All 16-23"); + hframe->AddFrame(bCheckHalf[1],new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5)); + bCheckHalf[1]->MapWindow(); + bCheckHalf[1]->Connect("Clicked()","ctbAdcs",this,"CheckHalf1()"); + // bCheckAll->Connect("Clicked()","ctbAdcs",this,"CheckAll()"); + + + bRemoveHalf[1]=new TGTextButton(hframe, "None 16-23"); + hframe->AddFrame(bRemoveHalf[1],new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 5, 5, 5, 5)); + bRemoveHalf[1]->MapWindow(); + bRemoveHalf[1]->Connect("Clicked()","ctbAdcs",this,"RemoveHalf1()"); + // bRemoveAll->Connect("Clicked()","ctbAdcs",this,"RemoveAll()"); + + + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + bCheckAll=new TGTextButton(hframe, "All"); + hframe->AddFrame(bCheckAll,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5)); + bCheckAll->MapWindow(); + bCheckAll->Connect("Clicked()","ctbAdcs",this,"CheckAll()"); + + + bRemoveAll=new TGTextButton(hframe, "None"); + hframe->AddFrame(bRemoveAll,new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 5, 5, 5, 5)); + bRemoveAll->MapWindow(); + bRemoveAll->Connect("Clicked()","ctbAdcs",this,"RemoveAll()"); + + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + TGLabel *label= new TGLabel(hframe, "Inversion mask: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + eInversionMask = new TGNumberEntry(hframe, 0, 16,999, TGNumberFormat::kNESHex, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + + hframe->AddFrame(eInversionMask,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eInversionMask->MapWindow(); + eInversionMask->Resize(150,30); + eInversionMask->SetState(kFALSE); + + + hframe=new TGHorizontalFrame(this, 800,50); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + label= new TGLabel(hframe, "Enable mask: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + eEnableMask = new TGNumberEntry(hframe, 0, 16,999, TGNumberFormat::kNESHex, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + + hframe->AddFrame(eEnableMask,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eEnableMask->MapWindow(); + eEnableMask->Resize(150,30); + eEnableMask->SetState(kFALSE); + +} + + +int ctbAdcs::setEnable(int reg) { + + // char aargs[10][100]; + // char *args[10]; + string retval; + int retreg; + + // for (int i=0; i<10; i++) args[i]=aargs[i]; + + // sprintf(args[0],"adcenable"); + // sprintf(args[1],"%x",reg); + // slsDetectorCommand *cmd=new slsDetectorCommand(myDet); + // if (reg>-1) { + // retval=cmd->executeLine(1,args,slsDetectorDefs::PUT_ACTION); + // } + if (reg>-1) { + try { + myDet->setADCEnableMask(reg); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + } + // retval=cmd->executeLine(1,args,slsDetectorDefs::GET_ACTION); + // cout <<"enable: " << retval << endl;; + // delete cmd; + + // sscanf(retval.c_str(),"%x",&retreg); + try { + retreg=myDet->getADCEnableMask(); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eEnableMask->SetHexNumber(retreg); + + return retreg; +} + +int ctbAdcs::setInvert(int reg) { + + // char aargs[10][100]; + // char *args[10]; + string retval; + int retreg; + + // for (int i=0; i<10; i++) args[i]=aargs[i]; + + //sprint// f(args[0],"adcinvert"); + // sprintf(args[1],"%x",reg); + // slsDetectorCommand *cmd=new slsDetectorCommand(myDet); + + if (reg>-1) { + try { + myDet->setADCInvert(reg); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + //retval=cmd->executeLine(1,args,slsDetectorDefs::PUT_ACTION); + } + try { + retreg=myDet->getADCInvert(); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + // retval=cmd->executeLine(1,args,slsDetectorDefs::GET_ACTION); + // cout <<"invert: " << retval << endl;; + // delete cmd; + + // sscanf(retval.c_str(),"%x",&retreg); + eInversionMask->SetHexNumber(retreg); + return retreg; +} + + + +void ctbAdcs::update() { + Int_t invreg;//=myDet->readRegister(67);//(120); + Int_t disreg;//=myDet->readRegister(120);//(94); + // for (int i=0; i<10; i++) + // args[i]=aargs[i]; + + // string retval; + // sprintf(args[0],"adcenable"); + // slsDetectorCommand *cmd=new slsDetectorCommand(myDet); + // retval=cmd->executeLine(1,args,slsDetectorDefs::GET_ACTION); + // delete cmd; + // // cout << retval << endl; + + // sscanf(retval.c_str(),"adcenable %x",&disreg); + + // eInversionMask->SetHexNumber(invreg); + // eEnableMask->SetHexNumber(disreg); + + disreg=setEnable(); + invreg=setInvert(); + + + for (int is=0; issetAdcAlias(NULL,-1,-1); + if (invreg & (1<setInverted(kTRUE); + else + sAdc[is]->setInverted(kFALSE); + + if (disreg & (1<setEnable(kTRUE); + else + sAdc[is]->setEnable(kFALSE); + + + } + + Emit("AdcEnable(Int_t)", disreg); + +} +string ctbAdcs::getAdcParameters() { + + ostringstream line; + + line << "reg "<< hex << setInvert() << "# ADC invert reg" << dec << endl; + line << "reg "<< hex << setEnable() << " # ADC enable reg"<< dec << endl; + // line << "reg "<< hex << 67 << " " << myDet->readRegister(67) << "# ADC invert reg" << dec << endl; + // line << "reg "<< hex << 120 << " " << myDet->readRegister(120) << " # ADC enable reg"<< dec << endl; + // // line << "reg "<< hex << 94 << " " << myDet->readRegister(94) << " # ADC enable reg"<< dec << endl; + return line.str(); + +} + + +void ctbAdcs::CheckAll() { + + + for (int is=0; issetEnabled(kTRUE); +} + + +void ctbAdcs::RemoveAll() { + + + for (int is=0; issetEnabled(kFALSE); +} + + + +void ctbAdcs::CheckHalf0() { + + + for (int is=0; issetEnabled(kTRUE); +} + + +void ctbAdcs::RemoveHalf0() { + + + for (int is=0; issetEnabled(kFALSE); +} + +void ctbAdcs::CheckHalf1() { + + + for (int is=NADCS/2; issetEnabled(kTRUE); +} + + +void ctbAdcs::RemoveHalf1() { + + + for (int is=NADCS/2; issetEnabled(kFALSE); +} + + +// TGraph* ctbAdcs::getGraph(int i) { + +// if (i>=0 && igetGraph(); +// return NULL; +// } + +int ctbAdcs::setAdcAlias(string line) { + + int is=-1, plot=0, color=-1; + char tit[100]; + int narg=sscanf(line.c_str(),"ADC%d %s %d %x",&is,tit,&plot, &color); + if (narg<2) + return -1; + if (narg!=3) + color=-1; + if (is>=0 && issetAdcAlias(tit,plot,color); + } + return is; + +} + +string ctbAdcs::getAdcAlias() { + + ostringstream line; + + for (int is=0; isgetAdcAlias(); + + return line.str(); +} + + +void ctbAdcs::ToggledAdcPlot(Int_t b){ + + + Emit("ToggledAdcPlot(Int_t)", b); + +} + +void ctbAdcs::AdcEnable(Int_t b){ + Emit("AdcEnable(Int_t)", b); +} + + +void ctbAdcs::ToggledAdcEnable(Int_t b){ + + + Int_t oreg=setEnable();//myDet->readRegister(67); + Int_t m=1<getEnable()) + oreg|=m; + else + oreg&=~m; + +// cout << dec << sizeof(Long64_t) << " " << mask << " " << hex << m << " ioreg " << oreg << endl; + + setEnable(oreg);//)writeRegister(67, oreg); + //oreg=setEnable();//myDet->readRegister(67); + + + Emit("AdcEnable(Int_t)", oreg); + //cout << "enable!" << endl; + // Emit("ToggledAdcPlot(Int_t)", b); + +} + + +void ctbAdcs::ToggledAdcInvert(Int_t b){ + + // char val[1000]; + Int_t oreg=setInvert();//myDet->readRegister(67); + Int_t m=1<getInverted()) + oreg|=m; + else + oreg&=~m; + +// cout << dec << sizeof(Long64_t) << " " << mask << " " << hex << m << " ioreg " << oreg << endl; + + setInvert(oreg);//)writeRegister(67, oreg); + // oreg=setInvert();//myDet->readRegister(67); + +// cout << dec << sizeof(Long64_t) << " " << mask << " " << hex << m << " ioreg " << oreg << endl; + + //sprintf(val,"%X",oreg); + //eInversionMask->SetHexNumber(oreg); +} + + + + + +Pixel_t ctbAdcs::getColor(int i){ + if (i>=0 && igetColor(); +} + +Bool_t ctbAdcs::getEnabled(int i){ + if (i>=0 && igetEnabled(); + +} + +Bool_t ctbAdcs::getEnable(int i){ + if (i>=0 && igetEnable(); + +} + +Bool_t ctbAdcs::getPlot(int i){ + if (i>=0 && igetPlot(); + +} diff --git a/ctbGui/ctbAdcs.h b/ctbGui/ctbAdcs.h new file mode 100755 index 000000000..7fe136188 --- /dev/null +++ b/ctbGui/ctbAdcs.h @@ -0,0 +1,151 @@ + + + +#ifndef CTBADCS_H +#define CTBADCS_H +#include + + +#define NADCS 32 + +class TRootEmbeddedCanvas; +class TGButtonGroup; +class TGVerticalFrame; +class TGHorizontalFrame; +class TGTextEntry; +class TGLabel; +class TGNumberEntry; +class TH2F; +class TGComboBox; +class TGCheckButton; +class TGColorSelect; +class TColor; + +class THStack; +class TGraphErrors; +class TGTextButton; +class TGTab; + +class TGraph; + +class multiSlsDetector; + +#include +using namespace std; + +class ctbAdc : public TGHorizontalFrame { + + + private: + + + TGLabel *sAdcLabel; + TGCheckButton *sAdcEnable; + TGCheckButton *sAdcPlot; + TGCheckButton *sAdcInvert; + + TGColorSelect *fColorSel; + + // TGraph *gADC; + + int id; + multiSlsDetector *myDet; + + public: + ctbAdc(TGVerticalFrame *page, int i, multiSlsDetector *det); + + + void setAdcAlias(char *tit, int plot, int color); + string getAdcAlias(); + void ToggledAdcPlot(Int_t b); + void ToggledAdcEnable(Int_t b); + void ToggledAdcInvert(Int_t b); + + + void ToggledPlot(Bool_t b); + void ToggledEnable(Bool_t b); + void ToggledInvert(Bool_t b); + void ColorChanged(Pixel_t); + void setEnabled(Bool_t b); + Bool_t getEnabled(); + // TGraph *getGraph(); + void update(); + + Pixel_t getColor(); + + Bool_t getEnable(); + void setEnable(Bool_t); + Bool_t getInverted(); + Bool_t getPlot(); + void setInverted(Bool_t); + + ClassDef(ctbAdc,0) + }; + + + +class ctbAdcs : public TGGroupFrame { +private: + + ctbAdc *sAdc[NADCS]; + multiSlsDetector *myDet; + + + TGTextButton *bCheckAll; + TGTextButton *bRemoveAll; + TGTextButton *bCheckHalf[2]; + TGTextButton *bRemoveHalf[2]; + TGNumberEntry *eInversionMask; + TGNumberEntry *eEnableMask; + + +/* TGTextButton *bPlotSelected; */ +/* TGNumberEntry *eMinX; */ +/* TGNumberEntry *eMaxX; */ +/* TGNumberEntry *eMinY; */ +/* TGNumberEntry *eMaxY; */ + + + +/* TGTextButton *bGetPixel; */ +/* TGNumberEntry *ePixelX; */ +/* TGNumberEntry *ePixelY; */ +/* TGLabel *lPixelValue; */ + +public: + + ctbAdcs(TGVerticalFrame *page, multiSlsDetector *det); + int setAdcAlias(string line); + string getAdcAlias(); + string getAdcParameters(); + void ToggledAdcPlot(Int_t); + void ToggledAdcInvert(Int_t); + void ToggledAdcEnable(Int_t); + void AdcEnable(Int_t b); + // TGraph *getGraph(int i); + void CheckAll(); + void RemoveAll(); + void update(); + + int setInvert(int reg=-1); + int setEnable(int reg=-1); + + + Pixel_t getColor(int i); + Bool_t getEnabled(int i); + Bool_t getPlot(int i); + Bool_t getEnable(int i); + + void CheckHalf0(); + void RemoveHalf0(); + + void CheckHalf1(); + void RemoveHalf1(); + + + ClassDef(ctbAdcs,0) +}; + +#endif + + diff --git a/ctbGui/ctbDacs.cpp b/ctbGui/ctbDacs.cpp new file mode 100755 index 000000000..afb137567 --- /dev/null +++ b/ctbGui/ctbDacs.cpp @@ -0,0 +1,251 @@ + +#include +#include +#include + +#include +#include +#include +#include + +#include "ctbDacs.h" +#include "multiSlsDetector.h" +#include "sls_detector_defs.h" + +using namespace std; + + + + + +ctbDac::ctbDac(TGGroupFrame *page, int idac, multiSlsDetector *det) : TGHorizontalFrame(page, 800,50) , id(idac), myDet(det) { + + + TGHorizontalFrame *hframe=this; + + page->AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + MapWindow(); + + char tit[100]; + + + sprintf(tit, "DAC %d:",idac); + + dacsLabel= new TGCheckButton(hframe, tit);// new TGLabel(hframe, tit); + dacsLabel->SetOn(kTRUE, kTRUE); + + dacsLabel->Connect("Toggled(Bool_t)","ctbDac",this,"setOn(Bool_t)"); + + + hframe->AddFrame(dacsLabel,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + dacsLabel->MapWindow(); + dacsLabel->SetTextJustify(kTextLeft); + + + dacsEntry = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 65535); + + hframe->AddFrame(dacsEntry,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5)); + dacsEntry->MapWindow(); + dacsEntry->Resize(150,30); + + + dacsUnit= new TGCheckButton(hframe, "mV"); + // if (idac!=slsDetectorDefs::ADC_VPP) { + hframe->AddFrame( dacsUnit,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + dacsUnit->MapWindow(); + if (idac==slsDetectorDefs::ADC_VPP) { + dacsUnit->SetEnabled(kFALSE); + hframe->HideFrame(dacsUnit); + dacsUnit->MapWindow(); + cout << "hiding!" << endl; + } + if (idac==slsDetectorDefs::HIGH_VOLTAGE) { + dacsUnit->SetText("V"); + dacsUnit->SetOn(kTRUE,kTRUE); + dacsUnit->SetEnabled(kFALSE); + } + //} + + + + sprintf(tit, "xxx"); + dacsValue= new TGLabel(hframe, tit); + hframe->AddFrame( dacsValue,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + dacsValue->MapWindow(); + dacsValue->SetTextJustify(kTextLeft); + + TGTextEntry *e=dacsEntry->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbDac",this,"setValue()"); + // e->Connect("ValueSet(Long_t)","ctbDac",this,"setValue(Long_t)"); + dacsEntry->Connect("ValueSet(Long_t)","ctbDac",this,"setValue(Long_t)"); + // cout << "(((((((((((((((((((((((((((((((" << dacsEntry->GetListOfSignals()->At(0)->IsA() << endl; + + +} + + + +int ctbDac::setLabel(char *tit, int mv) { + if(tit) + dacsLabel->SetText(tit); + if (mv==1) + dacsUnit->SetOn(kTRUE,kTRUE); + else if (mv==0) + dacsUnit->SetOn(kFALSE,kTRUE); + // else if (mv==2) { + // ;} + // else if (mv==3) + // ; + return id; + +} + +string ctbDac::getLabel() { + + ostringstream line; + line << dacsLabel->GetText() << " " << dacsUnit->IsOn() << endl; + + // line << "DAC" << dec << id << " " << dacsUnit->IsOn() << endl; + + return line.str(); + +} + + +void ctbDac::setValue(Long_t a) {setValue();} + +void ctbDac::setValue() { + + + + cout << "setting dac! "<< id << " value " << dacsEntry->GetIntNumber() << " units " << dacsUnit->IsOn() << endl; + try { + myDet->setDAC(dacsEntry->GetIntNumber(), (slsDetectorDefs::dacIndex)id, dacsUnit->IsOn()); } catch (...) { + cout << "Do nothing for this error" << endl; + } + + getValue(); + +} + +void ctbDac::setOn(Bool_t b) { + + + + // cout << "setting dac! "<< id << endl; + + if ( dacsLabel->IsOn()) { + setValue(); + } else { + try { + myDet->setDAC(-100, (slsDetectorDefs::dacIndex)id, 0); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + } + getValue(); + +} + +int ctbDac::getValue() { + int val; + try { + val=myDet->setDAC(-1,(slsDetectorDefs::dacIndex)id, dacsUnit->IsOn()); + } catch (...) { + cout << "Do nothing for this error" << endl; + } + char s[100]; + cout << "dac " << id << " " << val << endl; + sprintf(s,"%d",val); + dacsValue->SetText(s); + if (val>=0) { + dacsLabel->SetOn(kTRUE); + } else { + dacsLabel->SetOn(kFALSE); + } + + + return val; + +} + + + + + +ctbDacs::ctbDacs(TGVerticalFrame *page, multiSlsDetector *det) : TGGroupFrame(page,"DACs",kVerticalFrame) , myDet(det){ + + + SetTitlePos(TGGroupFrame::kLeft); + page->AddFrame(this,new TGLayoutHints( kLHintsTop | kLHintsExpandX , 10,10,10,10)); + MapWindow(); + + // cout << "window mapped " << endl; + + for (int idac=0; idacsetLabel("ADC Vpp",2); + dacs[NDACS+1]->setLabel("High Voltage",3); + +} + + +int ctbDacs::setDacAlias(string line) { + + int is=-1, mv=0; + char tit[100]; + int narg=sscanf(line.c_str(),"DAC%d %s %d",&is,tit,&mv); + if (narg<2) + return -1; + if (is>=0 && issetLabel(tit,mv); + return is; + +} + +string ctbDacs::getDacAlias() { + ostringstream line; + + for (int i=0; igetLabel() << endl; + return line.str(); + +} + + + + + +string ctbDacs::getDacParameters() { + + + ostringstream line; + + for (int i=0; igetValue << endl; + line << "dac:" << i << " " << dacs[i]->getValue() << endl; + } + return line.str(); + + +} + + + +void ctbDacs::update() { + + for (int idac=0; idacgetValue(); + } + + + +} diff --git a/ctbGui/ctbDacs.h b/ctbGui/ctbDacs.h new file mode 100755 index 000000000..ff921fa6b --- /dev/null +++ b/ctbGui/ctbDacs.h @@ -0,0 +1,74 @@ + + +#ifndef CTBDACS_H +#define CTBDACS_H +#include + + +#define NDACS 18 +//#define NDACS 16 + + +class TGTextEntry; +class TGLabel; +class TGNumberEntry; +class TGCheckButton; + + +class multiSlsDetector; + +#include +using namespace std; + + +class ctbDac : public TGHorizontalFrame { + + + protected: + // TGLabel *dacsLabel; + TGNumberEntry *dacsEntry; + TGCheckButton *dacsUnit; + TGCheckButton *dacsLabel; + TGLabel *dacsValue; + int id; + + multiSlsDetector* myDet; + public: + ctbDac(TGGroupFrame*, int , multiSlsDetector*); + void setValue(); + void setValue(Long_t); + int getValue(); + void setOn(Bool_t); + + int setLabel(char *tit, int mv); + string getLabel(); + + + + ClassDef(ctbDac,0) +}; + +class ctbDacs : public TGGroupFrame { +private: + + + + ctbDac *dacs[NDACS+2]; + + multiSlsDetector* myDet; + +public: + ctbDacs(TGVerticalFrame *page, multiSlsDetector*); + + int setDacAlias(string line); + // int setDacAlias(string line); + string getDacAlias(); + string getDacParameters(); + + void update(); + + ClassDef(ctbDacs,0) +}; + +#endif + diff --git a/ctbGui/ctbGui.cpp b/ctbGui/ctbGui.cpp new file mode 100755 index 000000000..e5df8b6db --- /dev/null +++ b/ctbGui/ctbGui.cpp @@ -0,0 +1,161 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include "multiSlsDetector.h" +#include "sls_detector_defs.h" +//#include "sls_receiver_defs.h" +#include "ctbMain.h" +using namespace std; + + +int main(int argc, char **argv) { + + + string afname, cfname, pfname; + int id=0; + + int af=0, cf=0, pf=0; + + + cout << " *** " << argc << endl; + for (int ia=0; iasetOnline(slsDetectorDefs::ONLINE_FLAG); + + //cout << id << " " << myDet << " " << myDet->setOnline() << endl; + if (cf) { + myDet->readConfigurationFile(cfname); + } else + cout << "No config file specified" << endl; + + cout << "aa" << endl; + + cout << "Created multi detector id " << id << " hostname " << myDet->getHostname() << endl; + + + cout << "bb" << endl; + if (pf) { + myDet->retrieveDetectorSetup(pfname); + } else + cout << "No parameter file specified" << endl; + + + + + + /***********Create GUI stuff *******************/ + TApplication theApp("App",&argc,argv); + + + gStyle->SetDrawBorder(0); + gStyle->SetCanvasColor(kWhite); + gStyle->SetCanvasDefH(800); + gStyle->SetCanvasDefW(800); + gStyle->SetCanvasBorderMode(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPaintTextFormat("5.2f"); + gStyle->SetLineWidth(2); + gStyle->SetTextSize(1.1); + gStyle->SetLabelSize(0.04,"xy"); + gStyle->SetTitleSize(0.05,"xy"); + gStyle->SetTitleOffset(1.0,"x"); + gStyle->SetTitleOffset(1.1,"y"); + gStyle->SetPadTopMargin(0.15); + gStyle->SetPadRightMargin(0.15); + gStyle->SetPadBottomMargin(0.15); + gStyle->SetPadLeftMargin(0.15); + gStyle->SetLegendBorderSize(1); + gStyle->SetFrameBorderMode(0); + gStyle->SetFrameFillColor(kWhite); + // gStyle->SetLegendFillColor(kWhite); + gStyle->SetTitleFillColor(kWhite); + gStyle->SetFillColor(kWhite); + gStyle->SetStatFontSize(0.03); + gStyle->SetStatBorderSize(1); + gStyle->SetStatFormat("6.4g"); + gStyle->SetStatX(0.95); + gStyle->SetStatY(0.95); + gStyle->SetStatW(0.2); + gStyle->SetStatH(0.2); + gStyle->SetTitleX(0.1); + gStyle->SetTitleY(0.95); + gStyle->SetTitleBorderSize(0); + gStyle->SetTitleFontSize(0.05); + gROOT->SetStyle("Default"); + + + TColor::InitializeColors(); + const Int_t NRGBs = 5; + const Int_t NCont = 90; + + Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; + Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; + Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; + Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; + TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); + gStyle->SetNumberContours(NCont); + + + gROOT->ForceStyle(); + ctbMain *mf=new ctbMain(gClient->GetRoot(),myDet); + + cout << " *** " << argc << endl; + for (int ia=0; ialoadAlias(afname); + else + cout << "no alias specified" << endl; + + theApp.Run(); + + return 0; +} diff --git a/ctbGui/ctbLinkDef.h b/ctbGui/ctbLinkDef.h new file mode 100755 index 000000000..dd61a0bba --- /dev/null +++ b/ctbGui/ctbLinkDef.h @@ -0,0 +1,15 @@ +#pragma link C++ class ctbMain; +#pragma link C++ class ctbDacs; +#pragma link C++ class ctbDac; +#pragma link C++ class ctbSignals; +#pragma link C++ class ctbSignal; +#pragma link C++ class ctbAdc; +#pragma link C++ class ctbAdcs; +#pragma link C++ class ctbLoop; +#pragma link C++ class ctbWait; +#pragma link C++ class ctbPattern; +#pragma link C++ class ctbAcquisition; +#pragma link C++ class ctbPower; +#pragma link C++ class ctbPowers; +#pragma link C++ class ctbSlowAdc; +#pragma link C++ class ctbSlowAdcs; diff --git a/ctbGui/ctbMain.cpp b/ctbGui/ctbMain.cpp new file mode 100755 index 000000000..f66560aa4 --- /dev/null +++ b/ctbGui/ctbMain.cpp @@ -0,0 +1,709 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +//#include +//#include + + + + + + + +#include +#include +#include +#include + +#include "multiSlsDetector.h" +#include "ctbMain.h" +#include "ctbDacs.h" +#include "ctbSlowAdcs.h" +#include "ctbPowers.h" +#include "ctbSignals.h" +#include "ctbPattern.h" +#include "ctbAdcs.h" +#include "ctbAcquisition.h" +//#include "ctbActions.h" + +using namespace std; + + + +ctbMain::ctbMain(const TGWindow *p, multiSlsDetector *det) + : TGMainFrame(p,800,800), pwrs(NULL), senses(NULL) { + + myDet=det; + + Connect("CloseWindow()", "ctbMain", this, "CloseWindow()"); + + + + + +// fMenuDock = new TGDockableFrame(this); +// AddFrame(fMenuDock, new TGLayoutHints(kLHintsExpandX, 0, 0, 1, 0)); +// fMenuDock->SetWindowName("GuiTest Menu"); + + fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX); + fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); + fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight); + + fMenuFile = new TGPopupMenu(gClient->GetRoot()); + int im=0; + + fMenuFile->AddEntry("Open Alias", im++); + fMenuFile->AddEntry("Save Alias", im++); + fMenuFile->AddSeparator(); + fMenuFile->AddEntry("Open Parameters", im++); + fMenuFile->AddEntry("Save Parameters", im++); + fMenuFile->AddSeparator(); + fMenuFile->AddEntry("Open Configuration", im++); + fMenuFile->AddEntry("Save Configuration", im++); + fMenuFile->AddSeparator(); + fMenuFile->AddEntry("Open Pattern", im++); + fMenuFile->AddEntry("Save Pattern", im++); + fMenuFile->AddSeparator(); + fMenuFile->AddEntry("Exit", im++); + + fMenuFile->Connect("Activated(Int_t)", "ctbMain", this, + "HandleMenu(Int_t)"); + + + i_dacs=-1; + i_pwrs=-1; + i_senses=-1; + i_sig=-1; + i_adcs=-1; + i_pat=-1; + i_acq=-1; + + int i_page=0; + + + + + + + + + + + + + + + + + + TGVerticalFrame *vframe=new TGVerticalFrame(this, 800,1200); //main frame + + + + fMenuBar = new TGMenuBar(vframe, 1, 1, kHorizontalFrame); + fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout); +// fMenuBar->AddPopup("&Test", fMenuTest, fMenuBarItemLayout); +// fMenuBar->AddPopup("&View", fMenuView, fMenuBarItemLayout); +// fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout); + + vframe->AddFrame(fMenuBar, fMenuBarLayout); + + TGHorizontalFrame* hpage=new TGHorizontalFrame(vframe, 800,1200); //horizontal frame. Inside there should be the tab and the canvas + mtab=new TGTab(hpage, 1500, 1200); //tab! + // page=new TGVerticalFrame(mtab, 1500,1200); + + cout << "DACS" << endl; + + TGCompositeFrame *tf = mtab->AddTab("DACs"); + TGVerticalFrame *page=new TGVerticalFrame(tf, 1500,1200); + tf->AddFrame(page, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + dacs=new ctbDacs(page, myDet); + i_dacs=i_page++; + + + cout << "power " << endl; + tf = mtab->AddTab("Power Supplies"); + page=new TGVerticalFrame(tf, 1500,1200); + tf->AddFrame(page, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + pwrs=new ctbPowers(page, myDet); + + i_pwrs=i_page++; + + cout << "sense " << endl; + tf = mtab->AddTab("Sense"); + page=new TGVerticalFrame(tf, 1500,1200); + tf->AddFrame(page, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + senses=new ctbSlowAdcs(page, myDet); + + i_senses=i_page++; + + + + cout << "signals " << endl; + tf = mtab->AddTab("Signals"); + page=new TGVerticalFrame(tf, 1500,1200); + tf->AddFrame(page, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + sig=new ctbSignals(page, myDet); + sig->Connect("ToggledSignalPlot(Int_t)","ctbMain",this,"setSignalPlot(Int_t)"); + + i_sig=i_page++; + + cout << "adcs " << endl; + tf = mtab->AddTab("ADCs"); + page=new TGVerticalFrame(tf, 1500,1200); + tf->AddFrame(page, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + adcs=new ctbAdcs(page, myDet); + adcs->Connect("ToggledAdcPlot(Int_t)","ctbMain",this,"setADCPlot(Int_t)"); + adcs->Connect("AdcEnable(Int_t)","ctbMain",this,"setADCEnable(Int_t)"); + i_adcs=i_page++; + + + cout << "pattern" << endl; + + tf = mtab->AddTab("Pattern"); + page=new TGVerticalFrame(tf, 1500,1200); + tf->AddFrame(page, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + pat=new ctbPattern(page, myDet); + pat->Connect("patternFileChanged(const char*)","ctbMain",this,"setPatternFile(const char*)"); + pat->Connect("patternCompilerChanged(const char*)","ctbMain",this,"setPatternCompiler(const char*)"); + pat->Connect("analogSamplesChanged(const int)","ctbMain",this,"setAnalogSamples(int)"); + pat->Connect("digitalSamplesChanged(const int)","ctbMain",this,"setDigitalSamples(int)"); + pat->Connect("readoutModeChanged(int)","ctbMain",this,"setReadoutMode(int)"); + + i_pat=i_page++; + + cout << "acquisition" << endl; + + tf = mtab->AddTab("Acquisition"); + page=new TGVerticalFrame(tf, 1500,1200); + tf->AddFrame(page, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + acq=new ctbAcquisition(page, myDet); + + + i_acq=i_page++; + + + // cout << "actions" << endl; + // tf = mtab->AddTab("Actions"); + // page=new TGVerticalFrame(tf, 1500,1200); + // tf->AddFrame(page, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + // actions=new ctbActions(page, myDet); + + + // i_actions=i_page++; + + + + cout << "tabs finished" << endl; + + hpage->AddFrame(mtab,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + + vframe->AddFrame(hpage,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + + AddFrame(vframe,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); + vframe->MapWindow(); + hpage->MapWindow(); + mtab->MapWindow(); + page->MapWindow(); + + // Sets window name and shows the main frame + cout << "dockabel" << endl; + TGDockableFrame *fdock=new TGDockableFrame(hpage); + hpage->AddFrame(fdock, new TGLayoutHints(kLHintsBottom | kLHintsCenterX | kLHintsExpandX | kLHintsExpandY, 10,10,10,10)); + fdock->MapWindow(); + + cout << "canvas" << endl; +// // Creates widgets of the example + + + fEcanvas = new TRootEmbeddedCanvas ("Ecanvas",fdock,800,800);//hpage,800,800); + //fEcanvas = new TRootEmbeddedCanvas ("Ecanvas",this,800,800);//hpage,800,800); + // fEcanvas->Resize(); + // fEcanvas->GetCanvas()->Update(); + //AddFrame(fEcanvas, new TGLayoutHints(kLHintsBottom | kLHintsCenterX | kLHintsExpandX | kLHintsExpandY, 10,10,10,10)); + + // // hpage-> + fdock->AddFrame(fEcanvas, new TGLayoutHints(kLHintsBottom | kLHintsCenterX | kLHintsExpandX | kLHintsExpandY, 10,10,10,10)); + + + fEcanvas->MapWindow(); + + acq->setCanvas(getCanvas()); + + + + hpage->MapSubwindows(); + mtab->Connect("Selected(Int_t)","ctbMain",this,"tabSelected(Int_t)"); + + + + cout << "connect mtab" << endl; + + + setReadoutMode(pat->getReadoutMode()); + setADCEnable(adcs->setEnable()); + setAnalogSamples(pat->getAnalogSamples()); + setDigitalSamples(pat->getDigitalSamples()); + + tabSelected(0); + + SetWindowName("CTB Gui"); + MapSubwindows(); + Resize(1500,1200); + + MapWindow(); +} + +void ctbMain::CloseWindow() { + gApplication->Terminate(); +} + +TCanvas* ctbMain::getCanvas() { + return fEcanvas->GetCanvas(); +} + + + +void ctbMain::HandleMenu(Int_t id) +{ + // Handle menu items. + + + + + switch (id) { + + case 0: // fMenuFile->AddEntry("Open Alias", im++); + cout << "Open Alias" << endl; + { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename); + // dir = fi.fIniDir; + if (fi.fFilename) + loadAlias(fi.fFilename); + } + break; + + case 1: // fMenuFile->AddEntry("Save Alias", im++); + cout << "Save Alias" << endl; + { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDSave, &fi); + printf("Save file: %s (dir: %s)\n", fi.fFilename); + // dir = fi.fIniDir; + if (fi.fFilename) + saveAlias(fi.fFilename); + } + break; + + case 2: //fMenuFile->AddEntry("Open Parameters", im++); + cout << "Open Parameters" << endl; + { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + // dir = fi.fIniDir; + if (fi.fFilename) + loadParameters(fi.fFilename); + } + break; + + case 3: //fMenuFile->AddEntry("Save Parameters", im++); + cout << "Save Parameters" << endl; + { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDSave, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + // dir = fi.fIniDir; + if (fi.fFilename) + saveParameters(fi.fFilename); + } + break; + + case 4: // fMenuFile->AddEntry("Open Configuration", im++); + cout << "Open configuration" << endl; + { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + // dir = fi.fIniDir; + if (fi.fFilename) + loadConfiguration(fi.fFilename); + } + break; + + case 5: // fMenuFile->AddEntry("Save Configuration", im++); + cout << "Save configuration" << endl; + { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDSave, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + // dir = fi.fIniDir; + if (fi.fFilename) + saveConfiguration(fi.fFilename); + } + break; + + case 6: //fMenuFile->AddEntry("Open Pattern", im++); + cout << "Open pattern" << endl; + { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + // dir = fi.fIniDir; + if (fi.fFilename) + loadParameters(fi.fFilename); + } + break; + + case 7: //fMenuFile->AddEntry("Save Pattern", im++); + cout << "Save pattern" << endl; + { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDSave, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + // dir = fi.fIniDir; + if (fi.fFilename) + saveParameters(fi.fFilename); + } + break; + + case 8: // fMenuFile->AddEntry("Exit", im++); + CloseWindow(); + + default: + printf("Menu item %d selected\n", id); + break; + } +} + + + +int ctbMain::setADCPlot(Int_t i) { + + // cout << "ADC " << i << " plot or color toggled" << endl; + // acq->setGraph(i,adcs->getGraph(i)); + acq->setGraph(i,adcs->getEnabled(i),adcs->getColor(i)); + +} + + +int ctbMain::setSignalPlot(Int_t i) { + + // cout << "ADC " << i << " plot or color toggled" << endl; + // acq->setGraph(i,adcs->getGraph(i)); + acq->setBitGraph(i,sig->getPlot(i),sig->getColor(i)); + +} + + + +int ctbMain::loadConfiguration(string fname) { + + myDet->readConfigurationFile(fname); + +// string line; +// int i; +// ifstream myfile (fname.c_str()); +// if (myfile.is_open()) +// { +// while ( getline (myfile,line) ) +// { + + + +// } +// myfile.close(); +// } + +// else cout << "Unable to open file"; + + return 0; + +} + + + + + +int ctbMain::saveConfiguration(string fname) { + + + myDet->writeConfigurationFile(fname); + // string line; +// int i; +// ofstream myfile (fname.c_str()); +// if (myfile.is_open()) +// { + + +// myfile.close(); +// } + +// else cout << "Unable to open file"; + + return 0; + +} + + + + + + + +int ctbMain::loadParameters(string fname) { + + myDet->retrieveDetectorSetup(fname); + +// string line; +// int i; +// ifstream myfile (fname.c_str()); +// if (myfile.is_open()) +// { +// while ( getline (myfile,line) ) +// { + + + +// } +// myfile.close(); +// } + +// else cout << "Unable to open file"; + + return 0; + +} + + + + + +int ctbMain::saveParameters(string fname) { + + + string line; + int i; + myDet->dumpDetectorSetup(fname); +// ofstream myfile (fname.c_str()); +// if (myfile.is_open()) +// { + +// myfile << dacs->getDacParameters(); +// myfile << sig->getSignalParameters(); +// myfile << adcs->getAdcParameters(); + +// myfile.close(); +// } + +// else cout << "Unable to open file"; + + return 0; + +} + + + + + +int ctbMain::loadAlias(string fname) { + + + string line; + char aaaa[1000]; + int i; + ifstream myfile (fname.c_str()); + if (myfile.is_open()) + { + while ( getline (myfile,line) ) + { + // cout << line ; + if (sscanf(line.c_str(),"BIT%d",&i)>0) { + //cout << "*******" << line<< endl; + sig->setSignalAlias(line); + // cout << line ; + } else if (sscanf(line.c_str(),"DAC%d",&i)>0) { + dacs->setDacAlias(line); + // cout << "+++++++++" << line<< endl; + } else if (sscanf(line.c_str(),"ADC%d",&i)>0) { + adcs->setAdcAlias(line); + // cout << "---------" << line<< endl; + } // else + // cout << "<<<<<<<" << line << endl; + else if (sscanf(line.c_str(),"PAT%s",aaaa)>0) { + pat->setPatternAlias(line); + // cout << "---------" << line<< endl; + } else if (sscanf(line.c_str(),"V%s",&i)>0) { + if (pwrs) pwrs->setPwrAlias(line); + // cout << "+++++++++" << line<< endl; + } else if (sscanf(line.c_str(),"SENSE%d",&i)>0) { + if (senses) senses->setSlowAdcAlias(line); + // cout << "+++++++++" << line<< endl; + } + + } + myfile.close(); + } + + else cout << "Unable to open file"; + + return 0; + +} + + + + + +int ctbMain::saveAlias(string fname) { + + + string line; + int i; + ofstream myfile (fname.c_str()); + if (myfile.is_open()) + { + //while ( getline (myfile,line) ) + // { + // cout << line ; + //if (sscanf(line.c_str(),"BIT%d",&i)>0) { + //cout << "*******" << line<< endl; + myfile << sig->getSignalAlias(); + // cout << line ; + // } else if (sscanf(line.c_str(),"DAC%d",&i)>0) { + myfile << dacs->getDacAlias(); + if (pwrs) myfile << pwrs->getPwrAlias(); + if (senses) myfile << senses->getSlowAdcAlias(); + // cout << "+++++++++" << line<< endl; + // } else if (sscanf(line.c_str(),"ADC%d",&i)>0) { + myfile << adcs->getAdcAlias(); + // cout << "---------" << line<< endl; + // } // else + // cout << "<<<<<<<" << line << endl; + myfile << pat->getPatternAlias(); + + //} + myfile.close(); + } + + else cout << "Unable to open file"; + + return 0; + +} + + + + + + + + + + + +void ctbMain::tabSelected(Int_t i) { + + // cout << "Selected tab " << i << endl; + // cout << "Current tab is " << mtab->GetCurrent() << endl; + + if (i==i_dacs) dacs->update(); + else if (i==i_pwrs) pwrs->update(); + else if (i==i_senses) ;//senses->update(); + else if (i==i_sig) sig->update(); + else if (i==i_adcs) adcs->update(); + else if (i==i_pat) pat->update(); + else if (i==i_acq) acq->update(); + else if (i==i_acq) acq->update(); + // else if (i==i_actions) actions->update(); + else cout << "Unknown tab " << i << endl; + + +} + +void ctbMain::setPatternFile(const char* t) { + acq->setPatternFile(t); + +} + +void ctbMain::setPatternCompiler(const char* t) { + acq->setPatternCompiler(t); + + +} + +void ctbMain::setAnalogSamples(const int n) { + acq->setAnalogSamples(n); + + +} + +void ctbMain::setDigitalSamples(const int n) { + acq->setDigitalSamples(n); + + +} + +void ctbMain::setReadoutMode(int flags) { + acq->setReadoutMode(flags); +} + +void ctbMain::setADCEnable(Int_t reg){ + acq->setADCEnable(reg); +} diff --git a/ctbGui/ctbMain.h b/ctbGui/ctbMain.h new file mode 100755 index 000000000..f3fb51574 --- /dev/null +++ b/ctbGui/ctbMain.h @@ -0,0 +1,126 @@ +#ifndef CTBMAIN_H +#define CTBMAIN_H +#include + + +class TRootEmbeddedCanvas; +class TGButtonGroup; +class TGVerticalFrame; +class TGHorizontalFrame; +class TGTextEntry; +class TGLabel; +class TGNumberEntry; +class TH2F; +class TGComboBox; +class TGCheckButton; + +class THStack; +class TGraphErrors; +class TGTextButton; +class TGTab; + +class TGMenuBar; +class TGPopupMenu; +class TGDockableFrame; +class TGLayoutHints; +class TGCanvas; +class TCanvas; + +class ctbDacs; +class ctbSlowAdcs; +class ctbPowers; + + +class ctbSignals; + +class multiSlsDetector; + +class ctbPattern; +class ctbAdcs; +class ctbAcquisition; +//class ctbActions; + +#include +using namespace std; + +class ctbMain : public TGMainFrame { +private: + + + multiSlsDetector *myDet; + + + + TRootEmbeddedCanvas *fEcanvas; + TRootEmbeddedCanvas *fModulecanvas; + TGButtonGroup *br; + + TGTab *mtab; + + + ctbDacs *dacs; + int i_dacs; + + ctbPowers *pwrs; + int i_pwrs; + + ctbSlowAdcs *senses; + int i_senses; + + + ctbSignals *sig; + int i_sig; + + + ctbAdcs *adcs; + int i_adcs; + + + ctbPattern *pat; + int i_pat; + + ctbAcquisition *acq; + int i_acq; + + // ctbActions *actions; + int i_actions; + + TGDockableFrame *fMenuDock; + + TGMenuBar *fMenuBar; + TGPopupMenu *fMenuFile, *fMenuTest, *fMenuView, *fMenuHelp; + TGPopupMenu *fCascadeMenu, *fCascade1Menu, *fCascade2Menu; + TGPopupMenu *fMenuNew1, *fMenuNew2; + TGLayoutHints *fMenuBarLayout, *fMenuBarItemLayout, *fMenuBarHelpLayout; + TGCanvas *myCanvas; + + +public: + ctbMain(const TGWindow *p, multiSlsDetector *det); + + + int loadAlias(string fname); + int saveAlias(string fname); + int loadParameters(string fname); + int saveParameters(string fname); + int loadConfiguration(string fname); + int saveConfiguration(string fname); + void tabSelected(Int_t); + int setADCPlot(Int_t); + int setSignalPlot(Int_t); + void CloseWindow(); + + void setPatternFile(const char* t); + + void setPatternCompiler(const char* t); + void setAnalogSamples(const int); + void setDigitalSamples(const int); + void setReadoutMode(int); + void setADCEnable(Int_t); + + void HandleMenu(Int_t); + TCanvas* getCanvas(); + ClassDef(ctbMain,0) +}; + +#endif diff --git a/ctbGui/ctbPattern.cpp b/ctbGui/ctbPattern.cpp new file mode 100755 index 000000000..4823f8570 --- /dev/null +++ b/ctbGui/ctbPattern.cpp @@ -0,0 +1,1263 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "ctbPattern.h" +#include "multiSlsDetector.h" + +using namespace std; + + + + + +ctbLoop::ctbLoop(TGGroupFrame *page, int i, multiSlsDetector *det) : TGHorizontalFrame(page, 800,800), id(i), myDet(det) { + + TGHorizontalFrame *hframe=this; + + char tit[100]; + + page->AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + MapWindow(); + + + + + + sprintf(tit, "Loop %d Repetitions: ", id); + + TGLabel *label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eLoopNumber = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + hframe->AddFrame( eLoopNumber,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eLoopNumber->MapWindow(); + eLoopNumber->Resize(150,30); + TGTextEntry *e= eLoopNumber->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbLoop",this,"setNLoops()"); + + + + + sprintf(tit, "Start Address: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eLoopStartAddr = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESHex, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 1024); + hframe->AddFrame( eLoopStartAddr,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eLoopStartAddr->MapWindow(); + eLoopStartAddr->Resize(150,30); + + // eLoopStartAddr->SetState(kFALSE); + + label= new TGLabel(hframe, "Stop Address: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + + eLoopStopAddr = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESHex, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 1024); + hframe->AddFrame( eLoopStopAddr,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eLoopStopAddr->MapWindow(); + eLoopStopAddr->Resize(150,30); + + + + // eLoopStopAddr->SetState(kFALSE); + + + + + + +} + +void ctbLoop::setNLoops() { + + int start, stop, n; + + + start=-1; + stop=-1; + n=eLoopNumber->GetNumber(); + try{ + myDet->setPatternLoops(id,start, stop,n); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + +} + + + +void ctbLoop::update() { + + int start, stop, n; + + std::array loop; + + try { + loop=myDet->getPatternLoops(id); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + + eLoopStartAddr->SetHexNumber(loop[0]); + eLoopStopAddr->SetHexNumber(loop[1]); + eLoopNumber->SetNumber(loop[2]); +} + + + +ctbWait::ctbWait(TGGroupFrame *page, int i, multiSlsDetector *det) : TGHorizontalFrame(page, 800,800), id(i), myDet(det) { + + char tit[100]; + TGHorizontalFrame *hframe=this; + page->AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + MapWindow(); + + + + sprintf(tit, "Wait %d (run clk): ", id); + + TGLabel *label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eWaitTime = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + hframe->AddFrame( eWaitTime,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eWaitTime->MapWindow(); + eWaitTime->Resize(150,30); + TGTextEntry *e= eWaitTime->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbWait",this,"setWaitTime()"); + + + + sprintf(tit, "Wait Address: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eWaitAddr = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESHex, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 1024); + hframe->AddFrame( eWaitAddr,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eWaitAddr->MapWindow(); + eWaitAddr->Resize(150,30); + + // eWaitAddr->SetState(kFALSE); + +} + + + +void ctbWait::setWaitTime() { + + + Long64_t t=eWaitTime->GetNumber(); + try{ + t=myDet->setPatternWaitTime(id,t); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } +} + + + +void ctbWait::update() { + + int start, stop, n, addr; + + Long64_t t=-1; + try{ + + t=myDet->setPatternWaitTime(id,t); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + try{ + addr=myDet->setPatternWaitAddr(id,-1); + + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + eWaitAddr->SetHexNumber(addr); + eWaitTime->SetNumber(t); + +} + + + + + + + + + +ctbPattern::ctbPattern(TGVerticalFrame *page, multiSlsDetector *det) + : TGGroupFrame(page,"Pattern",kVerticalFrame), myDet(det) { + + + SetTitlePos(TGGroupFrame::kLeft); + page->AddFrame(this,new TGLayoutHints( kLHintsTop | kLHintsExpandX , 10,10,10,10)); + MapWindow(); + + + char tit[100]; + + + TGHorizontalFrame* hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + sprintf(tit, "Run Clock Frequency (MHz): "); + + TGLabel *label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eRunClkFreq = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 400); + hframe->AddFrame( eRunClkFreq,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eRunClkFreq->MapWindow(); + eRunClkFreq->Resize(150,30); + TGTextEntry *e= eRunClkFreq->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setRunFreq()"); + + + + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + + + sprintf(tit, "ADC Clock Frequency (MHz): "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eAdcClkFreq = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 40); + hframe->AddFrame( eAdcClkFreq,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eAdcClkFreq->MapWindow(); + eAdcClkFreq->Resize(150,30); + e= eAdcClkFreq->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setAdcFreq()"); + + + + + sprintf(tit, "DBIT Clock Frequency (MHz): "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eDBitClkFreq = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 400); + hframe->AddFrame( eDBitClkFreq,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eDBitClkFreq->MapWindow(); + eDBitClkFreq->Resize(150,30); + e= eDBitClkFreq->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setDBitFreq()"); + + + + + + + + + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + + + label= new TGLabel(hframe, "ADC Clock Phase (a.u.): "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + + eAdcClkPhase = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEAAnyNumber, + TGNumberFormat::kNELLimitMinMax, + -255, 255); + hframe->AddFrame( eAdcClkPhase,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eAdcClkPhase->MapWindow(); + eAdcClkPhase->Resize(150,30); + e= eAdcClkPhase->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setAdcPhase()"); + + + + + label= new TGLabel(hframe, "DBit Clock Phase (a.u.): "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + + eDBitClkPhase = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEAAnyNumber, + TGNumberFormat::kNELLimitMinMax, + -255, 255); + hframe->AddFrame( eDBitClkPhase,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eDBitClkPhase->MapWindow(); + eDBitClkPhase->Resize(150,30); + e= eDBitClkPhase->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setDBitPhase()"); + + +// label= new TGLabel(hframe, " Phase (0.15ns step): "); +// hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); +// label->MapWindow(); +// label->SetTextJustify(kTextLeft); + + + + + +// eRunClkPhase = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, +// TGNumberFormat::kNEANonNegative, +// TGNumberFormat::kNELLimitMinMax, +// 0, 200); +// hframe->AddFrame( eRunClkPhase,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); +// eRunClkPhase->MapWindow(); +// eRunClkPhase->Resize(150,30); +// e= eRunClkPhase->TGNumberEntry::GetNumberEntry(); +// e->Connect("ReturnPressed()","ctbPattern",this,"setRunPhase()"); + + + + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + + + label= new TGLabel(hframe, "Adc pipeline: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + + eAdcPipeline = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 64); + hframe->AddFrame( eAdcPipeline,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eAdcPipeline->MapWindow(); + eAdcPipeline->Resize(150,30); + e= eAdcPipeline->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setAdcPipeline()"); + + + + + + + label= new TGLabel(hframe, "DBIT pipeline: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + + eDBitPipeline = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 64); + hframe->AddFrame( eDBitPipeline,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eDBitPipeline->MapWindow(); + eDBitPipeline->Resize(150,30); + e= eDBitPipeline->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setDBitPipeline()"); + + + + + + + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + sprintf(tit, "Number of cycles: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eCycles = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + hframe->AddFrame( eCycles,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eCycles->MapWindow(); + eCycles->Resize(150,30); + e= eCycles->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setCycles()"); + + + sprintf(tit, "Number of measurements: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eMeasurements = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + hframe->AddFrame( eMeasurements,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eMeasurements->MapWindow(); + eMeasurements->Resize(150,30); + e= eMeasurements->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setMeasurements()"); + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + sprintf(tit, "Number of frames: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eFrames = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + hframe->AddFrame( eFrames,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eFrames->MapWindow(); + eFrames->Resize(150,30); + e= eFrames->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setFrames()"); + + + label= new TGLabel(hframe, " Period (s): "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + + ePeriod = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESReal, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + hframe->AddFrame( ePeriod,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + ePeriod->MapWindow(); + ePeriod->Resize(150,30); + e= ePeriod->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setPeriod()"); + + + + + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + sprintf(tit, "Start Address: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + eStartAddr = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESHex, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 1024); + hframe->AddFrame( eStartAddr,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eStartAddr->MapWindow(); + eStartAddr->Resize(150,30); + + eStartAddr->SetState(kFALSE); + + label= new TGLabel(hframe, "Stop Address: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + + eStopAddr = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESHex, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 0, 1024); + hframe->AddFrame( eStopAddr,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eStopAddr->MapWindow(); + eStopAddr->Resize(150,30); + + + + + eStopAddr->SetState(kFALSE); + + + + + + + int idac=0; + for (idac=0; idacMapWindow(); + + + + label= new TGLabel(hframe, "Compiler: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + + patternCompiler=new TGTextEntry(hframe,"generate.sh"); + hframe->AddFrame(patternCompiler,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + patternCompiler->MapWindow(); + // patternCompiler->SetTextJustify(kTextLeft); + patternCompiler->Connect("ReturnPressed()","ctbPattern",this,"setCompiler()"); + + + browseCompiler=new TGTextButton(hframe,"Browse"); + hframe->AddFrame(browseCompiler,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + browseCompiler->MapWindow(); + // patternCompiler->SetTextJustify(kTextLeft); + browseCompiler->Connect("Clicked()","ctbPattern",this,"chooseCompiler()"); + + + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + label= new TGLabel(hframe, "Pattern: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + patternFile=new TGTextEntry(hframe,"file.p"); + hframe->AddFrame(patternFile,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + patternFile->MapWindow(); + patternFile->Connect("ReturnPressed()","ctbPattern",this,"setFile()"); + // patternFile->SetTextJustify(kTextLeft); + + + + browseFile=new TGTextButton(hframe,"Browse"); + hframe->AddFrame(browseFile,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + browseFile->MapWindow(); + // patternCompiler->SetTextJustify(kTextLeft); + browseFile->Connect("Clicked()","ctbPattern",this,"choosePattern()"); + + + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + sprintf(tit, "Samples per frame - "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + sprintf(tit, "Analog: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + eAnalogSamples = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 1, 8192); + hframe->AddFrame( eAnalogSamples,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eAnalogSamples->MapWindow(); + eAnalogSamples->Resize(150,30); + e= eAnalogSamples->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setAnalogSamples()"); + + sprintf(tit, "Digital: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + + eDigitalSamples = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, + 1, 8192); + hframe->AddFrame( eDigitalSamples,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eDigitalSamples->MapWindow(); + eDigitalSamples->Resize(150,30); + e= eDigitalSamples->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbPattern",this,"setDigitalSamples()"); + + + hframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + sprintf(tit, "Read Out Mode: "); + + label= new TGLabel(hframe, tit); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + cbAnalog= new TGCheckButton(hframe, "Analog"); + hframe->AddFrame(cbAnalog,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); + cbAnalog->MapWindow(); + cbAnalog->SetTextJustify(kTextRight); + cbAnalog->Connect("Toggled(Bool_t)","ctbPattern",this,"setReadoutMode(Bool_t)"); + + cbDigital= new TGCheckButton(hframe, "Digital"); + hframe->AddFrame(cbDigital,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); + cbDigital->MapWindow(); + cbDigital->SetTextJustify(kTextRight); + cbDigital->Connect("Toggled(Bool_t)","ctbPattern",this,"setReadoutMode(Bool_t)"); + + + + +} + +void ctbPattern::update() { + + int start, stop, n, addr; + + Long_t t; + + + try { + n=myDet->setSpeed(slsDetectorDefs::CLOCK_DIVIDER,-1,0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eRunClkFreq->SetNumber(n); + + try { + n=myDet->setSpeed(slsDetectorDefs::ADC_CLOCK,-1,0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eAdcClkFreq->SetNumber(n); + + try { + n=myDet->setSpeed(slsDetectorDefs::ADC_PHASE,-1,0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eAdcClkPhase->SetNumber(n); + + try { + n=myDet->setSpeed(slsDetectorDefs::ADC_PIPELINE,-1,0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + + eAdcPipeline->SetNumber(n); + + try { + n=myDet->setSpeed(slsDetectorDefs::DBIT_CLOCK,-1,0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + + eDBitClkFreq->SetNumber(n); + + try { + n=myDet->setSpeed(slsDetectorDefs::DBIT_PHASE,-1,0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + + eDBitClkPhase->SetNumber(n); +try { + myDet->setSpeed(slsDetectorDefs::DBIT_PIPELINE,0,-1); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + eDBitPipeline->SetNumber(n); + +try { + n=myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,-1); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eFrames->SetNumber(n); + + +try { + n=myDet->setTimer(slsDetectorDefs::FRAME_PERIOD,-1); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + + + ePeriod->SetNumber(((Double_t)n)*1E-9); + + try { + n=myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER,-1); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eCycles->SetNumber(n); + + + try { + myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eMeasurements->SetNumber(n); + + start=-1; + stop=-1; + n=-1; + std::array loop; + + try { + loop=myDet->getPatternLoops(-1); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eStartAddr->SetHexNumber(loop[0]); + eStopAddr->SetHexNumber(loop[1]); + + for (int iloop=0; iloopupdate(); + + } + + for (int iwait=0; iwaitupdate(); + } + + getAnalogSamples(); + getDigitalSamples(); + getReadoutMode(); + +} +void ctbPattern::setFile() { + patternFileChanged(patternFile->GetText()); + +} + + +void ctbPattern::setCompiler() { + patternCompilerChanged(patternCompiler->GetText()); +} + + +void ctbPattern::patternFileChanged(const char* t){ + Emit("patternFileChanged(const char*)", t); +} + + +void ctbPattern::patternCompilerChanged(const char* t){ + Emit("patternCompilerChanged(const char*)", t); + +} + + +void ctbPattern::setPatternAlias(string line){ + char fname[10000]; + if (sscanf(line.c_str(),"PATCOMPILER %s",fname)) { + patternCompiler->SetText(fname); + patternCompilerChanged(patternCompiler->GetText()); + } else if (sscanf(line.c_str(),"PATFILE %s",fname)) { + patternFile->SetText(fname); + patternFileChanged(patternFile->GetText()); + } +} + + +string ctbPattern::getPatternAlias() { + char line[100000]; + sprintf("PATCOMPILER %s\nPATFILE %s\n",patternCompiler->GetText(),patternFile->GetText()); +} + + +void ctbPattern::chooseCompiler() { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + // dir = fi.fIniDir; + if (fi.fFilename) { + patternCompiler->SetText(fi.fFilename); + patternCompilerChanged(patternCompiler->GetText()); + } +} + + +void ctbPattern::choosePattern() { + static TString dir("."); + TGFileInfo fi; + //fi.fFileTypes = filetypes; + fi.fIniDir = StrDup(dir); + printf("fIniDir = %s\n", fi.fIniDir); + new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi); + printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); + // dir = fi.fIniDir; + if (fi.fFilename) { + patternFile->SetText(fi.fFilename); + patternFileChanged(patternFile->GetText()); + } + +} + + +string ctbPattern::getCompiler() { + return string(patternCompiler->GetText()); + +} + +string ctbPattern::getPatternFile() { + return string(patternFile->GetText()); + +} + +void ctbPattern::setFrames() { + try { + myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,eFrames->GetNumber()); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } +} + +void ctbPattern::setCycles() { + try { + myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER,eFrames->GetNumber()); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } +} + +void ctbPattern::setMeasurements() { + try { + myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,eFrames->GetNumber()); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } +} + + + + +void ctbPattern::setPeriod() { + try { + myDet->setTimer(slsDetectorDefs::FRAME_PERIOD,ePeriod->GetNumber()*1E9); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } +} + + + + +void ctbPattern::setAdcFreq() { + try { + myDet->setSpeed(slsDetectorDefs::ADC_CLOCK,eAdcClkFreq->GetNumber(),0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } +} +void ctbPattern::setRunFreq() { + try{ + myDet->setSpeed(slsDetectorDefs::CLOCK_DIVIDER,eRunClkFreq->GetNumber(),0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + +} +void ctbPattern::setDBitFreq() { + // cout <<"Not setting dbit frequency to " << eDBitClkFreq->GetNumber()<< endl; + try { + myDet->setSpeed(slsDetectorDefs::DBIT_CLOCK,eDBitClkFreq->GetNumber(),0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + +} +void ctbPattern::setAdcPhase() { + try { + myDet->setSpeed(slsDetectorDefs::ADC_PHASE,eAdcClkPhase->GetNumber(),0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + +} + +void ctbPattern::setDBitPhase() { + // cout <<"Not setting dbit phase to " << eDBitClkPhase->GetNumber()<< endl; + try { + myDet->setSpeed(slsDetectorDefs::DBIT_PHASE,eDBitClkPhase->GetNumber(),0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + +} + + +void ctbPattern::setAdcPipeline() { + try { + myDet->setSpeed(slsDetectorDefs::ADC_PIPELINE,eAdcPipeline->GetNumber(),0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } +} + + +void ctbPattern::setDBitPipeline() { + // cout <<"Not setting dbit pipeline to " << eDBitPipeline->GetNumber() << endl; + try { + myDet->setSpeed(slsDetectorDefs::DBIT_PIPELINE,eDBitPipeline->GetNumber(),0); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } +} + + +void ctbPattern::setAnalogSamples() { + try { + myDet->setTimer(slsDetectorDefs::ANALOG_SAMPLES,eAnalogSamples->GetNumber()); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + analogSamplesChanged(eAnalogSamples->GetNumber()); +} + +void ctbPattern::setDigitalSamples() { + try { + myDet->setTimer(slsDetectorDefs::DIGITAL_SAMPLES,eDigitalSamples->GetNumber()); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + digitalSamplesChanged(eDigitalSamples->GetNumber()); +} + +void ctbPattern::setReadoutMode(Bool_t) { + // cout << "Set readout mode to be implemented" << endl; + slsDetectorDefs::readOutFlags flags; + if (cbAnalog->IsOn() && cbDigital->IsOn()) flags=slsDetectorDefs::ANALOG_AND_DIGITAL; + else if (~cbAnalog->IsOn() && cbDigital->IsOn()) flags=slsDetectorDefs::DIGITAL_ONLY; + else if (cbAnalog->IsOn() && ~cbDigital->IsOn()) flags=slsDetectorDefs::NORMAL_READOUT; + else flags=slsDetectorDefs::GET_READOUT_FLAGS; + try { + myDet->setReadOutFlags(flags); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + cout << "Set readout flags " << hex << flags << dec << endl; + getReadoutMode(); + // myDet->setTimer(slsDetectorDefs::SAMPLES_CTB,eSamples->GetNumber()); + //samplesChanged(eSamples->GetNumber()); +} + +void ctbPattern::readoutModeChanged(int flags) { + Emit("readoutModeChanged(Int_t)",(int)flags); + +} + +int ctbPattern::getReadoutMode() { + // cout << "Get readout mode to be implemented" << endl; + slsDetectorDefs::readOutFlags flags; + try { + flags=(slsDetectorDefs::readOutFlags) myDet->setReadOutFlags(); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + cout << "++++++++++++++++++++"<< hex << flags << dec << endl; + if (flags&slsDetectorDefs::ANALOG_AND_DIGITAL) { + cout << "analog and digital" << hex << slsDetectorDefs::ANALOG_AND_DIGITAL << dec<< endl; + cbAnalog->SetOn(kTRUE); + cbDigital->SetOn(kTRUE); + } else if (flags&slsDetectorDefs::DIGITAL_ONLY) { + cout << "digital only" << hex << slsDetectorDefs::DIGITAL_ONLY << dec << endl; + cbAnalog->SetOn(kFALSE); + cbDigital->SetOn(kTRUE); + }// else if (flags==slsDetectorDefs::NORMAL_READOUT) { + // cbAnalog->SetOn(kTRUE); + // cbDigital->SetOn(kFALSE); + // } + else { + cout << "analog only" << endl; + flags=slsDetectorDefs::NORMAL_READOUT; + cbAnalog->SetOn(kTRUE); + cbDigital->SetOn(kFALSE); + } + + Emit("readoutModeChanged(int)",(int)flags); + return (int)flags; + + // myDet->setTimer(slsDetectorDefs::SAMPLES_CTB,eSamples->GetNumber()); + //samplesChanged(eSamples->GetNumber()); +} + +int ctbPattern::getAnalogSamples() { + int n; + try { + n=(myDet->setTimer(slsDetectorDefs::ANALOG_SAMPLES,-1)); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + eAnalogSamples->SetNumber((Double_t)n); + Emit("analogSamplesChanged(const int)", eAnalogSamples->GetNumber()); + return eAnalogSamples->GetNumber(); +} + +int ctbPattern::getDigitalSamples() { + int n; + try { + + n=(myDet->setTimer(slsDetectorDefs::DIGITAL_SAMPLES,-1)); + } catch (...) { + + cout << "Do nothing for this error" << endl; + } + + eDigitalSamples->SetNumber(((Double_t)n)); + Emit("digitalSamplesChanged(const int)", eDigitalSamples->GetNumber()); + return eDigitalSamples->GetNumber(); +} + + + +void ctbPattern::analogSamplesChanged(const int t){ + Emit("analogSamplesChanged(const int)", t); +} + +void ctbPattern::digitalSamplesChanged(const int t){ + Emit("digitalSamplesChanged(const int)", t); +} diff --git a/ctbGui/ctbPattern.h b/ctbGui/ctbPattern.h new file mode 100755 index 000000000..fdfc0412b --- /dev/null +++ b/ctbGui/ctbPattern.h @@ -0,0 +1,176 @@ +#ifndef CTBPATTERN_H +#define CTBPATTERN_H +#include + + +#define NLOOPS 3 +#define NWAITS 3 +#define NADCS 32 +#define PATLEN 1024 + +class TRootEmbeddedCanvas; +class TGButtonGroup; +class TGVerticalFrame; +class TGHorizontalFrame; +class TGTextEntry; +class TGLabel; +class TGNumberEntry; +class TH2F; +class TGComboBox; +class TGCheckButton; +class TGTextEntry; +class TGCheckButton; + +class THStack; +class TGraphErrors; +class energyCalibration; +class TGTextButton; +class TGTab; + +class multiSlsDetector; + + +#include +using namespace std; + + + +class ctbLoop : public TGHorizontalFrame { + + + private: + + TGNumberEntry *eLoopStartAddr; + TGNumberEntry *eLoopStopAddr; + TGNumberEntry *eLoopNumber; + + int id; + + multiSlsDetector *myDet; + + public: + ctbLoop(TGGroupFrame *page, int i,multiSlsDetector *det); + + void setNLoops(); + void update(); + + ClassDef(ctbLoop,0) + }; + +class ctbWait : public TGHorizontalFrame { + + + private: + + TGNumberEntry *eWaitAddr; + TGNumberEntry *eWaitTime; + + int id; + + multiSlsDetector *myDet; + + public: + ctbWait(TGGroupFrame *page, int i,multiSlsDetector *det); + + void setWaitTime(); + void update(); + + ClassDef(ctbWait,0) + }; + + + + + + + +class ctbPattern : public TGGroupFrame { +private: + + + TGNumberEntry *eAdcClkFreq; + TGNumberEntry *eRunClkFreq; + TGNumberEntry *eDBitClkFreq; + TGNumberEntry *eAdcClkPhase; + TGNumberEntry *eDBitClkPhase; + //TGNumberEntry *eRunClkPhase; + + TGNumberEntry *eStartAddr; + TGNumberEntry *eStopAddr; + TGNumberEntry *eFrames; + TGNumberEntry *ePeriod; + TGNumberEntry *eCycles; + TGNumberEntry *eMeasurements; + TGNumberEntry *eAdcPipeline; + TGNumberEntry *eDBitPipeline; + + ctbLoop *eLoop[NLOOPS]; + ctbWait *eWait[NWAITS]; + + TGTextEntry *patternCompiler; + TGTextEntry *patternFile; + + TGTextButton *browseCompiler; + TGTextButton *browseFile; + + + TGNumberEntry *eAnalogSamples; + TGNumberEntry *eDigitalSamples; + + TGCheckButton *cbAnalog; + TGCheckButton *cbDigital; + + char pat[PATLEN*8]; + + multiSlsDetector *myDet; + +public: + + ctbPattern(TGVerticalFrame *page, multiSlsDetector *det); + + void update(); + void setAdcFreq(); + void setRunFreq(); + void setDBitFreq(); + void setAdcPhase(); + void setDBitPhase(); + // void setRunPhase(); + void setAdcPipeline(); + void setDBitPipeline(); + void setFrames(); + void setCycles(); + void setMeasurements(); + void setPeriod(); + + + void chooseCompiler(); + void choosePattern(); + + string getCompiler(); + string getPatternFile(); + + void setPatternAlias(string); + string getPatternAlias(); + + + int getAnalogSamples(); + void setAnalogSamples(); + int getDigitalSamples(); + void setDigitalSamples(); + void setReadoutMode(Bool_t); + int getReadoutMode(); + + + void setFile(); + void setCompiler(); + void patternFileChanged(const char*); + void patternCompilerChanged(const char*); + void analogSamplesChanged(const int t); + void digitalSamplesChanged(const int t); + void readoutModeChanged(int); + + + ClassDef(ctbPattern,0) +}; + +#endif diff --git a/ctbGui/ctbPowers.cpp b/ctbGui/ctbPowers.cpp new file mode 100644 index 000000000..1e4f8d170 --- /dev/null +++ b/ctbGui/ctbPowers.cpp @@ -0,0 +1,243 @@ +#include + + +#include +#include +#include +#include + +#include +#include +#include + +#include "ctbDacs.h" +#include "ctbPowers.h" +#include "multiSlsDetector.h" +#include "sls_detector_defs.h" + +using namespace std; + + + +ctbPower::ctbPower(TGGroupFrame* f, int i, multiSlsDetector* d) + : ctbDac(f, i, d) +{ + cout << "****************************************************************power " << i << endl; + dacsUnit->SetOn(kTRUE); + dacsUnit->SetEnabled(kFALSE); + int ii=0; + + switch(i) { + case slsDetectorDefs::V_POWER_IO: + dacsLabel->SetText("VIO"); + ii=slsDetectorDefs::I_POWER_IO; + break; + case slsDetectorDefs::V_POWER_A: + dacsLabel->SetText("VA"); + ii=slsDetectorDefs::I_POWER_A; + break; + case slsDetectorDefs::V_POWER_B: + dacsLabel->SetText("VB"); + ii=slsDetectorDefs::I_POWER_B; + break; + case slsDetectorDefs::V_POWER_C: + dacsLabel->SetText("VC"); + ii=slsDetectorDefs::I_POWER_C; + break; + case slsDetectorDefs::V_POWER_D: + dacsLabel->SetText("VD"); + ii=slsDetectorDefs::I_POWER_D; + break; + case slsDetectorDefs::V_POWER_CHIP: + dacsLabel->SetText("VCHIP"); + dacsLabel->SetEnabled(kFALSE); + ii=-1; + break; + default: + dacsLabel->SetText("Bad index"); + ii=-1; + break; + }; + + // ctbSlowAdc *vm=new ctbSlowAdc(f,i,d); + // vm->setLabel("V: "); + // if (ii>=0) { + // ctbSlowAdc *im=new ctbSlowAdc(f,ii,d); + // im->setLabel("I: "); + // } + + TGTextEntry *e=dacsEntry->TGNumberEntry::GetNumberEntry(); + e->Disconnect ("ReturnPressed()"); + e->Disconnect ("ValueSet(Long_t)"); + + e->Connect("ReturnPressed()","ctbPower",this,"setValue()"); + dacsEntry->Connect("ValueSet(Long_t)","ctbPower",this,"setValue(Long_t)"); + }; + + +string ctbPower::getLabel() { + + ostringstream line; + switch (id) { + case slsDetectorDefs::V_POWER_IO: + line << "VIO"; + break; + case slsDetectorDefs::V_POWER_A: + line << "VA"; + break; + case slsDetectorDefs::V_POWER_B: + line << "VB"; + break; + case slsDetectorDefs::V_POWER_C: + line << "VC"; + break; + case slsDetectorDefs::V_POWER_D: + line << "VD"; + break; + case slsDetectorDefs::V_POWER_CHIP: + line << "VCHIP"; + break; + default: + line << "VBAD"; + break; + + } + line << " " << dacsLabel->GetText() << endl; + return line.str(); + +} + + +void ctbPower::setValue(Long_t a) {cout << "ssssssssss" << endl; ctbPower::setValue();} +void ctbPower::setValue() { + + + cout << "***************************Setting power " << dacsEntry->GetIntNumber() << " " << (slsDetectorDefs::dacIndex)id <<" " << 1 << endl; + myDet->setDAC(dacsEntry->GetIntNumber(), (slsDetectorDefs::dacIndex)id, 1); + + getValue(); + +} + + +int ctbPower::getValue() { + + int val=myDet->setDAC(-1, (slsDetectorDefs::dacIndex)id, 1); + char s[100]; + cout << "****************************Getting power " << val << " " << (slsDetectorDefs::dacIndex)id <<" " << 1 << endl; + sprintf(s,"%d",val); + dacsValue->SetText(s); + if (val>0) { + if (id!=slsDetectorDefs::V_POWER_CHIP) + dacsLabel->SetOn(kTRUE); + } else { + dacsLabel->SetOn(kFALSE); + } + + + return val; + +} + + + +ctbPowers::ctbPowers(TGVerticalFrame* page, multiSlsDetector* det) : TGGroupFrame(page,"Power Supplies",kVerticalFrame) , myDet(det){ + + + SetTitlePos(TGGroupFrame::kLeft); + page->AddFrame(this,new TGLayoutHints( kLHintsTop | kLHintsExpandX , 10,10,10,10)); + MapWindow(); + + // cout << "window mapped " << endl; + + for (int idac=0; idacsetLabel(tit,1); + is=0; + } + + if (sscanf(line.c_str(),"VB %s",tit)) { + dacs[1]->setLabel(tit,1); + is=1; + } + + if (sscanf(line.c_str(),"VC %s",tit)) { + dacs[2]->setLabel(tit,1); + is=2; + } + + if (sscanf(line.c_str(),"VD %s",tit)) { + dacs[3]->setLabel(tit,1); + is=3; + } + + if (sscanf(line.c_str(),"VIO %s",tit)) { + dacs[4]->setLabel(tit,1); + is=4; + } + + if (sscanf(line.c_str(),"VCHIP %s",tit)) { + dacs[5]->setLabel(tit,1); + is=5; + } + + return is; + +} + +string ctbPowers::getPwrAlias() { + + ostringstream line; + + for (int i=0; igetLabel() << endl; + return line.str(); + +} + + + + +string ctbPowers::getPwrParameters() { + + + ostringstream line; + line << "v_a" << " " << dacs[0]->getValue() << " mv" << endl; + line << "v_b" << " " << dacs[1]->getValue() << " mv" << endl; + line << "v_c" << " " << dacs[2]->getValue() << " mv" << endl; + line << "v_d" << " " << dacs[3]->getValue() << " mv" << endl; + line << "v_io" << " " << dacs[4]->getValue() << " mv" << endl; + line << "v_chip" << " " << dacs[5]->getValue() << " mv" << endl; + // for (int i=0; igetValue << endl; + // line << "dac:" << i << " " << dacs[i]->getValue() << endl; + // } + return line.str(); + + +} + + + +void ctbPowers::update() { + + for (int idac=0; idacgetValue(); + + } + + +} diff --git a/ctbGui/ctbPowers.h b/ctbGui/ctbPowers.h new file mode 100644 index 000000000..3cd84d2bb --- /dev/null +++ b/ctbGui/ctbPowers.h @@ -0,0 +1,72 @@ +#ifndef CTBPOWERS_H +#define CTBPOWERS_H + +#include + +#ifndef CTB +#define NPOWERS 0 +#else + +#define NPOWERS 6 +#endif + + + + + +class TGTextEntry; +class TGLabel; +class TGNumberEntry; +class TGCheckButton; + + + + +class multiSlsDetector; + + +#include +using namespace std; + + +class ctbPower : public ctbDac { + + + + + public: + + ctbPower(TGGroupFrame* f, int i, multiSlsDetector* d); + + string getLabel(); + + int getValue(); + void setValue(); + void setValue(Long_t); + + ClassDef(ctbPower,0) +}; + + +class ctbPowers : public TGGroupFrame +{ + private: + + ctbPower *dacs[NPOWERS]; + + multiSlsDetector* myDet; + +public: + //ctbPowers(); + ctbPowers(TGVerticalFrame*, multiSlsDetector*); + + int setPwrAlias(string); + string getPwrAlias(); + string getPwrParameters(); + + void update(); + + ClassDef(ctbPowers,0) +}; + +#endif diff --git a/ctbGui/ctbSignals.cpp b/ctbGui/ctbSignals.cpp new file mode 100755 index 000000000..46197b81a --- /dev/null +++ b/ctbGui/ctbSignals.cpp @@ -0,0 +1,548 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "ctbSignals.h" +#include "multiSlsDetector.h" + +using namespace std; + + + +//#define DEFAULTFN "run_0.encal" + + +ctbSignal::ctbSignal(TGFrame *page, int i, multiSlsDetector *det) + : TGHorizontalFrame(page, 800,50), myDet(det), id(i), hsig(NULL) { + + + TGHorizontalFrame *hframe=this; + char tit[100]; + + + + sprintf(tit, "BIT%d ",id); + + sLabel= new TGLabel(hframe, tit); + hframe->AddFrame( sLabel,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + sLabel->MapWindow(); + sLabel->SetTextJustify(kTextLeft); + + + + sOutput= new TGCheckButton(hframe, "Out"); + hframe->AddFrame( sOutput,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + sOutput->MapWindow(); + + + sOutput->Connect("Toggled(Bool_t)","ctbSignal",this,"ToggledOutput(Bool_t)"); + + sDbitList= new TGCheckButton(hframe, "DB List"); + hframe->AddFrame( sDbitList,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + sDbitList->MapWindow(); + + sDbitList->Connect("Toggled(Bool_t)","ctbSignal",this,"ToggledDbitList(Bool_t)"); + + + sPlot= new TGCheckButton(hframe, "Plot"); + hframe->AddFrame( sPlot,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + sPlot->MapWindow(); + + sPlot->Connect("Toggled(Bool_t)","ctbSignal",this,"ToggledPlot(Bool_t)"); + + fColorSel = new TGColorSelect(hframe, id+1, 0); + fColorSel->Connect("ColorSelected(Pixel_t)","ctbSignal",this,"ColorChanged(Pixel_t)"); + hframe->AddFrame(fColorSel, new TGLayoutHints(kLHintsTop | + kLHintsLeft, 2, 0, 2, 2)); + + + fColorSel->SetColor(TColor::Number2Pixel(id+1)); + + + ToggledOutput(kFALSE); + + + ToggledPlot(kFALSE); + + // if (id==63) { +// sOutput->SetOn(kTRUE); +// sOutput->SetEnabled(kFALSE); +// } +// #ifdef CTB +// if (id==62) { +// sOutput->SetOn(kTRUE); +// sOutput->SetEnabled(kFALSE); +// } + +// // if (id>=32 && id<48) +// // fixOutput(1); +// // else if (id>=48 && id<64) +// // fixOutput(0); + +// #endif +} +int ctbSignal::setSignalAlias(char *tit, int plot, int col) { + + if (tit) + sLabel->SetText(tit); + + if (plot>0) { + sPlot->SetOn(kTRUE,kTRUE); + } else if (plot==0) + sPlot->SetOn(kFALSE,kTRUE); + + if (col>=0) + fColorSel->SetColor(col);//TColor::Number2Pixel(col+1)); + + fColorSel->SetEnabled(sPlot->IsOn()); + return 0; + +} + +string ctbSignal::getSignalAlias() { + + + ostringstream oss; + oss << "BIT" << dec << id << " " << sLabel->GetText()->Data() << " " << sPlot->IsOn() << hex << " " << fColorSel->GetColor() << endl; + return oss.str(); + + + + +} +int ctbSignal::setOutput(Long64_t r) { + + + // cout << hex << r << dec <SetOn(kTRUE,kTRUE); + else + sOutput->SetOn(kFALSE,kTRUE); + + return sOutput->IsOn(); + +} + +int ctbSignal::fixOutput(int i) { + + if (i) { + sPlot->SetOn(kFALSE); + //sClock->SetOn(kFALSE,kTRUE); + sOutput->SetOn(kTRUE); + // sPlot->SetEnabled(kFALSE); + // sClock->SetEnabled(kTRUE); + } else { + sOutput->SetOn(kFALSE,kTRUE); + // sClock->SetOn(kFALSE); + // sClock->SetEnabled(kFALSE); + sPlot->SetEnabled(kTRUE); + } + sOutput->SetEnabled(kFALSE); + return 0; + +} + +int ctbSignal::setDbitList(Long64_t r) { + + Long64_t mask=((Long64_t)1<SetOn(kTRUE,kFALSE); + else + sDbitList->SetOn(kFALSE,kFALSE); + + return sDbitList->IsOn(); + +} + +int ctbSignal::isDbitList() { return sDbitList->IsOn();} +int ctbSignal::isOutput() { return sOutput->IsOn();} +int ctbSignal::isPlot() { return sPlot->IsOn();} +Pixel_t ctbSignal::getColor(){return fColorSel->GetColor();} + +void ctbSignal::ToggledOutput(Bool_t b) { + Long_t mask=b<SetEnabled(kTRUE); + sPlot->SetOn(kFALSE); + // sPlot->SetEnabled(kFALSE); + fColorSel->SetEnabled(kFALSE); + } else { + // sClock->SetEnabled(kFALSE); + // sClock->SetOn(kFALSE); + sPlot->SetEnabled(kTRUE); + if ( sPlot->IsOn()) + fColorSel->SetEnabled(kFALSE); + else + fColorSel->SetEnabled(kTRUE); + } + + +} + +void ctbSignal::ToggledDbitList(Bool_t b){ + Long_t mask=id; + ToggledSignalDbitList(mask); +} + + +void ctbSignal::ToggledPlot(Bool_t b){ + Long_t mask=b<SetEnabled(b); +} + +void ctbSignal::ColorChanged(Pixel_t p){ + ToggledSignalPlot(id); +} + + +void ctbSignal::ToggledSignalOutput(Int_t b) { + cout << "Toggle signal " << id << " " << b << " " << sOutput->IsOn() <AddFrame(this,new TGLayoutHints( kLHintsTop | kLHintsExpandX , 10,10,10,10)); + MapWindow(); + + + TGHorizontalFrame *hframe; + char tit[100]; + + TGHorizontalFrame* hhframe=new TGHorizontalFrame(this, 800,800); + AddFrame(hhframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hhframe->MapWindow(); + + TGVerticalFrame *vframe; + + + + + int idac=0; + for (idac=0; idacAddFrame(vframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + vframe->MapWindow(); + } + + + signals[idac]=new ctbSignal(vframe,idac,myDet); + signals[idac]->Connect("ToggledSignalOutput(Int_t)","ctbSignals",this,"ToggledOutReg(Int_t)"); + signals[idac]->Connect("ToggledSignalDbitList(Int_t)","ctbSignals",this,"ToggledDbitList(Int_t)"); + signals[idac]->Connect("ToggledSignalPlot(Int_t)","ctbSignals",this,"ToggledPlot(Int_t)"); + + vframe->AddFrame(signals[idac],new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + signals[idac]->MapWindow(); + + + } + +// #ifdef CTB +// idac=62; +// signals[idac]=new ctbSignal(vframe,idac,myDet); +// vframe->AddFrame(signals[idac],new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); +// signals[idac]->MapWindow(); +// sprintf(tit,"DBIT Latch"); + +// signals[idac]->setSignalAlias(tit,-1,-1); + +// signals[idac]->Connect("ToggledSignalOutput(Int_t)","ctbSignals",this,"ToggledOutReg(Int_t)"); +// signals[idac]->Connect("ToggledSignalDbitList(Int_t)","ctbSignals",this,"ToggledDbitList(Int_t)"); +// signals[idac]->Connect("ToggledSignalPlot(Int_t)","ctbSignals",this,"ToggledPlot(Int_t)"); + + +// #endif + + + // idac=63; + // signals[idac]=new ctbSignal(vframe,idac,myDet); + // vframe->AddFrame(signals[idac],new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + // signals[idac]->MapWindow(); + // sprintf(tit,"ADC Latch"); + + // signals[idac]->setSignalAlias(tit,-1,-1); + + // signals[idac]->Connect("ToggledSignalOutput(Int_t)","ctbSignals",this,"ToggledOutReg(Int_t)"); + // signals[idac]->Connect("ToggledSignalDbitList(Int_t)","ctbSignals",this,"ToggledDbitList(Int_t)"); + // signals[idac]->Connect("ToggledSignalPlot(Int_t)","ctbSignals",this,"ToggledPlot(Int_t)"); + + + hframe=new TGHorizontalFrame(vframe, 800,50); + vframe->AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + TGLabel *label= new TGLabel(hframe, "IO Control Register: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + eIOCntrlRegister = new TGNumberEntry(hframe, 0, 16,999, TGNumberFormat::kNESHex, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + + hframe->AddFrame(eIOCntrlRegister,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eIOCntrlRegister->MapWindow(); + eIOCntrlRegister->Resize(150,30); + + + + + hframe=new TGHorizontalFrame(vframe, 800,50); + vframe->AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + hframe->MapWindow(); + + + label= new TGLabel(hframe, "DBit Offset: "); + hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + label->MapWindow(); + label->SetTextJustify(kTextLeft); + + + eDbitOffset = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELNoLimits); + + hframe->AddFrame(eDbitOffset,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + eDbitOffset->MapWindow(); + eDbitOffset->Resize(150,30); + + + TGTextEntry *e= eDbitOffset->TGNumberEntry::GetNumberEntry(); + e->Connect("ReturnPressed()","ctbSignals",this,"setDbitOffset()"); + + e->Connect("ValueSet(Long_t)","ctbSignals",this,"setDbitOffset(Long_t)"); +} + + + + +int ctbSignals::setSignalAlias(string line) { + + int is=-1, plot=0, col=-1; + char tit[100]; + int narg=sscanf(line.c_str(),"BIT%d %s %d %d",&is,tit,&plot,&col); + if (narg<2) + return -1; + if (is>=0 && issetSignalAlias(tit,plot,col); + } + return is; + +} + +string ctbSignals::getSignalAlias() { + + ostringstream oss; + for (int is=0; isgetSignalAlias() << endl; + + + return oss.str(); + +} + + +void ctbSignals::update() { + Long64_t oreg=myDet->setPatternIOControl();//setCTBWord(-1,-1); + // Long64_t creg=myDet->setPatternClockControl();//setCTBWord(-2,-1); + + + char val[1000]; + cout << hex << oreg << dec << endl; + // cout << hex << creg << dec << endl; + + sprintf(val,"%llX",oreg); + // eIOCntrlRegister->SetHexNumber(oreg); + + + for (int idac=0; idacsetOutput(oreg); + + } + + Long64_t mask; + std::vector dbitlist=myDet->getReceiverDbitList(); + if (dbitlist.empty()) + for (int is=0; is<64; is++) { + signals[is]->setDbitList(1); + } + else { + for (int is=0; is<64; is++) signals[is]->setDbitList(0); + for (const auto &value : dbitlist) { + signals[value]->setDbitList(1); + } + } + + + eDbitOffset->SetNumber(myDet->getReceiverDbitOffset()); + +} + + +string ctbSignals::getSignalParameters() { + + + ostringstream line; + line << "patioctrl " << hex << myDet->setPatternIOControl() << dec << endl;//setCTBWord(-1,-1) + return line.str(); + + +} + +void ctbSignals::ToggledOutReg(Int_t mask) { + + char val[1000]; + Long64_t oreg=myDet->setPatternIOControl();//setCTBWord(-1,-1); + Long64_t m=((Long64_t)1)<isOutput()) { + cout << " or " << m ; + oreg|=m; + } else { + cout << " not " << ~m ; + oreg&=~m; + } + cout << " after " << oreg << endl; + + myDet->setPatternIOControl(oreg);//setCTBWord(-1,oreg); + oreg=myDet->setPatternIOControl();//myDet->setCTBWord(-1,-1); + + cout << dec << sizeof(Long64_t) << " " << mask << " " << hex << m << " ioreg " << oreg << endl; + + sprintf(val,"%llX",oreg); + // eIOCntrlRegister->SetHexNumber(oreg); + eIOCntrlRegister->SetText(val); + // eIOCntrlRegister->SetNumber(oreg); + +} + + + +void ctbSignals::ToggledDbitList(Int_t mask){ + + + + cout << "************* Here" << endl; + + + + std::vector new_dbitlist; + std::vector old_dbitlist=myDet->getReceiverDbitList(); + + char val[1000]; + Long64_t m=((Long64_t)1)<isDbitList()) + ; + else { + int ns=0; + for (int is=0; is<64; is++) { + if (signals[is]->isDbitList()){ + new_dbitlist.push_back(is); + ns++; + cout << is << " " << ns << endl; + } + } + if (ns>63) new_dbitlist.clear(); + myDet->setReceiverDbitList(new_dbitlist); + } + std::vector dbitlist=myDet->getReceiverDbitList(); + if (dbitlist.empty()) + for (int is=0; is<64; is++) signals[is]->setDbitList(1); + else + for (int is=0; is<64; is++) signals[is]->setDbitList(0); + for (const auto &value : dbitlist) signals[value]->setDbitList(1); + +} + + + + +void ctbSignals::ToggledPlot(Int_t b) { + + Emit("ToggledSignalPlot(Int_t)", b); + +} + + +void ctbSignals::ToggledSignalPlot(Int_t b) { + + Emit("ToggledSignalPlot(Int_t)", b); + +} + + +Pixel_t ctbSignals::getColor(int i){ + if (i>=0 && igetColor(); +} + +int ctbSignals::getPlot(int i){ + if (i>=0 && iisPlot(); +}; + +void ctbSignals::setDbitOffset(Long_t) { + setDbitOffset(); +} +void ctbSignals::setDbitOffset(){ + myDet->setReceiverDbitOffset(eDbitOffset->GetNumber()); +} diff --git a/ctbGui/ctbSignals.h b/ctbGui/ctbSignals.h new file mode 100755 index 000000000..8761b5f1d --- /dev/null +++ b/ctbGui/ctbSignals.h @@ -0,0 +1,118 @@ +#ifndef CTBSIGNALS_H +#define CTBSIGNALS_H +#include + + +#define NSIGNALS 64 + +#define NIOSIGNALS 64 //for moench board was 52 + + +#define ADCLATCH 63 +#define DIGSIGLATCH 62 + + + + +class TGTextEntry; +class TGLabel; +class TGNumberEntry; +class TGCheckButton; +class TH1I; +class TGTextButton; +class TGColorSelect; + + + +class TGNumberEntry; +class multiSlsDetector; +class ctbSignal; + +#include +using namespace std; + +class ctbSignal : public TGHorizontalFrame { + + // RQ_OBJECT("ctbSignal") + +private: + + TGLabel *sLabel; + TGCheckButton *sOutput; + TGCheckButton *sDbitList; + TGCheckButton *sPlot; + TGLabel *sValue; + TGNumberEntry *sEntry; + TGColorSelect *fColorSel; + + multiSlsDetector *myDet; + Int_t id; + + TH1I *hsig; + +public: + + ctbSignal(TGFrame *page, int i, multiSlsDetector *det); + int setSignalAlias(char *tit, int plot, int col); + string getSignalAlias(); + + TH1I *getPlot() {return hsig;}; + int setOutput(Long64_t); + int fixOutput(int); + int setDbitList(Long64_t); + + void ToggledOutput(Bool_t); + void ToggledDbitList(Bool_t); + void ToggledPlot(Bool_t); + void ColorChanged(Pixel_t); + + int isDbitList(); + int isOutput(); + int isPlot(); + Pixel_t getColor(); + + + void ToggledSignalOutput(Int_t); //*SIGNAL* + void ToggledSignalDbitList(Int_t); //*SIGNAL* + void ToggledSignalPlot(Int_t); //*SIGNAL* + + + + ClassDef(ctbSignal,0) +}; + +class ctbSignals : public TGGroupFrame { +private: + + ctbSignal *signals[NSIGNALS]; + + TGNumberEntry *eIOCntrlRegister; + TGNumberEntry *eDbitOffset; + + multiSlsDetector *myDet; + +public: + ctbSignals(TGVerticalFrame *page, multiSlsDetector *det); + int setSignalAlias(string line); + string getSignalAlias(); + + int getPlot(int); + Pixel_t getColor(int); + + void update(); + // void saveParameters(); + string getSignalParameters(); + + //void setDbitList(Int_t); + void setDbitOffset(Long_t); + void setDbitOffset(); + + void ToggledOutReg(Int_t); + void ToggledDbitList(Int_t); + void ToggledPlot(Int_t); + void ToggledSignalPlot(Int_t); //*SIGNAL* + + ClassDef(ctbSignals,0) +}; + +#endif diff --git a/ctbGui/ctbSlowAdcs.cpp b/ctbGui/ctbSlowAdcs.cpp new file mode 100644 index 000000000..4c6d34113 --- /dev/null +++ b/ctbGui/ctbSlowAdcs.cpp @@ -0,0 +1,185 @@ + +#include +#include +#include + +#include +#include +#include +#include + +#include "ctbSlowAdcs.h" +#include "multiSlsDetector.h" +#include "sls_detector_defs.h" + +using namespace std; + + + + +ctbSlowAdc::ctbSlowAdc(TGGroupFrame *page, int idac, multiSlsDetector *det) : TGHorizontalFrame(page, 800,50) , id(idac), myDet(det) { + + + TGHorizontalFrame *hframe=this; + + page->AddFrame(hframe,new TGLayoutHints(kLHintsTop | kLHintsExpandX , 1,1,1,1)); + MapWindow(); + + char tit[100]; + + + sprintf(tit, "SENSE %d:",idac-1000); + + dacsLabel= new TGLabel(hframe, tit);// new TGLabel(hframe, tit); + + + + hframe->AddFrame(dacsLabel,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + dacsLabel->MapWindow(); + dacsLabel->SetTextJustify(kTextLeft); + + + + + sprintf(tit, "xxx"); + dacsValue= new TGLabel(hframe, tit); + hframe->AddFrame( dacsValue,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + dacsValue->MapWindow(); + dacsValue->SetTextJustify(kTextLeft); + + + + TGTextButton *b= new TGTextButton(hframe, "Update"); + hframe->AddFrame( b,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 5, 5, 5, 5)); + b->MapWindow(); + b->SetTextJustify(kTextLeft); + + b->Connect("Clicked()","ctbSlowAdc",this,"getValue()"); + + + +} + + + +int ctbSlowAdc::setLabel(char *tit) { + if(tit) + dacsLabel->SetText(tit); + + + return id; + +} + +string ctbSlowAdc::getLabel() { + + ostringstream line; + line << dacsLabel->GetText() << endl; + + // line << "DAC" << dec << id << " " << dacsUnit->IsOn() << endl; + + return line.str(); + +} + + + +int ctbSlowAdc::getValue() { + + int val=myDet->getADC((slsDetectorDefs::dacIndex)id); + char s[100]; + cout << "adc " << id << " " << val << endl; + sprintf(s,"%d mV",val); + if (id==999) + sprintf(s,"%d °C",val); + dacsValue->SetText(s); + + + + return val; + +} + + + + + + + +ctbSlowAdcs::ctbSlowAdcs(TGVerticalFrame *page, multiSlsDetector *det) : TGGroupFrame(page,"Sense",kVerticalFrame) , myDet(det){ + + + SetTitlePos(TGGroupFrame::kLeft); + page->AddFrame(this,new TGLayoutHints( kLHintsTop | kLHintsExpandX , 10,10,10,10)); + MapWindow(); + + // cout << "window mapped " << endl; + + + for (int idac=0; idacsetLabel("Temperature"); + +} + + + + +int ctbSlowAdcs::setSlowAdcAlias(string line) { + + int is=-1, mv=0; + char tit[100]; + int narg=sscanf(line.c_str(),"SENSE%d %s",&is,tit,&mv); + if (narg<2) + return -1; + if (is>=0 && issetLabel(tit); + return is; + +} + +string ctbSlowAdcs::getSlowAdcAlias() { + + ostringstream line; + + for (int i=0; igetLabel() << endl; + return line.str(); + +} + + + + +string ctbSlowAdcs::getAdcParameters() { + + + ostringstream line; + + for (int i=0; igetValue << endl; + line << "adc:" << i << " " << adcs[i]->getValue() << endl; + } + line << "adc:-1" << adcs[NSLOWADCS]->getValue() << endl; + return line.str(); + + +} + + + +void ctbSlowAdcs::update() { + + + for (int idac=0; idacgetValue(); + + } + + +} diff --git a/ctbGui/ctbSlowAdcs.h b/ctbGui/ctbSlowAdcs.h new file mode 100644 index 000000000..ef25944fa --- /dev/null +++ b/ctbGui/ctbSlowAdcs.h @@ -0,0 +1,75 @@ + + +#ifndef CTBSLOWADCS_H +#define CTBSLOWADCS_H +#include + + +//#define NDACS 16 +#define NSLOWADCS 8 + + + + +class TGTextEntry; +class TGLabel; +class TGNumberEntry; +class TGCheckButton; +class TGTextButton; + + + +class multiSlsDetector; + +#include +using namespace std; + +class ctbSlowAdc : public TGHorizontalFrame { + + + protected: + // TGLabel *dacsLabel; + // TGNumberEntry *dacsEntry; + // TGCheckButton *dacsUnit; + TGLabel *dacsLabel; + TGLabel *dacsValue; + int id; + + multiSlsDetector* myDet; + public: + ctbSlowAdc(TGGroupFrame*, int , multiSlsDetector*); + int getValue(); + + int setLabel(char *tit); + string getLabel(); + + + + ClassDef(ctbSlowAdc,0) +}; + + +class ctbSlowAdcs : public TGGroupFrame { +private: + + + + ctbSlowAdc *adcs[NSLOWADCS+1]; + + multiSlsDetector* myDet; + +public: + ctbSlowAdcs(TGVerticalFrame *page, multiSlsDetector*); + + int setSlowAdcAlias(string line); + // int setDacAlias(string line); + string getSlowAdcAlias(); + string getAdcParameters(); + + void update(); + + ClassDef(ctbSlowAdcs,0) +}; + +#endif + diff --git a/ctbGui/patternGenerator/deserializer.cpp b/ctbGui/patternGenerator/deserializer.cpp new file mode 100644 index 000000000..c315ca419 --- /dev/null +++ b/ctbGui/patternGenerator/deserializer.cpp @@ -0,0 +1,110 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + + int iarg; + char fname[10000]; + uint64_t word; + int val[64]; + int bit[64]; + FILE *fdin; + + int nb=2; + int off=0; + int ioff=0; + int dr=24; + int idr=0; + int ib=0; + int iw=0; + bit[0]=19; + bit[1]=8; + // for (iarg=0; iarg2) dr=atoi(argv[2]); + if (argc>3) off=atoi(argv[3]); + if (argc>4) { + for (ib=0; ib<64; ib++) { + if (argc>4+ib) { + bit[ib]=atoi(argv[4+ib]); + nb++; + } + } + + } + + idr=0; + for (ib=0; ib +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXLOOPS 3 +#define MAXTIMERS 3 +#define MAXWORDS 1024 + + + +uint64_t pat=0; +uint64_t iopat=0; +uint64_t clkpat=0; + +int iaddr=0; +int waitaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS}; +int startloopaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS}; +int stoploopaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS}; +int start=0, stop=0; +uint64_t waittime[3]={0,0,0}; +int nloop[3]={0,0,0}; + +char infile[10000], outfile[10000]; + +FILE *fd, *fd1; +uint64_t PAT[MAXWORDS]; + + +int i,ii,iii,j,jj,jjj,pixx,pixy,memx,memy,muxout,memclk,colclk,rowclk,muxclk,memcol,memrow,loopcounter; + +void setstart() { + start=iaddr; +} + +void setstop() { + stop=iaddr; +} + +void setinput(int bit) { + uint64_t mask=1; + mask=mask<>bit; +} + +void setstartloop(int iloop) { + if (iloop>=0 && iloop=0 && iloop=0 && iloop=0 && iloop=0 && iloop=MAXWORDS) printf("ERROR: too many word in the pattern (%d instead of %d)!",iaddr, MAXWORDS); +} + +int parseCommand(int clk, int cmdbit, int cmd, int length) { + int ibit; + clearbit(clk); + for (ibit=0; ibit>ibit)) + setbit(cmdbit); + else + clearbit(cmdbit); + pw(); + /******/ + setbit(clk); + pw(); + /******/ + } +}; + + + +main(void) { + int iloop=0; + fd=fopen(OUTFILE,"w"); +#include INFILE + + fprintf(fd,"patioctrl %016llx\n",iopat); + fprintf(fd,"patclkctrl %016llx\n",clkpat); + fprintf(fd,"patlimits %04x %04x\n",start, stop); + + for (iloop=0; iloop usleep for meas. time , TS # -# # -##################################################################### - -BEGIN { - -# initialize variables - NPAR=3 - - PAR[1]="nrun" - PAR[2]="fn" - PAR[3]="par" - -# initialize default values - - - - PARVAL[1] = 100 - PARVAL[2] = "microstrip_july2007" - PARVAL[3]=0 - - - - - - printf("\n\nnumber of command line arguments: %i (incl. command)\n\n", ARGC); - -# read command line defined variables - if (ARGC>1) { - printf("\n\nnumber of command line arguments: %i (incl. command)\n\n", ARGC); - for (i=1; i<=ARGC; i++) { - printf("%s \n", ARGV[i]); - nsplit=split(ARGV[i],array,"=") - VAR = array[1]; - VAL = array[2]; - - for (j=1; j<=NPAR; j++) { - if ( VAR==PAR[j] ) { - PARVAL[j] = VAL - } - } - } - } - run=PARVAL[1] - fn=PARVAL[2] - par=PARVAL[3] - - -# print command line arguments - for (i=1; i<=NPAR; i++){ - printf("\t... %2i.\t%7s = %s\n", i, PAR[i], PARVAL[i] ); - } - printf("\n\n"); - -# generate parameter file - - fnamep=fn".parab" - printf("header before\n")>> fnamep - system("date >>"fnamep) - printf("run=%i \n", run ) >> fnamep - -#print detector parameters to file - if (par==1) { - - command="sls_detector_get exptime| awk -F \" \" '{print $2}'" - command | getline var - printf("acquisition time = %11.6f second(s)\n", var) >> fnamep - - command="sls_detector_get settings| awk -F \" \" '{print $2}'" - command | getline var - printf("settings = %s\n", var) >> fnamep; - - command="sls_detector_get threshold| awk -F \" \" '{print $2}'" - command | getline var - printf("threshold energy = %d eV\n", var) >> fnamep; - - command="sls_detector_get badchannels| awk -F \" \" '{print $2}'" - command | getline var - printf("bad channel list = %s\n",var) >> fnamep; - - - command="sls_detector_get angconv| awk -F \" \" '{print $2}'" - command | getline var - printf("angle calibration conversion = %s\n",var) >> fnamep; - - - command="sls_detector_get globaloff| awk -F \" \" '{print $2}'" - command | getline var - printf("beamline offset = %f deg\n", var) >> fnamep; - - command="sls_detector_get fineoff| awk -F \" \" '{print $2}'" - command | getline var - printf("fine offset = %f deg\n", var) >> fnamep; - - command="sls_detector_get flatfield| awk -F \" \" '{print $2}'" - command | getline var - printf("Flat field corrections = %s\n",var) >> fnamep; - - command="sls_detector_get ratecorr| awk -F \" \" '{print $2}'" - command | getline var - printf("Dead time corrections tau = %d ns\n",var) >> fnamep; - - } - - -#print beamline parameters to file - -#read detector position - system("caget X04SA-ES2-TH2:RO.RBV >>"fnamep) -#read I0 - system("caget X04SA-ES2-SC:CH6>>"fnamep) -} - - - - - diff --git a/examples/scripts/ScanScript.awk b/examples/scripts/ScanScript.awk deleted file mode 100755 index 7617e340c..000000000 --- a/examples/scripts/ScanScript.awk +++ /dev/null @@ -1,87 +0,0 @@ -#! /bin/awk -f - -# this is an awk script to start a run -# you first need to run inimodule.awk to initialize -# the pattern, set Vc and set the trimbits -# - -##################################################################### -# revision history # -##################################################################### -# 31.10.2001 first version # -##################################################################### -# # -# Bernd Schmitt # -# # -# bernd.schmitt@psi.ch # -# # -##################################################################### -# # -# modifications: # -# # -# 1.3.2002 BS adapted for use with DCB # -# # -# 25.5.2002 BS adapted to new convert program # -# # -# 29.5.2002 sleep -> usleep for meas. time , TS # -# # -##################################################################### - -BEGIN { - -# initialize variables - NPAR=4 - - PAR[1]="nrun" - PAR[2]="fn" - PAR[3]="var" - PAR[4]="par" - - -# initialize default values - PARVAL[1] = 100 - PARVAL[2] = "myfname" - PARVAL[3] = 0 - PARVAL[2] = "none" - - - -# read command line defined variables - if (ARGC>1) { - printf("\n\nnumber of command line arguments: %i (incl. command)\n\n", ARGC); - for (i=1; i<=ARGC; i++) { - - nsplit=split(ARGV[i],array,"=") - VAR = array[1]; - VAL = array[2]; - - for (j=1; j<=NPAR; j++) { - if ( VAR==PAR[j] ) { - PARVAL[j] = VAL - } - } - } - } - - run=PARVAL[1] - fn=PARVAL[2] - var=PARVAL[3] - par=PARVAL[4] - - - - -# print command line arguments - for (i=1; i<=NPAR; i++){ - printf("\t... %2i.\t%7s = %s\n", i, PAR[i], PARVAL[i] ); - } - -#execute you command hereafter e.g. change temperature etc. - - -} - - - - - diff --git a/examples/scripts/ScriptBeforeAfter.awk b/examples/scripts/ScriptBeforeAfter.awk deleted file mode 100755 index 14838e280..000000000 --- a/examples/scripts/ScriptBeforeAfter.awk +++ /dev/null @@ -1,100 +0,0 @@ -#! /bin/awk -f - -# this is an awk script to start a run -# you first need to run inimodule.awk to initialize -# the pattern, set Vc and set the trimbits -# - -##################################################################### -# revision history # -##################################################################### -# 31.10.2001 first version # -##################################################################### -# # -# Bernd Schmitt # -# # -# bernd.schmitt@psi.ch # -# # -##################################################################### -# # -# modifications: # -# # -# 1.3.2002 BS adapted for use with DCB # -# # -# 25.5.2002 BS adapted to new convert program # -# # -# 29.5.2002 sleep -> usleep for meas. time , TS # -# # -##################################################################### - -BEGIN { - -# initialize variables - NPAR=7 - - PAR[1]="nrun" - PAR[2]="fn" - PAR[3]="par" - PAR[4]="sv0" - PAR[5]="sv1" - PAR[6]="p0" - PAR[7]="p1" - -# initialize default values - PARVAL[1] = 100 - PARVAL[2] = "myfname" - PARVAL[3] = 1 - PARVAL[4] = 0 - PARVAL[5] = 0 - PARVAL[6] = "none" - PARVAL[7] = "none" - - - -# read command line defined variables - if (ARGC>1) { - printf("\n\nnumber of command line arguments: %i (incl. command)\n\n", ARGC); - for (i=1; i<=ARGC; i++) { - - nsplit=split(ARGV[i],array,"=") - VAR = array[1]; - VAL = array[2]; - - for (j=1; j<=NPAR; j++) { - if ( VAR==PAR[j] ) { - PARVAL[j] = VAL - } - } - } - } - - run=PARVAL[1] - fn=PARVAL[2] - "par"PAR[3]= - sv0=PAR[4] - sv1=PAR[5] - p0=PAR[6] - p1=PAR[7] - - - -# print command line arguments - for (i=1; i<=NPAR; i++){ - printf("\t... %2i.\t%7s = %s\n", i, PAR[i], PARVAL[i] ); - } -# printf("\n\n"); - # system("close_shutter_g95") - -# execute your actions hereafter - if (par==1) { - #open shutter - } else { - #close shutter - } - -} - - - - - diff --git a/examples/scripts/StartStopScript.awk b/examples/scripts/StartStopScript.awk deleted file mode 100755 index f8e53917c..000000000 --- a/examples/scripts/StartStopScript.awk +++ /dev/null @@ -1,79 +0,0 @@ -#! /bin/awk -f - -# this is an awk script to start a run -# you first need to run inimodule.awk to initialize -# the pattern, set Vc and set the trimbits -# - -##################################################################### -# revision history # -##################################################################### -# 31.10.2001 first version # -##################################################################### -# # -# Bernd Schmitt # -# # -# bernd.schmitt@psi.ch # -# # -##################################################################### -# # -# modifications: # -# # -# 1.3.2002 BS adapted for use with DCB # -# # -# 25.5.2002 BS adapted to new convert program # -# # -# 29.5.2002 sleep -> usleep for meas. time , TS # -# # -##################################################################### - -BEGIN { - -# initialize variables - NPAR=2 - - PAR[1]="nrun" - PAR[2]="par" - - -# initialize default values - PARVAL[1] = 100 - PARVAL[2] = "none" - - - -# read command line defined variables - if (ARGC>1) { - printf("\n\nnumber of command line arguments: %i (incl. command)\n\n", ARGC); - for (i=1; i<=ARGC; i++) { - - nsplit=split(ARGV[i],array,"=") - VAR = array[1]; - VAL = array[2]; - - for (j=1; j<=NPAR; j++) { - if ( VAR==PAR[j] ) { - PARVAL[j] = VAL - } - } - } - } - - run=PARVAL[1] - par=PARVAL[2] - - - - -# print command line arguments - for (i=1; i<=NPAR; i++){ - printf("\t... %2i.\t%7s = %s\n", i, PAR[i], PARVAL[i] ); - } -#execute action hereafter - -} - - - - - diff --git a/examples/two_no_receiver.config b/examples/two_no_receiver.config deleted file mode 100755 index 18718ad64..000000000 --- a/examples/two_no_receiver.config +++ /dev/null @@ -1,64 +0,0 @@ -#####Any line with a # is not read###### - -#type Gotthard+ -hostname bchip007+bchip009+ - -#0:hostname bchip007 -#0:port 1952 -#0:stopport 1953 -#0:rx_tcpport 1956 -0:settingsdir /home/l_msdetect/dhanya/slsDetectorsPackage/settingsdir/gotthard -0:angdir 1.000000 -0:moveflag 0.000000 -0:lock 0 -0:caldir /home/l_msdetect/dhanya/slsDetectorsPackage/settingsdir/gotthard -0:ffdir /home/l_msdetect -0:extsig:0 off -0:extsig:1 off -0:extsig:2 off -0:extsig:3 off -#0:detectorip 10.1.1.2 -#0:detectormac 00:aa:bb:cc:dd:ee -#0:rx_udpport 50001 -#0:rx_udpip 10.1.1.1 -#0:rx_hostname 129.129.202.134 -0:outdir /data/speedt -0:vhighvoltage 120 - - -#1:hostname bchip009 -#1:port 1952 -#1:stopport 1953 -1:rx_tcpport 1957 -1:settingsdir /home/l_msdetect/dhanya/slsDetectorsPackage/settingsdir/gotthard -1:angdir 1.000000 -1:moveflag 0.000000 -1:lock 0 -1:caldir /home/l_msdetect/dhanya/slsDetectorsPackage/settingsdir/gotthard -1:ffdir /home/l_msdetect -1:extsig:0 off -1:extsig:1 off -1:extsig:2 off -1:extsig:3 off -#1:detectorip 10.1.2.2 -#1:detectormac 00:aa:bb:cc:dd:ee -#1:rx_udpport 50004 -#1:rx_udpip 10.1.2.1 -#1:rx_hostname 129.129.202.134 -1:outdir /data/speedt -1:vhighvoltage 120 - - -master -1 -sync none -outdir /data/speedt -ffdir /home/l_msdetect -headerbefore none -headerafter none -headerbeforepar none -headerafterpar none -badchannels none -angconv none -globaloff 0.000000 -binsize 0.001000 -threaded 1 diff --git a/integrationTests/test-integrationDectector.cpp b/integrationTests/test-integrationDectector.cpp index eab84b241..0523f0edc 100755 --- a/integrationTests/test-integrationDectector.cpp +++ b/integrationTests/test-integrationDectector.cpp @@ -479,4 +479,42 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert", "[.ctbintegrat CHECK(m.getExternalSampling() == 1); CHECK(m.readRegister(0x7b) == 0x1003E); +} + +TEST_CASE("Eiger or Jungfrau startingfnum", "[.eigerintegration][.jungfrauintegration][startingfnum]") { + SingleDetectorConfig c; + + // pick up multi detector from shm id 0 + multiSlsDetector m(0); + + // ensure ctb detector type, hostname and online + REQUIRE(((m.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::EIGER) || (m.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::JUNGFRAU))); + REQUIRE(m.getHostname() == c.hostname); + REQUIRE(m.setOnline(true) == slsDetectorDefs::ONLINE_FLAG); + + CHECK(m.setTimer(slsDetectorDefs::FRAME_NUMBER, 1) == 1); + + // starting fnum + uint64_t val = 8; + + m.setStartingFrameNumber(val); + CHECK(m.getStartingFrameNumber() == val); + CHECK(m.acquire() == slsDetectorDefs::OK); + CHECK(m.getReceiverCurrentFrameIndex() == val); + + ++val; + CHECK(m.acquire() == slsDetectorDefs::OK); + CHECK(m.getReceiverCurrentFrameIndex() == val); + + CHECK_THROWS_AS(m.setStartingFrameNumber(0), sls::RuntimeError); + + if (m.getDetectorTypeAsString() == "Eiger") { + val = 281474976710655; + } else if (m.getDetectorTypeAsString() == "Jungfrau") { + val = 18446744073709551615; + } + m.setStartingFrameNumber(val); + CHECK(m.getStartingFrameNumber() == val); + CHECK(m.acquire() == slsDetectorDefs::OK); + CHECK(m.getReceiverCurrentFrameIndex() == val); } \ No newline at end of file diff --git a/integrationTests/test-integrationMulti.cpp b/integrationTests/test-integrationMulti.cpp index 580d5723c..2eb138eb3 100755 --- a/integrationTests/test-integrationMulti.cpp +++ b/integrationTests/test-integrationMulti.cpp @@ -107,4 +107,4 @@ TEST_CASE("Set and read timers", "[.integration][.multi]") { // MAX_TIMERS d.freeSharedMemory(); -} \ No newline at end of file +} diff --git a/manual/manual-api/mainReceiver.cpp b/manual/manual-api/mainReceiver.cpp index ca6e0f591..7762079e5 100755 --- a/manual/manual-api/mainReceiver.cpp +++ b/manual/manual-api/mainReceiver.cpp @@ -19,18 +19,18 @@ It is linked in manual/manual-api from slsReceiverSoftware/include ] #include "sls_detector_defs.h" #include "slsReceiverUsers.h" -#include -#include -#include //SIGINT +#include //SIGINT #include //system +#include +#include //#include "utilities.h" //#include "logger.h" +#include +#include #include //wait #include //wait -#include -#include //usleep -#include #include //tid +#include //usleep using namespace std; diff --git a/manual/manual-main/slsDetectorInstall.tex b/manual/manual-main/slsDetectorInstall.tex index dcf7fc84e..542935881 100755 --- a/manual/manual-main/slsDetectorInstall.tex +++ b/manual/manual-main/slsDetectorInstall.tex @@ -127,7 +127,7 @@ conda install sls_detector_gui=4.0.0 \begin{verbatim} #Add conda channels conda config --add channels conda-forge -conda config --add channels sls_detector +conda config --add channels slsdetectorgroup #Install latest version conda install sls_detector diff --git a/python/src/Detector.h b/python/src/Detector.h index bb11b1a27..fd626ae37 100755 --- a/python/src/Detector.h +++ b/python/src/Detector.h @@ -7,12 +7,9 @@ #include #include -#include "error_defs.h" #include "multiSlsDetector.h" #include "slsDetector.h" -// #include "slsDetectorUtils.h" #include "sls_detector_defs.h" -// #include "sls_receiver_defs.h" class Detector { public: diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h new file mode 100755 index 000000000..35249b1c9 --- /dev/null +++ b/slsDetectorCalibration/MovingStat.h @@ -0,0 +1,156 @@ +#ifndef MOVINGSTAT_H +#define MOVINGSTAT_H + +#include + + +class MovingStat + { + + /** @short approximated moving average structure */ + public: + + + /** constructor + \param nn number of samples parameter to be used + */ + MovingStat(int nn=1000) : n(nn), m_n(0) {} + + /** + clears the moving average number of samples parameter, mean and standard deviation + */ + void Clear() + { + m_n = 0; + m_newM=0; + m_newM2=0; + } + + /** + clears the moving average number of samples parameter, mean and standard deviation + */ + void Set(double val, double rms=0, int m=-1) + { + if (m>=0) m_n = m; else m_n = n; + m_newM=val*m_n; + SetRMS(rms); + } + /** + clears the moving average number of samples parameter, mean and standard deviation + */ + void SetRMS(double rms) + { + if (rms<=0) { + m_newM2=m_newM*m_newM/n; + m_n=0; + } else { + if (m_n>0) + m_newM2=(m_n*rms*rms+m_newM*m_newM/m_n); + else { + m_newM2=(m_n*rms*rms+m_newM*m_newM/n); + m_n=0; + } + } + } + + /** sets number of samples parameter + \param i number of samples parameter to be set + */ + + int SetN(int i) {if (i>=1) n=i; return n;}; + + /** + gets number of samples parameter + \returns actual number of samples parameter + */ + int GetN() {return m_n;}; + + /** calculates the moving average i.e. adds if number of elements is lower than number of samples parameter, pushes otherwise + \param x value to calculate the moving average + */ + inline void Calc(double x) { + if (m_n 0) ? m_newM/m_n : 0.0; + } + + /** returns the squared mean, 0 if no elements are inside + \returns returns the squared average + */ + double M2() const + { + return ( (m_n > 1) ? m_newM2/m_n : 0.0 ); + } + + /** returns the variance, 0 if no elements are inside + \returns returns the variance + */ + inline double Variance() const + { + return ( (m_n > 1) ? (M2()-Mean()*Mean()) : 0.0 ); + } + + /** returns the standard deviation, 0 if no elements are inside + \returns returns the standard deviation + */ + inline double StandardDeviation() const + { + return ( (Variance() > 0) ? sqrt( Variance() ) : -1 ); + } + + private: + int n; /**< number of samples parameter */ + int m_n; /**< current number of elements */ + double m_newM; /**< accumulated average */ + double m_newM2; /**< accumulated squared average */ + }; +#endif diff --git a/slsDetectorCalibration/RunningStat.h b/slsDetectorCalibration/RunningStat.h new file mode 100755 index 000000000..1197ffc0f --- /dev/null +++ b/slsDetectorCalibration/RunningStat.h @@ -0,0 +1,55 @@ + class RunningStat + { + public: + RunningStat() : m_n(0) {} + + void Clear() + { + m_n = 0; + } + + void Push(double x) + { + m_n++; + + // See Knuth TAOCP vol 2, 3rd edition, page 232 + if (m_n == 1) + { + m_oldM = m_newM = x; + m_oldS = 0.0; + } + else + { + m_newM = m_oldM + (x - m_oldM)/m_n; + m_newS = m_oldS + (x - m_oldM)*(x - m_newM); + + // set up for next iteration + m_oldM = m_newM; + m_oldS = m_newS; + } + } + + int NumDataValues() const + { + return m_n; + } + + double Mean() const + { + return (m_n > 0) ? m_newM : 0.0; + } + + double Variance() const + { + return ( (m_n > 1) ? m_newS/(m_n - 1) : 0.0 ); + } + + double StandardDeviation() const + { + return sqrt( Variance() ); + } + + private: + int m_n; + double m_oldM, m_newM, m_oldS, m_newS; + }; diff --git a/slsDetectorCalibration/Stat.h b/slsDetectorCalibration/Stat.h new file mode 100644 index 000000000..196f5bbb7 --- /dev/null +++ b/slsDetectorCalibration/Stat.h @@ -0,0 +1,45 @@ +class Stat + { + public: + + Stat() : n(0), m(0.), m2(0.) {} + + void Clear() + { + n = 0; + m=0; + m2=0; + } + + void Push(double x) + { + + m+=x; + m2+=x*x; + n++; + } + + int NumDataValues() const + { + return n; + } + + double Mean() const + { + return (n > 0) ? m/n : 0.0; + } + + double Variance() const + { + return ( (n >0 ) ? (m2/n-m*m/(n*n)) : 0.0 ); + } + + double StandardDeviation() const + { + return sqrt( Variance() ); + } + + private: + int n; + double m, m2; + }; diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h new file mode 100644 index 000000000..49197f0a6 --- /dev/null +++ b/slsDetectorCalibration/analogDetector.h @@ -0,0 +1,1166 @@ +#ifndef ANALOGDETECTOR_H +#define ANALOGDETECTOR_H + +//#include + +#include +#include "slsDetectorData.h" +#include "pedestalSubtraction.h" +#include "commonModeSubtraction.h" +#include "tiffIO.h" +#include "slsInterpolation.h" + + +#ifdef ROOTSPECTRUM +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +using namespace std; + +#ifndef FRAMEMODE_DEF +#define FRAMEMODE_DEF +/** +enum to define the flags of the data set, which are needed to seect the type of processing it should undergo: frame, pedestal, flat +*/ + enum frameMode { eFrame, ePedestal, eFlat }; +/** +enum to define the detector mode +*/ + enum detectorMode { eAnalog, ePhotonCounting, eInterpolating }; +#endif + + +template class analogDetector { + + /** @short class to perform pedestal subtraction etc. for an analog detector */ + + public: + + + + /** + + Constructor (no error checking if datasize and offsets are compatible!) + \param d detector data structure to be used - if null it is assumed that the data are in ordered ip=iy*nx+ix + \param sign is the sign of the data + \param nped number of samples for pedestal averaging + \param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none + \param nnx detector size in x - must be specified if no data structure is defined, otherwise defaults to the size of the data structure. + \param nny detector size in y - must be specified if no data structure is defined, otherwise defaults to the size of the data structure. + \param gm pointer to tha gain map matrix + + + */ + + + analogDetector(slsDetectorData *d, int sign=1, + commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), iframe(-1), dataSign(sign), gmap(gm), id(0) { + + if (det) + det->getDetectorSize(nx,ny); + + stat=new pedestalSubtraction*[ny]; + for (int i=0; idet; + nx=orig->nx; + ny=orig->ny; + dataSign=orig->dataSign; + iframe=orig->iframe; + gmap=orig->gmap; + cmSub=orig->cmSub; + id=orig->id; + xmin=orig->xmin; + xmax=orig->xmax; + ymin=orig->ymin; + ymax=orig->ymax; + thr=orig->thr; + // nSigma=orig->nSigma; + fMode=orig->fMode; + myFile=orig->myFile; + + + stat=new pedestalSubtraction*[ny]; + for (int i=0; iSetNPedestals(); + //cout << nped << " " << orig->getPedestal(ix,iy) << orig->getPedestalRMS(ix,iy) << endl; + for (int iy=0; iygetPedestal(ix,iy),orig->getPedestalRMS(ix,iy),orig->GetNPedestals(ix,iy)); + } + } + image=new int[nx*ny]; +#ifdef ROOTSPECTRUM + hs=(TH2F*)(orig->hs)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); +#ifdef ROOTCLUST + hs3=(TH2F*)(orig->hs3)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs5=(TH2F*)(orig->hs5)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs7=(TH2F*)(orig->hs7)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs9=(TH2F*)(orig->hs9)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); +#endif +#endif + + } + + + /** + clone. Must be virtual! + \returns a clone of the original analog detector + */ + virtual analogDetector *Clone() { + return new analogDetector(this); + } + + /** + Gives an id to the structure. For debugging purposes in case of multithreading. + \param i is to be set + \returns current id + */ + int setId(int i){id=i; return id;}; + + /** + Returns id of the structure. For debugging purposes in case of multithreading. + \returns current id + */ + int getId() {return id; }; + /** + Returns data size of the detector data structure + \returns data size of the detector data structurein bytes + */ + int getDataSize(){return det->getDataSize();}; + /** + Returns data size of the detector image matrix + \param nnx reference to image size in x + \param nny reference to image size in y + \param nns reference to number of subpixels for interpolating detector, will always be 1 in this case + \returns number of pixels of the detector image + */ + virtual int getImageSize(int &nnx, int &nny, int &nns){nnx=nx; nny=ny; nns=1; return nx*ny;}; + /** + Returns data size of the detector image matrix + \param nnx reference to pixel size in x + \param nny reference to pixel size in y + \returns number of pixels of the detector image + */ + virtual int getDetectorSize(int &nnx, int &nny){nnx=nx; nny=ny; return nx*ny;}; + + /** + set gain map + \param gm pointer to gain map matrix to be set - NULL unsets + \returns pointer to current gain map + */ + double *setGainMap(double *gm) {gmap=gm; return gmap;}; + + /** + return gain map + \returns pointer to current gain map + */ + double *getGainMap() {return gmap;}; + /** + reads a 32 bit tiff file of the size of the detector and sets its values as gain map for the detector. If file does not exist returns NULL, but does not change gainmap compared to previous settings. + \param imgname complete name of the file containing the gain map data + \returns pointer to current gain map is file reading succeeded, NULL is file reading didn't work. + */ + double *readGainMap(const char * imgname) { + uint32 nnx, nny; + float *gm=ReadFromTiff( imgname, nny, nnx); + if (gm) { + if (gmap) delete [] gmap; + gmap=new double[nnx*nny]; + for (int iy=0; iyClear(); +#ifdef ROOTSPECTRUM + hs->Reset(); +#ifdef ROOTCLUST + hs3->Reset();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs5->Reset();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs7->Reset();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs9->Reset();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); +#endif +#endif + }; + + /** resets the commonModeSubtraction and increases the frame index */ + virtual void newFrame(){iframe++; if (cmSub) cmSub->newFrame();}; + + + /** sets the commonModeSubtraction algorithm to be used + \param cm commonModeSubtraction algorithm to be used (NULL unsets) + \returns pointer to the actual common mode subtraction algorithm + */ + commonModeSubtraction *setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;}; +/** + gets the commonModeSubtraction algorithm to be used + \returns pointer to the actual common mode subtraction algorithm + */ + commonModeSubtraction *getCommonModeSubtraction() {return cmSub;}; + + + /** + sets the sign of the data + \param sign 1 means positive values for photons, -1 negative, 0 gets + \returns current sign for the data + */ + int setDataSign(int sign=0) {if (sign==1 || sign==-1) dataSign=sign; return dataSign;}; + + + /** + adds value to pedestal (and common mode) for the given pixel + \param val value to be added + \param ix pixel x coordinate + \param iy pixel y coordinate + \param cm 1 adds the value to common mod, 0 skips it. Defaults to 0. - not properly implemented + */ + virtual void addToPedestal(double val, int ix, int iy=0, int cm=0){ + if (ix>=0 && ix=0 && iy0) { + val-= getCommonMode(ix, iy); + } + stat[iy][ix].addToPedestal(val); + /* if (cmSub && cm>0) { */ + /* if (det) if (det->isGood(ix, iy)==0) return; */ + /* cmSub->addToCommonMode(val, ix, iy); */ + /* }; */ + }; + } + + double getCommonMode(int ix, int iy) { + if (cmSub) return cmSub->getCommonMode(ix, iy); + else return 0; + } + + + virtual void addToCommonMode(char *data){ + if (cmSub) { + for (int iy=ymin; iy0) + if (det->isGood(ix,iy)) + addToCommonMode(data, ix, iy); + } + } + //cout << "cm " << getCommonMode(0,0) << " " << getCommonMode(1,0) << endl; + } + } + virtual void addToCommonMode(char *data, int ix, int iy=0){ + if (cmSub) { + if (det) if (det->isGood(ix, iy)==0) return; + if (getNumpedestals(ix,iy)>0){ + cmSub->addToCommonMode(subtractPedestal(data,ix,iy,0), ix, iy); + // cout << ix << " " <=0 && ix=0 && iy0) + return stat[iy][ix].getPedestal()+getCommonMode(ix,iy); + else return stat[iy][ix].getPedestal(); + else return -1; + }; + + + /** + gets pedestal rms (i.e. noise) + \param ix pixel x coordinate + \param iy pixel y coordinate + \returns pedestal rms + */ + virtual double getPedestalRMS(int ix, int iy){ + if (ix>=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iySetBinContent(ix+1, iy+1,image[iy*nx+ix]); +#endif + } + } + ret=WriteToTiff(gm, imgname, ny, nx); + delete [] gm; +#ifdef ROOTSPECTRUM + char rootfn[10000]; + sprintf(rootfn,"%s.root",imgname); + TFile *f=new TFile(rootfn,"RECREATE"); + hs->Write("hs"); +#ifdef ROOTCLUST + hs3->Write("hs3"); + hs5->Write("hs5"); + hs7->Write("hs7"); + hs9->Write("hs9"); +#endif + hmap->Write("hmap"); + + + f->Close(); + delete f; + delete hmap; +#endif + return ret; + } +#ifdef ROOTSPECTRUM + TH2F *getSpectrum(){return hs;}; +#endif + /** + write 32bit tiff file containing the pedestals + \param imgname file name to be written + \returns NULL if file writing didn't succed, otherwise a pointer + */ + + virtual void *writePedestals(const char * imgname) { + float *gm=NULL; + void *ret; + gm=new float[nx*ny]; +#ifdef ROOTSPECTRUM + + TH2F *hmap=new TH2F("hmap","hmap",nx, -0.5,nx-0.5, ny, -0.5, ny-0.5); + +#endif + for (int iy=0; iygetCommonMode(); */ + /* else */ + gm[iy*nx+ix]=stat[iy][ix].getPedestal(); +#ifdef ROOTSPECTRUM + hmap->SetBinContent(ix+1, iy+1,gm[iy*nx+ix]); +#endif + } + } + ret=WriteToTiff(gm, imgname, ny, nx); + delete [] gm; + +#ifdef ROOTSPECTRUM + char rootfn[10000]; + sprintf(rootfn,"%s.root",imgname); + TFile *f=new TFile(rootfn,"RECREATE"); + hs->Write("hs"); +#ifdef ROOTCLUST + hs3->Write("hs3"); + hs5->Write("hs5"); + hs7->Write("hs7"); + hs9->Write("hs9"); +#endif + hmap->Write("hmap"); + f->Close(); + delete f; + delete hmap; +#endif + return ret; + } + + /** + read 32bit tiff file containing the pedestals + \param imgname file name to be read + \returns 0 if file reading didn't succed, otherwise 1 + */ + int readPedestals(const char * imgname) { + uint32 nnx, nny; + float *gm=ReadFromTiff( imgname, nny, nnx); + if (nnx>nx) nnx=nx; + if (nny>ny) nny=ny; + + + + if (gm) { + for (int iy=0; iynx) nnx=nx; + if (nny>ny) nny=ny; + + + + if (gm) { + for (int iy=0; iynx) nnx=nx; + if (nny>ny) nny=ny; + if (gm) { + for (int iy=0; iyisGood(ix,iy)) { + addToPedestal(data,ix,iy,1); + //if (ix==10 && iy==10) + // cout <=0 && xmi<=nx) xmin=xmi; + if (xma>=0 && xma<=nx) xmax=xma; + if (xmax=0 && ymi<=ny) ymin=ymi; + if (yma>=0 && yma<=ny) ymax=yma; + if (ymax=0 && ix=0 && iygetValue(data, ix, iy); + else + val=((double*)data)[iy*nx+ix]; + + /* if (ix==10 && iy==10) */ + /* cout << ix << " " << iy << " " << val ; */ + /* if (ix==100 && iy==100) */ + /* cout << ix << " " << iy << " " << val; */ + addToPedestal(val,ix,iy); + /* if (ix==10 && iy==10) */ + /* cout <<" " << getPedestal(ix,iy)<< endl; */ + /* if (ix==100 && iy==100) */ + /* cout << " " << getPedestal(ix,iy)<< endl; */ + } + return ; + + }; + + + /** + Subtracts pedestal from the data array in the region of interest + \param data pointer to the data + \param val pointer where the pedestal subtracted data should be added. If NULL, the internal image is used + \returns pointer to the pedestal subtracted data + */ + // virtual int *subtractPedestal(char *data, int *val=NULL) { + + virtual int *subtractPedestal(char *data, int *val=NULL, int cm=0) { + + newFrame(); + + if (val==NULL) + val=image;//new double[nx*ny]; + + for (int iy=ymin; iyisGood(ix,iy)) + val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm); + } + } + return val; + }; + + + + + /** + Subtracts pedestal from the data for a selected pixel + \param data pointer to the data + \param ix pixel x coordinate + \param iy pixel y coordinate + \returns pedestal subtracted value + */ + + + + virtual double subtractPedestal(char *data, int ix, int iy=0, int cm=0) { + double g=1.; + double val; + if (ix>=0 && ix=0 && iygetChannel(data, ix, iy)>=0x3fff) */ + /* cout << ix << " " << iy << " " << det->getChannel(data, ix, iy) <getValue(data, ix, iy)-getPedestal(ix,iy,cm))/g; + } else + val= (((double*)data)[iy*nx+ix]-getPedestal(ix,iy))/g; + +#ifdef ROOTSPECTRUM + hs->Fill(val,(iy-ymin)*(xmax-xmin)+(ix-xmin)); +#ifdef ROOTCLUST + double v3=0,v5=0,v7=0,v9=0; + for (int iix=-4; iix<5; iix++) + for (int iiy=-4; iiy<5; iiy++) { + if (det) + val= (dataSign*det->getValue(data, ix+iix, iy+iiy)-getPedestal(ix+iix,iy+iiy,cm))/g; + else + val= (((double*)data)[(iy+iiy)*nx+ix+iix]-getPedestal(ix+iix,iy+iiy,cm))/g; + + if (iix>-4 && iiy>-4 && iix<4 && iiy<4) { + if (iix>-3 && iiy>-3 && iix<3 && iiy<3){ + if (iix>-2 && iiy>-2 && iix<2 && iiy<2){ + v3+=val; + } + v5+=val; + } + v7+=val; + } + v9+=val; + } + hs3->Fill(v3,(iy-ymin)*(xmax-xmin)+(ix-xmin)); + hs5->Fill(v5,(iy-ymin)*(xmax-xmin)+(ix-xmin)); + hs7->Fill(v7,(iy-ymin)*(xmax-xmin)+(ix-xmin)); + hs9->Fill(v9,(iy-ymin)*(xmax-xmin)+(ix-xmin)); + +#endif +#endif + return val; + } + }; + + + /** + sets threshold value for conversion into number of photons + \param t threshold to be set + \returns threshold value + */ + double setThreshold(double t){thr=t; return thr;}; + + /** + gets threshold value for conversion into number of photons + \returns threshold value + */ + double getThreshold(){return thr;}; + /** + converts the data into number of photons for the selected pixel + \param data pointer to the data + \param ix pixel x coordinate + \param iy pixel y coordinate + \returns converted number of photons. If no threshold is set, returns gain converted pedestal subtracted data. + */ + + virtual int getNPhotons(char *data, int ix, int iy=0) { + int nph=0; + double v; + if (ix>=0 && ix=0 && iyFill(v,(iy-ymin)*(xmax-xmin)+(ix-xmin)); */ +/* #endif */ + if (thr>0) { + v+=0.5*thr; + nph=v/thr; + if (nph>0) + return nph; + return 0; + } + return v; + } + return 0; + }; + + /** + converts the data into number of photons for all pixels + \param data pointer to the data + \param nph pointer where the photons should added. If NULL,the internal image is used + \returns pointer to array containing the number of photons + */ + int *getNPhotons(char *data, int *nph=NULL) { + + double val; + if (nph==NULL) + nph=image; + newFrame(); + + addToCommonMode(data); + + for (int iy=ymin; iyisGood(ix,iy)) + nph[iy*nx+ix]+=getNPhotons(data, ix, iy); + } + } + return nph; + + } + + /** + clears the image array + + */ + virtual void clearImage(){ + for (int iy=0; iyReset(); +#ifdef ROOTCLUST + + if (hs3) + hs3->Reset(); + if (hs5) + hs5->Reset(); + if (hs7) + hs7->Reset(); + if (hs9) + hs9->Reset(); +#endif + //cout << "done " << endl; +#endif + }; + + /** sets/gets number of samples for moving average pedestal calculation + \param i number of samples to be set (0 or negative gets) + \returns actual number of samples + */ + int SetNPedestals(int i=-1) { + int ix=0, iy=0; + if (i>0) + for (iy=0; iy=0 && ix=0 && iyisGood(ix,iy)) { + if (ix>=0 && ix=0 && iy *det; /**< slsDetectorData to be used */ + int nx; /**< Size of the detector in x direction */ + int ny; /**< Size of the detector in y direction */ + pedestalSubtraction **stat; /**< pedestalSubtraction class */ + commonModeSubtraction *cmSub;/**< commonModeSubtraction class */ + int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */ + int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */ + double *gmap; + int *image; + int id; + //int xmin, xmax, ymin, ymax; int xmin; /**< minimum x of the region of interest */ + int xmin; /**< minimum x of the region of interest */ + int xmax; /**< maximum x of the region of interest */ + int ymin;/**< minimum y of the region of interest */ + int ymax;/**< maximum y of the region of interest */ + double thr; /**< threshold to be used for conversion into number of photons */ + // int nSigma; /**< number of sigma to be used for conversion into number of photons if threshold is undefined */ + frameMode fMode; /**< current detector frame mode */ + detectorMode dMode; /**< current detector frame mode */ + FILE *myFile; /**< file pointer to write to */ +#ifdef ROOTSPECTRUM + TH2F *hs; +#ifdef ROOTCLUST + TH2F *hs3; + TH2F *hs5; + TH2F *hs7; + TH2F *hs9; +#endif +#endif +}; + +#endif diff --git a/slsDetectorCalibration/commonModeSubtraction.h b/slsDetectorCalibration/commonModeSubtraction.h new file mode 100644 index 000000000..0484e6746 --- /dev/null +++ b/slsDetectorCalibration/commonModeSubtraction.h @@ -0,0 +1,82 @@ +#ifndef COMMONMODESUBTRACTION_H +#define COMMONMODESUBTRACTION_H + +#include "MovingStat.h" + + + + +class commonModeSubtraction { + + /** @short class to calculate the common mode of the pedestals based on an approximated moving average*/ + + public: + + /** constructor + \param nn number of samples for the moving average to calculate the average common mode + \param iroi number of regions on which one can calculate the common mode separately. Defaults to 1 i.e. whole detector + + */ + commonModeSubtraction(int nn=1000, int iroi=1) : cmStat(NULL), cmPed(NULL), nCm(NULL), nROI(iroi) {cmStat=new MovingStat[nROI]; for (int i=0; i0) cmStat[i].Calc(cmPed[i]/nCm[i]); + nCm[i]=0; + cmPed[i]=0; + }}; + + /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest + \param val value to add + \param ix pixel x coordinate + \param iy pixel y coordinate + */ + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + (void) ix; (void) iy; + + //if (isc>=0 && isc0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); + return 0;}; + + + + + + protected: + MovingStat *cmStat; /** + +class commonModeSubtraction { + + /** @short class to calculate the common mode of the pedestals based on an approximated moving average*/ + + public: + + /** constructor + \param nn number of samples for the moving average to calculate the average common mode + \param iroi number of regions on which one can calculate the common mode separately. Defaults to 1 i.e. whole detector + + */ + commonModeSubtraction(int iroi=1, int ns=3) : nROI(iroi), nsigma(ns) { + mean=new double[nROI]; + mean2=new double[nROI]; + nCm=new double[nROI]; + }; + + /** destructor - deletes the moving average(s) and the sum of pedestals calculator(s) */ + virtual ~commonModeSubtraction() {delete [] mean; delete [] mean2; delete [] nCm;}; + + + /** clears the moving average and the sum of pedestals calculation - virtual func*/ + virtual void Clear(){ + for (int i=0; i0) cmStat[i].Calc(cmPed[i]/nCm[i]); + nCm[i]=0; + mean[i]=0; + mean2[i]=0; + }}; + + /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest + \param val value to add + \param ix pixel x coordinate + \param iy pixel y coordinate + */ + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + + int iroi=getROI(ix,iy); + // if (iroi==0) val=100; + // else val=-100; + // if (isc>=0 && isc=0 && iroi=0 && iroi0) + return mean[iroi]/nCm[iroi]; + } + return 0; + }; + + /** gets the common mode i.e. the difference between the current average sum of pedestals mode and the average pedestal + \param ix pixel x coordinate + \param iy pixel y coordinate + \return the difference between the current average sum of pedestals and the average pedestal + */ + virtual double getCommonModeRMS(int ix=0, int iy=0) { + int iroi=getROI(ix,iy); + if (iroi>=0 && iroi0) + return sqrt(mean2[iroi]/nCm[iroi]-(mean[iroi]/nCm[iroi])*(mean[iroi]/nCm[iroi])); + } + return 0; + }; + + /** + gets the common mode ROI for pixel ix, iy -should be overloaded! + */ + virtual int getROI(int ix, int iy){ (void) ix; (void) iy; return 0;}; + + + + protected: + double *mean; /** { + + + public: + mythen3_01_jctbData( int nch=64*3,int dr=24, int off=5): slsDetectorData(64*3,1,dr*8*nch,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch) {}; + + virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;}; + + virtual short unsigned int getChannel(char *data, int ix, int iy=0) { + int ret=-1; + short unsigned int *val=mythen03_frame(data,dynamicRange,numberOfCounters,serialOffset); + if (ix>=0 && ix=0) frameNumber=f; return frameNumber; }; + virtual int setDynamicRange(int d=-1) {if (d>0 && d<=24) dynamicRange=d; return dynamicRange;}; + virtual int setSerialOffset(int d=-1) {if (d>=0) serialOffset=d; return serialOffset;}; + virtual int setNumberOfCounters(int d=-1) {if (d>=0) numberOfCounters=d; return numberOfCounters;}; + + + private: + + int dynamicRange; + int serialOffset; + int frameNumber; + int numberOfCounters; + + + + +}; + +#endif diff --git a/slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h b/slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h new file mode 100644 index 000000000..a76e2cbaf --- /dev/null +++ b/slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h @@ -0,0 +1,130 @@ +#ifndef MYTHEN302JCTBDATA_H +#define MYTHEN302JCTBDATA_H + + +#include "Mythen3_01_jctbData.h" +//class mythen3_02_jctbData : public slsDetectorData { +class mythen3_02_jctbData : public mythen3_01_jctbData { + + + public: + mythen3_02_jctbData( int nch=64*3,int dr=24, int off=5): mythen3_01_jctbData( nch,dr, off) + //slsDetectorData(64*3,1,dr*8*nch,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch) + {}; + + /* virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;}; */ + + /* virtual short unsigned int getChannel(char *data, int ix, int iy=0) { */ + /* int ret=-1; */ + /* short unsigned int *val=mythen03_frame(data,dynamicRange,numberOfCounters,serialOffset); */ + /* if (ix>=0 && ix=0) frameNumber=f; return frameNumber; }; */ + /* virtual int setDynamicRange(int d=-1) {if (d>0 && d<=24) dynamicRange=d; return dynamicRange;}; */ + /* virtual int setSerialOffset(int d=-1) {if (d>=0) serialOffset=d; return serialOffset;}; */ + /* virtual int setNumberOfCounters(int d=-1) {if (d>=0) numberOfCounters=d; return numberOfCounters;}; */ + + + /* private: */ + + /* int dynamicRange; */ + /* int serialOffset; */ + /* int frameNumber; */ + /* int numberOfCounters; */ + + + + +}; + +#endif diff --git a/slsDetectorCalibration/dataStructures/adcSar2_jctbData.h b/slsDetectorCalibration/dataStructures/adcSar2_jctbData.h new file mode 100644 index 000000000..0b0665aaf --- /dev/null +++ b/slsDetectorCalibration/dataStructures/adcSar2_jctbData.h @@ -0,0 +1,63 @@ +#ifndef ADCSAR2_JCTBDATA_H +#define ADCSAR2_JCTBDATA_H + + +class adcSar2_jctbData : public slsDetectorData { + + + public: + adcSar2_jctbData(int nsamples=1000): slsDetectorData(nsamples,1,nsamples*8,NULL,NULL,NULL){}; + + virtual void getPixel(int ip, int &x, int &y) {x=ip/8; y=1;}; + + virtual short unsigned int getChannel(char *data, int ix, int iy=0) { + int adcvalue=0; + int vv1= *((int16_t*) (data+8*ix)); + int vv2= *((int16_t*) (data+8*ix+2)); + for (int jj=0;jj<8;jj++){ + adcvalue=adcvalue+ (((vv1>>(jj*2)) & 0x1)<<(jj)); + } + for (int jj=0;jj<4;jj++){ + adcvalue=adcvalue+ (((vv2>>(jj*2)) & 0x1)<<(jj+8)); + } + return adcvalue; + }; + + virtual int getFrameNumber(char *buff) {return frameNumber;}; + + virtual char *findNextFrame(char *data, int &ndata, int dsize) { + ndata=dsize; + return data; + } + + virtual char *readNextFrame(ifstream &filebin) { + char *data=NULL; + if (filebin.is_open()) { + data=new char[dataSize]; + filebin.read(data,dataSize); + } + return data; + } + + /* virtual int **getData(char *ptr, int dsize=-1) { */ + /* int **val; */ + /* val=new int*[1]; */ + /* val[0]=mythen03_frame(ptr,dynamicRange,nx,serialOffset); */ + /* return val; */ + + /* } */ + + + + virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; }; + + private: + + int frameNumber; + + + + +}; + +#endif diff --git a/slsDetectorCalibration/dataStructures/chiptestBoardData.h b/slsDetectorCalibration/dataStructures/chiptestBoardData.h new file mode 100644 index 000000000..0ef633c44 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/chiptestBoardData.h @@ -0,0 +1,89 @@ +#ifndef CHIPTESTDATA_H +#define CHIPTESTDATA_H + +#include "slsDetectorData.h" + +class chiptestBoardData : public slsDetectorData { + + + public: + + /** + chiptestBoard data structure. Works for data acquired using the chiptestBoard. + Inherits and implements slsDetectorData. + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param nadc number of adcs + \param offset offset at the beginning of the pattern + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. + + */ + chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; // should be? nadc*(npx*npy+offset) + + + + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + \param buff pointer to the dataset + \returns frame number + + */ + + virtual int getFrameNumber(char *buff){(void)buff; return iframe;}; + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param data pointer to the memory to be analyzed + \param ndata size of frame returned + \param dsize size of the memory slot to be analyzed + \returns always return the pointer to data (no frame loss!) + */ + + virtual char *findNextFrame(char *data, int &ndata, int dsize) {ndata=dsize;setDataSize(dsize); return data;}; + + /** + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete + */ + + virtual char *readNextFrame(ifstream &filebin) { + + int afifo_length=0; + uint16_t *afifo_cont; + + if (filebin.is_open()) { + if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) { + setDataSize(afifo_length*nAdc*sizeof(uint16_t)); + afifo_cont=new uint16_t[afifo_length*nAdc]; + if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) { + iframe++; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } else { + return NULL; + } + } + return NULL; + }; + + private: + const int nAdc; /** + +class deserializer : public slsDetectorData { + + + public: + + + deserializer( std::vector dbl, int nch=64*3,int dr=24, int off=2): slsDetectorData(nch,1,nch*dr*8+off*8,NULL,NULL,NULL), dbitlist(dbl), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch) {}; + + deserializer( std::vector dbl, int nch,int dr, int off, int ds): slsDetectorData(nch,1,ds,NULL,NULL,NULL), dbitlist(dbl), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch) {}; + + virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;}; + + virtual int getChannel(char *data, int ix, int iy=0) { + int ret=-1; + if (ix>=0 && ix dbl, int dr=24, int nch=64*3, int off=5) { + // off=0; + int iarg; + int64_t word, *wp; + int* val=new int[nch]; + int ioff=0; + int idr=0; + int ib=0; + int iw=0; + int ii=0; + int ich; + int nb=dbl.size(); + idr=0; + for (ib=0; ib dbl, int dr=24, int nch=64*3, int off=5) { + // off=0; + int iarg; + int64_t word; + int* val=new int[nch]; + int ioff=0; + int idr=0; + int ib=0; + int iw=0; + int ii=0; + int ich; + int nb=dbl.size(); + + char *dval; + + idr=0; + for (ib=0; ib=dr) { + idr=0; + ich++; + } + } + ii++; + ib++; + }//end for + + + return val; + } + + virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; }; + virtual int setDynamicRange(int d=-1) {if (d>0 && d<=24) dynamicRange=d; return dynamicRange;}; + virtual int setSerialOffset(int d=-1) {if (d>=0) serialOffset=d; return serialOffset;}; + virtual int setNumberOfCounters(int d=-1) {if (d>=0) numberOfCounters=d; return numberOfCounters;}; + virtual std::vector setDBitList(std::vector dbl) {dbitlist=dbl; return dbitlist;}; + virtual std::vector getDBitList() {return dbitlist;}; + + + private: + + int dynamicRange; + int serialOffset; + int frameNumber; + int numberOfCounters; + std::vector dbitlist; + + + +}; + +#endif diff --git a/slsDetectorCalibration/dataStructures/gotthardDoubleModuleDataNew.h b/slsDetectorCalibration/dataStructures/gotthardDoubleModuleDataNew.h new file mode 100644 index 000000000..9cf11c540 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/gotthardDoubleModuleDataNew.h @@ -0,0 +1,172 @@ +#ifndef GOTTHARD2MODULEDATANEW_H +#define GOTTHARD2MODULEDATANEW_H +#include "gotthardModuleDataNew.h" + + + + + + + + +class gotthardDoubleModuleDataNew : public slsDetectorData { + + private: + const int nModules; + const int offset; + int iframe; + + +public: + + + + /** + Implements the slsReceiverData structure for the gotthard read out by a module i.e. using the slsReceiver + (1x1280 pixels, 2 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + gotthardDoubleModuleDataNew(int off=24*2, int nmod=2): slsDetectorData(1280*nmod, 1, nmod*(1280*2+off)), nModules(nmod), offset(off),iframe(0) { + + + + +#ifdef BCHIP074_BCHIP075 + cout << "This is a bchip074-bchip075 system " << endl; +#endif + + + uint16_t **dMask; + int **dMap; + int ix, iy; + int ypixels=1; + int xpixels=1280*nmod; + int imod, ipix; + dMask=new uint16_t*[1]; + dMap=new int*[1]; + dMap[0] = new int[1280*nmod]; + dMask[0] = new uint16_t[1280*nmod]; + + for(int ix=0; ix=128*4 && ibad<128*5) || (ibad>=9*128 && ibad<10*128) || (ibad>=(1280+128*4) && ibad=(1280+128*6))) + dataROIMask[0][ix]=0; +#endif + } + + setDataMap(dMap); + setDataMask(dMask); + + }; + + + /** + + Returns the frame number for the given dataset. + \param buff pointer to the dataset + \returns frame number + + */ + + + int getFrameNumber(char *buff){if (offset>=sizeof(sls_detector_header)) return ((sls_detector_header*)buff)->frameNumber; return iframe;};//*((int*)(buff+5))&0xffffff;}; + + + + /** + gets the packets number (last packet is labelled with 0 and is replaced with 40) + \param buff pointer to the memory + \returns packet number + + */ + + int getPacketNumber(char *buff){if (offset>=sizeof(sls_detector_header))return ((sls_detector_header*)buff)->packetNumber;}; + + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize){ + if (dsize=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, dataSize) ){ + ff=getFrameNumber(data); + np=getPacketNumber(data); + return data; + } + } + return NULL; + + + + }; + + + + +}; + + + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/gotthardShortModuleData.h b/slsDetectorCalibration/dataStructures/gotthardShortModuleData.h new file mode 100644 index 000000000..4d853c7b0 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/gotthardShortModuleData.h @@ -0,0 +1,127 @@ +#ifndef GOTTHARDSHORTMODULEDATA_H +#define GOTTHARDSHORTMODULEDATA_H +#include "slsReceiverData.h" + + + + + + +class gotthardShortModuleData : public slsReceiverData { +public: + + + + + /** + Implements the slsReceiverData structure for the gotthard short read out by a module i.e. using the slsReceiver + (1x256 pixels, 1 packet 256 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + gotthardShortModuleData(double c=0): slsReceiverData(xpixels, ypixels, npackets, buffersize), xtalk(c){ + + uint16_t **dMask; + int **dMap; + int ix, iy; + int offset = 2; + + dMask=new uint16_t*[ypixels]; + dMap=new int*[ypixels]; + for (int i = 0; i < ypixels; i++) { + dMap[i] = new int[xpixels]; + dMask[i] = new uint16_t[xpixels]; + } + + for(ix=0; ix::getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); + }; + + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ + double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ + double getXTalk() {return xtalk;} + + + + + + + +private: + + double xtalk; /** { + + private: + + int iframe; + // int *xmap, *ymap; + int nadc; + int sc_width; + int sc_height; + + int maplength; + + + + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + moench02CtbData(int ns=6400): slsDetectorData(160, 160, ns*2*32, NULL, NULL) , nadc(32), sc_width(40), sc_height(160) { + + + int adc_off[4]={40,0,120,80}; + int adc_nr[4]={8,10,20,22}; + int row, col; + + int isample; + int iadc, iiadc; + int ix, iy; + maplength=this->getDataSize()/2; + //cout << maplength << endl; + + for (iiadc=0; iiadc<4; iiadc++) { + + iadc=adc_nr[iiadc]; + //cout << iiadc << endl; + for (int i=0; i=dataSize) { + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + + } + } + + for (int i=0; i=0){ + xmap[i]=adc_off[iadc]+ix; + ymap[i]=iy; + }else{ + xmap[i]=-1; + ymap[i]=-1; + } + } + iframe=0; + cout << "data struct created" << endl; + }; + + void getPixel(int ip, int &x, int &y) { + if(ip>=0 && ip0) { + iframe++; + //cout << ib/2 << "-" << endl; + //for (int i=0; i { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + moench03CtbData(int ns=5000): slsDetectorData(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) { + + + int row, col; + + int isample; + int iadc; + int ix, iy; + + int adc_nr[32]={200,225,250,275,300,325,350,375,\ + 0,25,50,75,100,125,150,175,\ + 175,150,125,100,75,50,25,0,\ + 375,350,325,300,275,250,225,200}; + + /* int adc_nr[32]={300,325,350,375,300,325,350,375, \ */ + /* 200,225,250,275,200,225,250,275,\ */ + /* 100,125,150,175,100,125,150,175,\ */ + /* 0,25,50,75,0,25,50,75}; */ + + + for (iadc=0; iadc=2*400*400) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + } + for (int i=0; i0) { + iframe++; + // cout << ib << "-" << endl; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } + return NULL; + }; + + + + +}; + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/moench03T1CtbData.h b/slsDetectorCalibration/dataStructures/moench03T1CtbData.h new file mode 100644 index 000000000..4a99d3746 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench03T1CtbData.h @@ -0,0 +1,158 @@ +#ifndef MOENCH03T1CTBDATA_H +#define MOENCH03T1CTBDATA_H +#include "slsDetectorData.h" + + + +class moench03T1CtbData : public slsDetectorData { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + moench03T1CtbData(int ns=5000): slsDetectorData(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) { + + + int adc_nr[32]={300,325,350,375,300,325,350,375, \ + 200,225,250,275,200,225,250,275,\ + 100,125,150,175,100,125,150,175,\ + 0,25,50,75,0,25,50,75}; + + int row, col; + + int isample; + int iadc; + int ix, iy; + + + + + + for (iadc=0; iadc=2*400*400) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + } + int adc4; + for (int i=0; i0) { + iframe++; + // cout << ib << "-" << endl; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } + return NULL; + }; + + + + +}; + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h new file mode 100644 index 000000000..d3a5e55e1 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h @@ -0,0 +1,290 @@ +#ifndef MOENCH03T1RECDATANEW_H +#define MOENCH03T1RECDATANEW_H +#include "slsDetectorData.h" + +//#define VERSION_V2 + /** + @short structure for a Detector Packet or Image Header + @li frameNumber is the frame number + @li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) + @li packetNumber is the packet number + @li bunchId is the bunch id from beamline + @li timestamp is the time stamp with 10 MHz clock + @li modId is the unique module id (unique even for left, right, top, bottom) + @li xCoord is the x coordinate in the complete detector system + @li yCoord is the y coordinate in the complete detector system + @li zCoord is the z coordinate in the complete detector system + @li debug is for debugging purposes + @li roundRNumber is the round robin set number + @li detType is the detector type see :: detectorType + @li version is the version number of this structure format + */ + typedef struct { + uint64_t frameNumber; /**< is the frame number */ + uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */ + uint32_t packetNumber; /**< is the packet number */ + uint64_t bunchId; /**< is the bunch id from beamline */ + uint64_t timestamp; /**< is the time stamp with 10 MHz clock */ + uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */ + uint16_t xCoord; /**< is the x coordinate in the complete detector system */ + uint16_t yCoord; /**< is the y coordinate in the complete detector system */ + uint16_t zCoord; /**< is the z coordinate in the complete detector system */ + uint32_t debug; /**< is for debugging purposes */ + uint16_t roundRNumber; /**< is the round robin set number */ + uint8_t detType; /**< is the detector type see :: detectorType */ + uint8_t version; /**< is the version number of this structure format */ +#ifndef VERSION_V1 + uint64_t packetCaught[8]; /**< is the version number of this structure format */ +#endif + + } sls_detector_header; + + + + +class moench03T1ReceiverDataNew : public slsDetectorData { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + const int nSamples; + + + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(400, 400, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { + + int nadc=32; + int sc_width=25; + int sc_height=200; + + int adc_nr[32]={300,325,350,375,300,325,350,375, \ + 200,225,250,275,200,225,250,275,\ + 100,125,150,175,100,125,150,175,\ + 0,25,50,75,0,25,50,75}; + + int row, col; + + int isample; + int iadc; + int ix, iy; + + int npackets=40; + int i; + int adc4(0); + + for (int ip=0; ip=nSamples*2*32) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + } + } + } + + int ipacket; + int ibyte; + int ii=0; + for (ibyte=0; ibyteframeNumber;};//*((int*)(buff+5))&0xffffff;}; + + /** + + Returns the packet number for the given dataset. purely virtual func + \param buff pointer to the dataset + \returns packet number number + + + + */ + int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;}; + +/* /\** */ + +/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */ +/* \param data pointer to the memory to be analyzed */ +/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */ +/* \param dsize size of the memory slot to be analyzed */ +/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */ + +/* *\/ */ +/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */ + + +/* /\** */ + +/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */ +/* \param filebin input file stream (binary) */ +/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */ + +/* *\/ */ +/* virtual char *readNextFrame(ifstream &filebin){ */ +/* // int afifo_length=0; */ +/* uint16_t *afifo_cont; */ +/* int ib=0; */ +/* if (filebin.is_open()) { */ +/* afifo_cont=new uint16_t[dataSize/2]; */ +/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */ +/* ib+=2; */ +/* if (ib==dataSize) break; */ +/* } */ +/* if (ib>0) { */ +/* iframe++; */ +/* // cout << ib << "-" << endl; */ +/* return (char*)afifo_cont; */ +/* } else { */ +/* delete [] afifo_cont; */ +/* return NULL; */ +/* } */ +/* } */ +/* return NULL; */ +/* }; */ + + + virtual char *readNextFrame(ifstream &filebin) { + int ff=-1, np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int &ff) { + int np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { + char *data=new char[dataSize]; + char *d=readNextFrame(filebin, ff, np, data); + if (d==NULL) {delete [] data; data=NULL;} + return data; + } + + + + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { + char *retval=0; + int nd; + int fnum = -1; + np=0; + int pn; + + // cout << dataSize << endl; + if (ff>=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, dataSize) ){ + ff=getFrameNumber(data); + np=getPacketNumber(data); + return data; + } + } + return NULL; + + + + }; + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize){ + if (dsize { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + const int nSamples; + + + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ +#ifdef HOR + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(800, 200, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { +#endif +#ifdef VERT + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(200, 800, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { +#endif + int nadc=32; + int sc_width=25; + int sc_height=200; + + int adc_nr[32]={300,325,350,375,300,325,350,375, \ + 200,225,250,275,200,225,250,275,\ + 100,125,150,175,100,125,150,175,\ + 0,25,50,75,0,25,50,75}; + + int row, col; + + int isample; + int iadc; + int ix, iy; + + int npackets=40; + int i; + int adc4(0); + int pix; + + + int off=0; +#ifdef OFF_1 + off=1; +#endif + cout << "This is a MOENCH with rectangular pixels!" << endl; + + for (int ip=0; ip=nSamples*2*32+sizeof(sls_detector_header)) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + ix=col; + iy=row; +#ifdef HOR + if (row%2==off) { + ix=2*col; + iy=row/2; + } else { + ix=2*col+1; + iy=row/2; + } +#endif + +#ifdef VERT + if (col%2==off) { + ix=col/2; + iy=row*2+1; + } else { + ix=col/2; + iy=row*2; + } +#endif + dataMap[iy][ix]=pix; + } + } + } + } + + /* int ipacket; */ + /* int ibyte; */ + /* int ii=0; */ + /* for (ibyte=0; ibyteframeNumber;};//*((int*)(buff+5))&0xffffff;}; + + /** + + Returns the packet number for the given dataset. purely virtual func + \param buff pointer to the dataset + \returns packet number number + + + + */ + int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;}; + +/* /\** */ + +/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */ +/* \param data pointer to the memory to be analyzed */ +/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */ +/* \param dsize size of the memory slot to be analyzed */ +/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */ + +/* *\/ */ +/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */ + + +/* /\** */ + +/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */ +/* \param filebin input file stream (binary) */ +/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */ + +/* *\/ */ +/* virtual char *readNextFrame(ifstream &filebin){ */ +/* // int afifo_length=0; */ +/* uint16_t *afifo_cont; */ +/* int ib=0; */ +/* if (filebin.is_open()) { */ +/* afifo_cont=new uint16_t[dataSize/2]; */ +/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */ +/* ib+=2; */ +/* if (ib==dataSize) break; */ +/* } */ +/* if (ib>0) { */ +/* iframe++; */ +/* // cout << ib << "-" << endl; */ +/* return (char*)afifo_cont; */ +/* } else { */ +/* delete [] afifo_cont; */ +/* return NULL; */ +/* } */ +/* } */ +/* return NULL; */ +/* }; */ + + + virtual char *readNextFrame(ifstream &filebin) { + int ff=-1, np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int &ff) { + int np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { + char *data=new char[dataSize]; + char *d=readNextFrame(filebin, ff, np, data); + if (d==NULL) {delete [] data; data=NULL;} + return data; + } + + + + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { + char *retval=0; + int nd; + int fnum = -1; + np=0; + int pn; + + // cout << dataSize << endl; + if (ff>=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, dataSize) ){ + ff=getFrameNumber(data); + np=getPacketNumber(data); + return data; + } + } + return NULL; + + + + }; + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize){ + if (dsize { + + private: + + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + fwrite(&ff, 8, 1,of);//write detector frame number + fwrite(&ifr, 8, 1,of);//write datset frame number + fwrite(data,2,NX*NY,of);//write reordered data + */ + moench03T1ReorderedData(): slsDetectorData(400, 400, 2*400*400+2*8) { + for (int iy=0; iy<400; iy++) + for (int ix=0; ix<400; ix++) + dataMap[iy][ix]=2*8+2*(iy*400+ix); + + int ibyte; + for (ibyte=0; ibyte<8; ibyte++){ + xmap[ibyte]=-1; + ymap[ibyte]=-1; + } + for (ibyte=0; ibyte<400*400; ibyte++){ + xmap[ibyte+8]=ibyte%400; + ymap[ibyte+8]=ibyte/400; + } + + // cout << "data struct created" << endl; + }; + + + + /** + + Returns the frame number for the given dataset. Purely virtual func. + \param buff pointer to the dataset + \returns frame number + + */ + +/* class jfrau_packet_header_t { */ +/* public: */ +/* unsigned char reserved[4]; */ +/* unsigned char packetNumber[1]; */ +/* unsigned char frameNumber[3]; */ +/* unsigned char bunchid[8]; */ +/* }; */ + + + + int getFrameNumber(char *buff){return *((int*)buff);}; + +/* /\** */ + +/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */ +/* \param data pointer to the memory to be analyzed */ +/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */ +/* \param dsize size of the memory slot to be analyzed */ +/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */ + +/* *\/ */ +/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */ + + +/* /\** */ + +/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */ +/* \param filebin input file stream (binary) */ +/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */ + +/* *\/ */ +/* virtual char *readNextFrame(ifstream &filebin){ */ +/* // int afifo_length=0; */ +/* uint16_t *afifo_cont; */ +/* int ib=0; */ +/* if (filebin.is_open()) { */ +/* afifo_cont=new uint16_t[dataSize/2]; */ +/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */ +/* ib+=2; */ +/* if (ib==dataSize) break; */ +/* } */ +/* if (ib>0) { */ +/* iframe++; */ +/* // cout << ib << "-" << endl; */ +/* return (char*)afifo_cont; */ +/* } else { */ +/* delete [] afifo_cont; */ +/* return NULL; */ +/* } */ +/* } */ +/* return NULL; */ +/* }; */ + + + virtual char *readNextFrame(ifstream &filebin) { + int ff=-1, np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int &ff) { + int np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { + char *data=new char[dataSize]; + char *d=readNextFrame(filebin, ff, np, data); + if (d==NULL) {delete [] data; data=NULL;} + return data; + } + + + + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { + char *retval=0; + int nd; + int fnum = -1; + np=0; + int pn; + + if (ff>=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, dataSize) ){ + ff=getFrameNumber(data); + np=40; + return data; + } + } + return NULL; + + + + }; + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize){ + if (dsize { + + private: + + // int iframe; + int nadc; + int sc_width; + int sc_height; + const int nSamples; + const int offset; + + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + moench03T1ZmqDataNew(int ns=5000): slsDetectorData(400, 400, ns*32*2+sizeof(int)), nSamples(ns), offset(sizeof(int)) { + + int nadc=32; + int sc_width=25; + int sc_height=200; + + int adc_nr[32]={300,325,350,375,300,325,350,375, \ + 200,225,250,275,200,225,250,275,\ + 100,125,150,175,100,125,150,175,\ + 0,25,50,75,0,25,50,75}; + + int row, col; + + int isample; + int iadc; + int ix, iy; + + int npackets=40; + int i; + int adc4(0); + + for (int ip=0; ip=dataSize) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + } + } + } + + + int ii=0; + + for (i=0; i< dataSize; i++) { + if (i0) { */ +/* iframe++; */ +/* // cout << ib << "-" << endl; */ +/* return (char*)afifo_cont; */ +/* } else { */ +/* delete [] afifo_cont; */ +/* return NULL; */ +/* } */ +/* } */ +/* return NULL; */ +/* }; */ + + + virtual char *readNextFrame(ifstream &filebin) { + int ff=-1, np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int &ff) { + int np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { + char *data=new char[32*2*nSamples]; + char *d=readNextFrame(filebin, ff, np, data); + if (d==NULL) {delete [] data; data=NULL;} + return data; + } + + + + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { + char *retval=0; + int nd; + int fnum = -1; + np=0; + int pn; + + + if (ff>=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, 32*2*nSamples) ){ + // iframe++; + //ff=iframe; + return data; + } + } + return NULL; + + + + }; + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize){ + if (dsize<32*2*nSamples) ndata=dsize; + else ndata=32*2*nSamples; + return data; + + } + + + + + + + // virtual int setFrameNumber(int ff){iframe=ff}; + + + + + + + + + + +int getPacketNumber(int x, int y) {return 0;}; + +}; + + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/moench03TCtbData.h b/slsDetectorCalibration/dataStructures/moench03TCtbData.h new file mode 100644 index 000000000..5edbdd247 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench03TCtbData.h @@ -0,0 +1,180 @@ +#ifndef MOENCH03TCTBDATA_H +#define MOENCH03TCTBDATA_H +#include "slsDetectorData.h" + + + +class moench03TCtbData : public slsDetectorData { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + moench03TCtbData(int ns=5000): slsDetectorData(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) { + + + int row, col; + + int isample; + int iadc; + int ix, iy; + + + + int adc_nr[32]={300,325,350,375,300,325,350,375, \ + 200,225,250,275,200,225,250,275,\ + 100,125,150,175,100,125,150,175,\ + 0,25,50,75,0,25,50,75}; + + + + /* int adc_nr[32]={200,225,250,275,300,325,350,375,\ */ + /* 0,25,50,75,100,125,150,175,\ */ + /* 175,150,125,100,75,50,25,0,\ */ + /* 375,350,325,300,275,250,225,200}; */ + + + for (iadc=0; iadc=2*400*400) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + } + int adc4; + for (int i=0; i0) { + iframe++; + // cout << ib << "-" << endl; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } + return NULL; + }; + + + + +}; + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h b/slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h new file mode 100644 index 000000000..0ee4c8458 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h @@ -0,0 +1,291 @@ +#ifndef MOENCH04RECDATA_H +#define MOENCH04RECDATA_H +#include "slsDetectorData.h" + +//#define VERSION_V2 + /** + @short structure for a Detector Packet or Image Header + @li frameNumber is the frame number + @li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) + @li packetNumber is the packet number + @li bunchId is the bunch id from beamline + @li timestamp is the time stamp with 10 MHz clock + @li modId is the unique module id (unique even for left, right, top, bottom) + @li xCoord is the x coordinate in the complete detector system + @li yCoord is the y coordinate in the complete detector system + @li zCoord is the z coordinate in the complete detector system + @li debug is for debugging purposes + @li roundRNumber is the round robin set number + @li detType is the detector type see :: detectorType + @li version is the version number of this structure format + */ + typedef struct { + uint64_t frameNumber; /**< is the frame number */ + uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */ + uint32_t packetNumber; /**< is the packet number */ + uint64_t bunchId; /**< is the bunch id from beamline */ + uint64_t timestamp; /**< is the time stamp with 10 MHz clock */ + uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */ + uint16_t xCoord; /**< is the x coordinate in the complete detector system */ + uint16_t yCoord; /**< is the y coordinate in the complete detector system */ + uint16_t zCoord; /**< is the z coordinate in the complete detector system */ + uint32_t debug; /**< is for debugging purposes */ + uint16_t roundRNumber; /**< is the round robin set number */ + uint8_t detType; /**< is the detector type see :: detectorType */ + uint8_t version; /**< is the version number of this structure format */ + uint64_t packetCaught[8]; /**< is the version number of this structure format */ + + } sls_detector_header; + + + + +class moench04CtbReceiverData : public slsDetectorData { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + const int aSamples; + const int dSamples; + + + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + moench04CtbReceiverData(int nas=5000, int nds=0): slsDetectorData(400, 400, nas*2*32+sizeof(sls_detector_header)+nds*8), aSamples(nas), dSamples(nds) { + + int nadc=32; + int sc_width=25; + int sc_height=200; + + int adc_nr[32]={9, 8,11,10,13,12,15,14,1,0,3,2,5,4,7,6,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24 }; + + int row, col; + + int isample; + int iadc; + int ix, iy; + + int npackets=40; + int i; + int adc4(0); + + for (int ip=0; ip0) { + row=199-i/sc_width; + } else { + row=200+i/sc_width; + } + dataMap[row][col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1); + if (dataMap[row][col]<0 || dataMap[row][col]>=aSamples*2*32) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + } + } + } + + int ipacket; + int ibyte; + int ii=0; + for (ibyte=0; ibyteframeNumber;};//*((int*)(buff+5))&0xffffff;}; + + /** + + Returns the packet number for the given dataset. purely virtual func + \param buff pointer to the dataset + \returns packet number number + + + + */ + int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;}; + +/* /\** */ + +/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */ +/* \param data pointer to the memory to be analyzed */ +/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */ +/* \param dsize size of the memory slot to be analyzed */ +/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */ + +/* *\/ */ +/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */ + + +/* /\** */ + +/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */ +/* \param filebin input file stream (binary) */ +/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */ + +/* *\/ */ +/* virtual char *readNextFrame(ifstream &filebin){ */ +/* // int afifo_length=0; */ +/* uint16_t *afifo_cont; */ +/* int ib=0; */ +/* if (filebin.is_open()) { */ +/* afifo_cont=new uint16_t[dataSize/2]; */ +/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */ +/* ib+=2; */ +/* if (ib==dataSize) break; */ +/* } */ +/* if (ib>0) { */ +/* iframe++; */ +/* // cout << ib << "-" << endl; */ +/* return (char*)afifo_cont; */ +/* } else { */ +/* delete [] afifo_cont; */ +/* return NULL; */ +/* } */ +/* } */ +/* return NULL; */ +/* }; */ + + + virtual char *readNextFrame(ifstream &filebin) { + int ff=-1, np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int &ff) { + int np=-1; + return readNextFrame(filebin, ff, np); + }; + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { + char *data=new char[dataSize]; + char *d=readNextFrame(filebin, ff, np, data); + if (d==NULL) {delete [] data; data=NULL;} + return data; + } + + + + + virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { + char *retval=0; + int nd; + int fnum = -1; + np=0; + int pn; + + // cout << dataSize << endl; + if (ff>=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, dataSize) ){ + ff=getFrameNumber(data); + np=getPacketNumber(data); + return data; + } + } + return NULL; + + + + }; + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize){ + if (dsize +#include +#include + +using namespace std; + + +template +class slsDetectorData { + + protected: + const int nx; /**< Number of pixels in the x direction */ + const int ny; /**< Number of pixels in the y direction */ + int dataSize; /**=0 && ix=0 && iy=0 && ix=0 && iydataSize) dsize=dataSize; + for (int ip=0; ip<(dsize/sizeof(dataType)); ip++) { + getPixel(ip,ix,iy); + if (ix>=0 && ix=0 && iydataSize) dsize=dataSize; + for (int ip=0; ip<(dsize/sizeof(dataType)); ip++) { + getPixel(ip,ix,iy); + if (ix>=0 && ix=0 && iy=0 && ix=0 && iy=0 && dataMap[iy][ix] +#include // exit() +template +class slsReceiverData : public slsDetectorData { + + +public: + + /** + slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. + Inherits and implements slsDetectorData. + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param np number of packets + \param psize packets size + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. + + */ + slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; + + + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + \param buff pointer to the dataset + \returns frame number + + */ + + virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; + + /** + + Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. + \param buff pointer to the dataset + \returns packet number number + + */ + + virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;}; + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param data pointer to the memory to be analyzed + \param ndata size of frame returned + \param dsize size of the memory slot to be analyzed + \returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found + + */ + + virtual char *findNextFrame(char *data, int &ndata, int dsize) { + char *retval=NULL, *p=data; + int dd=0; + int fn, fnum=-1, np=0, pnum=-1; + while (dd<=(dsize-packetSize)) { + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + //cout <<"fnum:"<nPackets) { + //cout << "Bad packet number " << pnum << " frame "<< fn << endl; + retval=NULL; + np=0; + } else if (pnum==1) { + retval=p; + if (np>0) + /*cout << "*Incomplete frame number " << fnum << endl;*/ + np=0; + fnum=fn; + } else if (fn!=fnum) { + if (fnum!=-1) { + /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ + retval=NULL; + } + np=0; + } + p+=packetSize; + dd+=packetSize; + np++; + //cout <<"fnum:"<0){ + //cprintf(BG_RED, "Too few packets for this frame! fnum:%d, pnum:%d np:%d\n",fnum,pnum,np); + cout << "Too few packets for this frame! "<< fnum << " " << pnum << " " << np <nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else if (retval!=NULL) { + // cout << "+" << endl;; + for (int ip=0; ipnPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + // cout << "." << endl;; + np++; + } + } + } + delete [] data; + return NULL; + }; + + + /** + + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \param fnum frame number of frame returned + \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete + + */ + + virtual char *readNextFrame(ifstream &filebin, int& fnum) { + char *data=new char[packetSize*nPackets]; + char *retval=0; + int np=0, nd; + fnum = -1; + + if (filebin.is_open()) { + while (filebin.read(data+np*packetSize,packetSize)) { + + if (np==(nPackets-1)) { + + fnum=getFrameNumber(data); //cout << "fnum:"<nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else if (retval!=NULL) { + // cout << "+" << endl;; + for (int ip=0; ipnPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + // cout << "." << endl;; + np++; + //cout<<"np:"<