various bug fix

This commit is contained in:
Ryan Tang 2022-12-20 17:46:39 -05:00
parent 9e11e8f613
commit e4aca6af42
8 changed files with 330 additions and 276 deletions

View File

@ -285,7 +285,6 @@ void Pixie16::CheckHardware(){
void Pixie16::GetDigitizerInfo(unsigned short modID){
//retval = Pixie16ReadModuleInfo(modID, &ModRev, &ModSerNum, &ModADCBits, &ModADCMSPS, &numChannels);
retval = Pixie16ReadModuleInfo(modID, &ModRev[modID], &ModSerNum[modID], &ModADCBits[modID], &ModADCMSPS[modID], &numChannels[modID]);
@ -317,6 +316,20 @@ void Pixie16::BootDigitizers(){
printf("\033[32mBooting module ...\033[0m\n");
for( int i = 0 ; i < NumModules; i++){
fifo_worker_config worker_config;
retval = PixieGetWorkerConfiguration(i, &worker_config);
if( CheckError("PixieGetWorkerConfiguration") < 0 ) return ;
printf("Getting FIFO worker information for modulus %d", i);
std::cout << "Bandwidth (MB/sec): " << worker_config.bandwidth_mb_per_sec << std::endl;
std::cout << "Buffers : " << worker_config.buffers << std::endl;
std::cout << "DMA Trigger Level (B): " << worker_config.dma_trigger_level_bytes << std::endl;
std::cout << "Hold (usec): " << worker_config.hold_usecs << std::endl;
std::cout << "Idle wait (usec): " << worker_config.idle_wait_usecs << std::endl;
std::cout << "Run wait (usec): " << worker_config.run_wait_usecs << std::endl;
std::cout << "End List-Mode FIFO worker information for Module " << i << std::endl;
GetDigitizerInfo(i);
retval = Pixie16BootModule (
@ -386,6 +399,15 @@ void Pixie16::StartRun(bool listMode){
totNumFIFOWords = 0;
AccumulatedFIFONumDataBlock = 0;
nextWord = 0;
int synch_wait = 0;
int in_synch = 0;
retval = Pixie16WriteSglModPar("SYNCH_WAIT", synch_wait, 0);
if( CheckError("Pixie16StartListModeRun") < 0 ) return;
retval = Pixie16WriteSglModPar("IN_SYNCH", in_synch, 0);
if( CheckError("Pixie16StartListModeRun") < 0 ) return;
retval = Pixie16StartListModeRun(NumModules, LIST_MODE_RUN, mode);
if( CheckError("Pixie16StartListModeRun") < 0 ) return;
printf("\033[32m LIST_MODE run\033[0m\n");
@ -438,27 +460,69 @@ void Pixie16::ReadData(unsigned short modID){
}
}
void Pixie16::ClearFIFOData(){
FIFONumDataBlock = 0;
nextWord = 0;
delete FIFOEnergies;
delete FIFOChannels;
delete FIFOMods;
delete FIFOTimestamps;
FIFOEnergies = new unsigned short[MAXFIFODATABLOCK];
FIFOChannels = new unsigned short[MAXFIFODATABLOCK];
FIFOMods = new unsigned short[MAXFIFODATABLOCK];
FIFOTimestamps = new unsigned long long[MAXFIFODATABLOCK];
}
void Pixie16::PrintExtFIFOWords() {
unsigned int nWords = (ExtFIFO_Data[nextWord] >> 17) & 0x3FFF;
printf("------------------- print dataBlock, nWords = %d\n", nWords);
int count = 0;
for( unsigned int i = nextWord; i < nextWord + nWords + 10 ; i++){
if( i == nextWord + nWords ) printf("===== end of dataBlock\n");
if( count % 4 == 3 ){
printf("%08X \n", ExtFIFO_Data[i]);
}else{
printf("%08X ", ExtFIFO_Data[i]);
}
count ++;
}
printf("\n------------------- \n");
}
unsigned int Pixie16::ScanNumDataBlockInExtFIFO(){
unsigned int nextWordtemp = nextWord;
///if( nextWordtemp < nFIFOWords ) printf("============= FIFOWord : %u \n", nFIFOWords);
//if( nextWordtemp < nFIFOWords ) {
// printf("============= FIFOWord : %u \n", nFIFOWords);
// PrintExtFIFOWords();
//}
while( nextWordtemp < nFIFOWords ){
unsigned short eventLen = (ExtFIFO_Data[nextWordtemp] >> 17) & 0x3FFF;
uint32_t haha = ExtFIFO_Data[nextWordtemp];
unsigned short eventLen = (haha >> 17) & 0x3FFF;
FIFOChannels[FIFONumDataBlock] = (haha & 0xF );
FIFOMods[FIFONumDataBlock] = ((haha >> 4) & 0xF) - 2;
FIFOEnergies[FIFONumDataBlock] = (ExtFIFO_Data[nextWordtemp + 3] & 0xFFFF );
FIFOChannels[FIFONumDataBlock] = (ExtFIFO_Data[nextWordtemp] & 0xF );
FIFOMods[FIFONumDataBlock] = ((ExtFIFO_Data[nextWordtemp] >> 4) & 0xF) - 2;
FIFOTimestamps[FIFONumDataBlock] = ((unsigned long long)(ExtFIFO_Data[nextWordtemp+2] & 0xFFFF) << 32) + ExtFIFO_Data[nextWordtemp+1];
nextWordtemp += eventLen;
///printf("%u | nextWordtemp %u, nextWord %u, ch %u, energy %u \n", FIFONumDataBlock, nextWordtemp, nextWord, FIFOChannels[FIFONumDataBlock], FIFOEnergies[FIFONumDataBlock]);
nextWordtemp += eventLen;
//printf("%u | nextWordtemp %u, nextWord %u, eventLen: %u, ch %u, energy %u, time : %llu \n", FIFONumDataBlock, nextWordtemp, nextWord, eventLen,
// FIFOChannels[FIFONumDataBlock],
// FIFOEnergies[FIFONumDataBlock],
// FIFOTimestamps[FIFONumDataBlock]);
FIFONumDataBlock ++;
if (FIFONumDataBlock > MAXFIFODATABLOCK ) break;
}
nextWord = nextWordtemp - nFIFOWords ;
AccumulatedFIFONumDataBlock += FIFONumDataBlock;
//printf("FIFONumDataBlock : %u, %u \n", FIFONumDataBlock, AccumulatedFIFONumDataBlock);
return FIFONumDataBlock;
}
@ -784,6 +848,7 @@ void Pixie16::PrintStatistics(unsigned short modID){
GetStatitics(modID);
if( retval >= 0 ){
double realTime = Pixie16ComputeRealTime (Statistics, modID);
printf("===================================== statistics based on digitizer.\n");
printf(" Real (or RUN) Time : %9.3f sec \n", realTime);
printf(" ch | live time (sec) | input count rate | output count rate | trigger | events \n");
printf("-----+-----------------+------------------+-------------------+---------+--------\n");
@ -831,6 +896,16 @@ double Pixie16::GetRealTime(unsigned short modID){
return Pixie16ComputeRealTime (statistics, modID);
}
void Pixie16::LoadSettings(std::string fileName){
retval = Pixie16LoadDSPParametersFromFile((char*) fileName.c_str());
if( CheckError("Pixie16SaveDSPParametersToFile") < 0 ) {
return;
}else{
printf("loaded setting from %s\n", fileName.c_str());
}
}
void Pixie16::SaveSettings(std::string fileName){
retval = Pixie16SaveDSPParametersToFile((char *)fileName.c_str());

View File

@ -6,7 +6,7 @@
#include "pixie16/pixie16.h"
#include "DataBlock.h"
#define MAXFIFODATABLOCK 1000 ///max FIFO Datablack for one read
#define MAXFIFODATABLOCK 10000 ///max FIFO Datablack for one read
enum CSRA_BIT{
FAST_TRIGGER = 0x00000001,
@ -167,7 +167,6 @@ public:
void PrintChannelAllSettings(unsigned short modID, unsigned short ch);
void PrintChannelSettingsSummary(unsigned short modID);
void SetChannelSetting(std::string parName, double val, unsigned short modID, unsigned short ch, bool verbose = false);
void SetChannelTriggerRiseTime (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("TRIGGER_RISETIME", val, modID, ch, 1);}
void SetChannelTriggerFlatTop (double val, unsigned short modID, unsigned short ch){ SetChannelSetting("TRIGGER_FLATTOP", val, modID, ch, 1);}
@ -189,6 +188,8 @@ public:
void SetChannelGain(bool high, unsigned short modID, unsigned short ch) { SetCSRABit(CSRA_BIT::INPUT_RELAY, high, modID, ch); }
void SetChannelQDCsumOnOff(bool high, unsigned short modID, unsigned short ch) { SetCSRABit(CSRA_BIT::ENABLE_QDC, high, modID, ch); }
///========================== Setting file;
void LoadSettings(std::string fileName);
void SaveSettings(std::string fileName);
///========================== RUN
@ -204,7 +205,7 @@ public:
void PrintStatistics(unsigned short modID);
void CheckExternalFIFOWords(unsigned short modID);
void ReadData(unsigned short modID);
void ReadData(unsigned short modID); // this will reset the FIFONumDataBlock;
unsigned int GetTotalNumWords() {return totNumFIFOWords;}
unsigned int GetnFIFOWords() {return nFIFOWords;}
@ -219,26 +220,13 @@ public:
unsigned short * GetFIFOChannels() {return FIFOChannels;}
unsigned short * GetFIFOMods() {return FIFOMods;}
unsigned long long * GetFIFOTimestamps() {return FIFOTimestamps;}
void ClearFIFOData();
/// FIFOisUsed is not used in this Class, it is for sync in thread
void SetFIFOisUsed(bool isUsed) {this->FIFOisUsed = isUsed;};
bool GetFIFOisUsed() {return FIFOisUsed;}
void PrintExtFIFOWords() {
unsigned int nWords = (ExtFIFO_Data[nextWord] >> 17) & 0x3FFF;
printf("------------------- print dataBlock, nWords = %d\n", nWords);
int count = 0;
for( unsigned int i = nextWord; i < nextWord + nWords + 10 ; i++){
if( i == nextWord + nWords ) printf("===== end of dataBlock\n");
if( count % 4 == 3 ){
printf("%08X \n", ExtFIFO_Data[i]);
}else{
printf("%08X ", ExtFIFO_Data[i]);
}
count ++;
}
printf("\n------------------- \n");
}
void PrintExtFIFOWords();
void OpenFile(std::string fileName, bool append);
void SaveData();

View File

@ -425,6 +425,7 @@ void MainWindow::Scope(){
usleep(runDuration*1000);
pixie->ReadData(0);
pixie->StopRun();
pixie->PrintStatistics(modID);
delete gTrace;
@ -461,6 +462,7 @@ void MainWindow::Scope(){
}
}
///printf("=============== finished \n");
}
@ -573,8 +575,8 @@ void MainWindow::StartRun(){
}
}
TString cmd = Form("/home/tandem/PixieDAQ/elogEntry.sh %d %d \"%s\"", 1, (int) runIDEntry->GetIntNumber(), StartStopDialog::Comment.Data() );
int temp = system(cmd.Data());
//TString cmd = Form("/home/tandem/PixieDAQ/elogEntry.sh %d %d \"%s\"", 1, (int) runIDEntry->GetIntNumber(), StartStopDialog::Comment.Data() );
//int temp = system(cmd.Data());
pixie->StartRun(1);
if( pixie->IsRunning() ) saveDataThread->Run(); /// call SaveData()
@ -609,8 +611,8 @@ void MainWindow::StopRun(){
bStopRun->SetEnabled(false);
bFitTrace->SetEnabled(true);
TString cmd = Form("/home/tandem/PixieDAQ/elogEntry.sh %d %d \"%s\"", 0, (int)runIDEntry->GetIntNumber(), StartStopDialog::Comment.Data() );
int temp = system(cmd.Data());
//TString cmd = Form("/home/tandem/PixieDAQ/elogEntry.sh %d %d \"%s\"", 0, (int)runIDEntry->GetIntNumber(), StartStopDialog::Comment.Data() );
//int temp = system(cmd.Data());
runIDEntry->SetIntNumber(runIDEntry->GetIntNumber()+1);
}
@ -674,7 +676,7 @@ void * MainWindow::SaveData(void* ptr){
localClock.Reset();
localClock.Start("timer");
int pauseTime = 10 ; ///msec
int pauseTime = 1 ; ///msec
while( pixie->IsRunning() ){
@ -687,8 +689,8 @@ void * MainWindow::SaveData(void* ptr){
if( pixie->GetnFIFOWords() > 0 ) {
pixie->SaveData();
///ScanNumDataBlockInExtFIFO() should be here after ReadData(). becasue not a whlole dataBlock is in FIFO.
pixie->ScanNumDataBlockInExtFIFO(); //TODO need to check the time comsumtion
pixie->SetFIFOisUsed(false);
///pixie->ScanNumDataBlockInExtFIFO(); //TODO need to check the time comsumtion
///pixie->SetFIFOisUsed(false);
localClock.Stop("timer");
newTime = localClock.GetRealTime("timer"); /// sec

View File

@ -418,8 +418,6 @@ void SettingsSummary::OpenFile(){
}
void SettingsSummary::SaveSetting(){
printf("save button is pressed.\n");
pixie->SaveSettings(settingFileName.Data());
teFileName->SetText(settingFileName + " (saved)");
}

View File

@ -4,20 +4,20 @@
"input": {
"BLcut": [
90,
1,
1,
31,
120,
43,
8,
32,
6,
306,
0,
0,
4,
1,
1,
0,
4,
6,
2,
0,
16,
107,
1,
1,
0,
0,
2
],
"BaselinePercent": [
@ -93,22 +93,22 @@
120
],
"ChanCSRa": [
18592,
16544,
16544,
16544,
132,
132,
16544,
16544,
16544,
132,
16544,
16544,
16544,
16544,
16544,
16544
18564,
16516,
16516,
16516,
16772,
16772,
16772,
16772,
16772,
16772,
16772,
16772,
16772,
16772,
16772,
16772
],
"ChanCSRb": [
0,
@ -255,22 +255,22 @@
10
],
"FastThresh": [
2000,
65535,
65535,
65535,
40000,
40000,
4000,
65535,
4000,
40000,
65535,
65535,
4000,
65535,
65535,
65535
4000,
4000,
4000,
4000,
4000,
4000,
4000,
4000,
4000,
4000,
4000,
4000,
4000
],
"FastTrigBackLen": [
10,
@ -419,38 +419,38 @@
"OffsetDAC": [
21845,
32768,
32768,
32768,
48059,
48059,
48059,
48059,
21845,
32768,
48059,
21845,
50244,
32768,
32768,
48059,
21845,
32768,
32768,
32768
48059
],
"PAFlength": [
1018,
1768,
1768,
1768,
1268,
1018,
666,
1768,
1018,
1018,
1792,
1768,
1768,
1768,
1768,
1768
893,
893,
893,
893,
893,
893,
893,
893,
893,
893,
893,
893,
893,
893,
893,
893
],
"PSAlength": [
0,
@ -495,11 +495,11 @@
95,
95,
95,
51,
95,
95,
95,
98,
95,
95,
95,
95,
95,
@ -513,11 +513,11 @@
97,
97,
97,
53,
97,
97,
97,
100,
97,
97,
97,
97,
97,
@ -526,21 +526,21 @@
],
"PreampTau": [
1112014848,
1100456650,
1100456650,
1100456650,
1095552204,
1095552204,
1112012226,
1100456650,
1112014848,
1112014848,
1100428083,
1100456650,
1112014848,
1100456650,
1100456650,
1100456650
1112014848,
1112014848,
1112014848,
1112014848,
1112014848,
1112014848,
1112014848,
1112014848,
1112014848,
1112014848,
1112014848,
1112014848
],
"QDCLen0": [
30,
@ -715,7 +715,7 @@
19,
19,
19,
22,
19,
19,
19,
19,
@ -729,7 +729,7 @@
78,
78,
78,
34,
78,
78,
78,
78,
@ -759,22 +759,22 @@
0
],
"TraceLength": [
5000,
5000,
5000,
5000,
5000,
5000,
2504,
5000,
3750,
5000,
5000,
5000,
5000,
5000,
5000,
5000
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250,
1250
],
"TrigOutLen": [
0,
@ -801,11 +801,11 @@
768,
768,
768,
416,
768,
768,
768,
792,
768,
768,
768,
768,
768,

View File

@ -2,4 +2,4 @@
rm -f Pixie16Msg.log
./testing/example $1 --config=testing/example_config.json
./example $1 --config=example_config.json

View File

@ -1,14 +1,14 @@
[
{
"slot": 2,
"slot": 9,
"dsp": {
"ldr": "/usr/opt/Pixie16/pixie16_revf_general_12b250m_41847_2019-05-18/dsp/Pixie16DSP_revfgeneral_12b250m_r41847.ldr",
"ldr": "/home/ryan/Pixie16/GUI/firmware/pixie16_revf_general_12b250m_41847_2019-05-18/dsp/Pixie16DSP_revfgeneral_12b250m_r41847.ldr",
"par": "/home/ryan/Pixie16/GUI/test_ryan.set",
"var": "/usr/opt/Pixie16/pixie16_revf_general_12b250m_41847_2019-05-18/dsp/Pixie16DSP_revfgeneral_12b250m_r41847.var"
"var": "/home/ryan/Pixie16/GUI/firmware/pixie16_revf_general_12b250m_41847_2019-05-18/dsp/Pixie16DSP_revfgeneral_12b250m_r41847.var"
},
"fpga": {
"fippi": "/usr/opt/Pixie16/pixie16_revf_general_12b250m_41847_2019-05-18/firmware/fippixie16_revfgeneral_12b250m_r42081.bin",
"sys": "/usr/opt/Pixie16/pixie16_revf_general_12b250m_41847_2019-05-18/firmware/syspixie16_revfgeneral_adc250mhz_r33339.bin",
"fippi": "/home/ryan/Pixie16/GUI/firmware/pixie16_revf_general_12b250m_41847_2019-05-18/firmware/fippixie16_revfgeneral_12b250m_r42081.bin",
"sys": "/home/ryan/Pixie16/GUI/firmware/pixie16_revf_general_12b250m_41847_2019-05-18/firmware/syspixie16_revfgeneral_adc250mhz_r33339.bin",
"trig": "FPGATrig"
}
}

View File

@ -5,7 +5,6 @@
#include <unistd.h>
#include <sys/stat.h>
#include <bitset>
#include <unistd.h>
#include <limits.h>
#include <ctime>
#include <sys/time.h> /* struct timeval, select() */
@ -35,12 +34,14 @@
#include <thread>
#include <unistd.h>
#include "evtReader.h"
long get_time();
void ProcessData(); // using evtReader.h
void FillHistograms(uint32_t period = 500);
void PrintCommands();
void GetADCTrace(int ch);
void GetBaseline(int ch);
bool QuitFlag = false;
@ -48,8 +49,126 @@ Pixie16 * pixie = 0;
TGraph * gTrace = 0;
TCanvas * canvas = 0;
TH1F * hch = 0;
TH1F * hE = 0;
TH1F * hE[16] = {0};
int ch2ns;
uint32_t StartTime = 0, CurrentTime =0 ;
uint32_t ElapsedTime = 0, PresenTime = 0;
///##################################################
int main(int argc, char *argv[]){
printf("Removing Pixie16Msg.log \n");
remove( "Pixie16Msg.log");
//============= Root things
TApplication * app = new TApplication("app", &argc, argv);
canvas = new TCanvas("canvas", "Canvas", 1600, 2000);
canvas->Divide(4,5);
hch = new TH1F("hch", "channel", 16, 0, 16);
for( int i = 0; i < 16 ; i ++){
hE[i] = new TH1F(Form("hE%02d",i), Form("energy-%02d", i), 400, 0, 30000);
}
gTrace = new TGraph();
//=========================== open pixie digitizer
pixie = new Pixie16();
if ( pixie->GetStatus() < 0 ) {
printf("Exiting program... \n");
return 0;
}
ch2ns = pixie->GetCh2ns(0);
gTrace->GetXaxis()->SetTitle("time [ns]");
pixie->PrintDigitizerSettings(0);
double time = 1.0; ///sec
pixie->PrintChannelSettingsSummary(0);
pixie->OpenFile("haha.evt", false);
pixie->ClearFIFOData();
//=========================== Start run loop
printf("start run for %f sec\n", time);
StartTime = get_time(), CurrentTime = get_time();
ElapsedTime = 0, PresenTime = StartTime;
pixie->StartRun(1);
while( CurrentTime - StartTime < time * 1000 ){
pixie->ReadData(0); // this will reset the FIFONumDataBlock;
if( pixie->GetnFIFOWords() > 0 ) {
pixie->SaveData();
FillHistograms();
}
CurrentTime = get_time();
ElapsedTime = CurrentTime - PresenTime;
}
pixie->StopRun();
pixie->ReadData(0);
if( pixie->GetnFIFOWords() > 0 ) pixie->SaveData();
pixie->CloseFile();
FillHistograms(0);
pixie->PrintStatistics(0);
unsigned int haha = pixie->GetTotalNumWords();
unsigned int kaka = pixie->GetAccumulatedFIFONumDataBlock();
printf("=========== total nFIFO words : %d (%d) \n", haha, kaka);
app->Run();
printf("================ end of program. \n");
return 0;
}
///##################################################
void FillHistograms(uint32_t period){
unsigned int nData = pixie->ScanNumDataBlockInExtFIFO();
unsigned short * energies = pixie->GetFIFOEnergies();
unsigned short * channels = pixie->GetFIFOChannels();
//unsigned long long * timestamps = pixie->GetFIFOTimestamps();
for( unsigned int h = 0; h < nData; h++) {
//printf(" %3u| %8u, %8u , %20llu\n", h, channels[h], energies[h], timestamps[h]);
hch->Fill(channels[h] );
hE[channels[h]]->Fill( energies[h] );
}
if( ElapsedTime > period ) {
pixie->PrintStatistics(0);
PresenTime = CurrentTime;
ElapsedTime = 0;
for( int i = 0; i < 16; i++){
canvas->cd(i+1); hE[i]->Draw();
}
canvas->cd(17); hch->Draw();
canvas->Modified();
canvas->Update();
gSystem->ProcessEvents();
}
}
long get_time(){
long time_ms;
struct timeval t1;
struct timezone tz;
gettimeofday(&t1, &tz);
time_ms = (t1.tv_sec) * 1000 + t1.tv_usec / 1000;
return time_ms;
}
void PrintCommands(){
@ -115,7 +234,7 @@ void ProcessData(){
//data->Print(0);
hch->Fill( data->ch);
hE->Fill( data->energy );
hE[data->ch]->Fill( data->energy );
if( data->eventID %100 == 0 ){
if( data->trace_length > 0 ) {
@ -128,9 +247,8 @@ void ProcessData(){
}
if( data->eventID %200 == 0 ){
//data->Print(0);
canvas->cd(1); hch->Draw();
canvas->cd(2); hE->Draw();
canvas->cd(17); hch->Draw();
for( int i = 0; i < 16; i++) {canvas->cd(i+1); hE[i]->Draw();}
canvas->Modified();
canvas->Update();
gSystem->ProcessEvents();
@ -149,137 +267,10 @@ void ProcessData(){
}
printf("========= finished ProcessData()\n");
canvas->cd(1); hch->Draw();
canvas->cd(2); hE->Draw();
canvas->cd(17); hch->Draw();
for( int i = 0; i < 16; i++) {canvas->cd(i+1); hE[i]->Draw();}
canvas->Modified();
canvas->Update();
gSystem->ProcessEvents();
}
///##################################################
int main(int argc, char *argv[]){
printf("Removing Pixie16Msg.log \n");
remove( "Pixie16Msg.log");
pixie = new Pixie16();
if ( pixie->GetStatus() < 0 ) {
QuitFlag = true;
printf("Exiting program... \n");
return 0;
}
TApplication * app = new TApplication("app", &argc, argv);
canvas = new TCanvas("canvas", "Canvas", 1800, 400);
canvas->Divide(3,1);
hch = new TH1F("hch", "channel", 16, 0, 16);
hE = new TH1F("hE", "energy", 400, 0, 30000);
gTrace = new TGraph();
ch2ns = pixie->GetCh2ns(0);
gTrace->GetXaxis()->SetTitle("time [ns]");
pixie->PrintDigitizerSettings(0);
int ch = 6;
double time = 1.0; ///sec
pixie->PrintChannelAllSettings(0, ch);
pixie->PrintChannelSettingsSummary(0);
pixie->OpenFile("haha.evt", false);
printf("start run for %f sec\n", time);
uint32_t StartTime = get_time(), CurrentTime = get_time();
uint32_t ElapsedTime = 0, PresenTime = StartTime;
pixie->StartRun(1);
///std::thread kakakaka(ProcessData);
while( CurrentTime - StartTime < time * 1000 ){
pixie->ReadData(0);
if( pixie->GetnFIFOWords() > 0 ) pixie->SaveData();
//if( pixie->GetnFIFOWords() > 0 ) {/// msec
// printf("number of dataBlack read : %u\n", pixie->ScanNumDataBlockInExtFIFO());
//}
//TODO a quick way to read and fill histogram; the most time consumping part is filling trace
unsigned int nData = pixie->ScanNumDataBlockInExtFIFO();
unsigned short * energies = pixie->GetFIFOEnergies();
unsigned short * channels = pixie->GetFIFOChannels();
//unsigned long long * timestamps = pixie->GetFIFOTimestamps();
for( unsigned int h = 0; h < nData; h++) {
//printf(" %3u| %8u, %8u , %20llu\n", h, channels[h], energies[h], timestamps[h]);
hch->Fill(channels[h] );
hE->Fill( energies[h] );
}
if( ElapsedTime > 500 ) {
pixie->PrintStatistics(0);
PresenTime = CurrentTime;
ElapsedTime = 0;
canvas->cd(1); hch->Draw();
canvas->cd(2); hE->Draw();
canvas->Modified();
canvas->Update();
gSystem->ProcessEvents();
}
CurrentTime = get_time();
ElapsedTime = CurrentTime - PresenTime;
}
pixie->StopRun();
pixie->CloseFile();
unsigned int nData = pixie->ScanNumDataBlockInExtFIFO();
unsigned short * energies = pixie->GetFIFOEnergies();
unsigned short * channels = pixie->GetFIFOChannels();
for( unsigned int h = 0; h < nData; h++) {
//printf(" %3u| %8u, %8u , %20llu\n", h, channels[h], energies[h], timestamps[h]);
hch->Fill(channels[h] );
hE->Fill( energies[h] );
}
canvas->cd(1); hch->Draw();
canvas->cd(2); hE->Draw();
canvas->Modified();
canvas->Update();
gSystem->ProcessEvents();
printf("===================================\n");
pixie->PrintStatistics(0);
unsigned int haha = pixie->GetTotalNumWords();
printf("=========== total nFIFO words : %d (%f) \n", haha, haha/1256.);
app->Run();
QuitFlag = true;
printf("================ end of program. \n");
return 0;
}
///##################################################
long get_time(){
long time_ms;
struct timeval t1;
struct timezone tz;
gettimeofday(&t1, &tz);
time_ms = (t1.tv_sec) * 1000 + t1.tv_usec / 1000;
return time_ms;
}