fixed online event builder, but rebining histogram2D during run will seg fault
This commit is contained in:
parent
d9034fd8b1
commit
21f19b6ff7
10
Analyser.cpp
10
Analyser.cpp
|
@ -51,10 +51,10 @@ void Analyzer::SetUpCanvas(){
|
|||
|
||||
setGeometry(0, 0, 1600, 800);
|
||||
|
||||
h2 = new Histogram2D("testing", "x", "y", 400, 0, 4000, 400, 0, 4000, this);
|
||||
h2 = new Histogram2D("testing", "x", "y", 400, 0, 10000, 400, 0, 10000, this);
|
||||
layout->addWidget(h2, 0, 0);
|
||||
|
||||
h1 = new Histogram1D("testing", "x", 400, 0, 4000, this);
|
||||
h1 = new Histogram1D("testing", "x", 400, 0, 10000, this);
|
||||
layout->addWidget(h1, 0, 1);
|
||||
|
||||
// std::random_device rd;
|
||||
|
@ -74,11 +74,13 @@ void Analyzer::UpdateHistograms(){
|
|||
|
||||
//Set with digitizer to be event build
|
||||
digiMTX[0].lock();
|
||||
oeb[0]->BuildEvents(100, true);
|
||||
oeb[0]->BuildEvents(100, false);
|
||||
digiMTX[0].unlock();
|
||||
|
||||
oeb[0]->PrintStat();
|
||||
|
||||
//============ Get events, and do analysis
|
||||
long eventBuilt = oeb[0]->eventbuilt;
|
||||
long eventBuilt = oeb[0]->eventBuilt;
|
||||
if( eventBuilt == 0 ) return;
|
||||
|
||||
long eventIndex = oeb[0]->eventIndex;
|
||||
|
|
|
@ -283,7 +283,7 @@ inline void Data::PrintAllData(bool tableMode) const{
|
|||
if( DataIndex[ch] > MaxEntry ) MaxEntry = DataIndex[ch];
|
||||
}
|
||||
if( DataIndex[ch] < 0 ) continue;
|
||||
printf(" %5s-%02d,%-9d |", "ch", ch, DataIndex[ch]);
|
||||
printf(" %5s-%02d,%2d,%-6d |", "ch", ch, LoopIndex[ch], DataIndex[ch]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
|
|
@ -766,7 +766,7 @@ void MainWindow::UpdateScalar(){
|
|||
if( scalar == nullptr ) return;
|
||||
//if( !scalar->isVisible() ) return;
|
||||
|
||||
digi[0]->GetData()->PrintAllData();
|
||||
// digi[0]->GetData()->PrintAllData();
|
||||
|
||||
lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));
|
||||
|
||||
|
|
|
@ -12,15 +12,16 @@ OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){
|
|||
|
||||
OnlineEventBuilder::~OnlineEventBuilder(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::ClearEvents(){
|
||||
eventIndex = -1;
|
||||
totalEventBuilt = 0;
|
||||
for( int i = 0; i < MaxNEvent; i++ ) events[i].clear();
|
||||
|
||||
for( int i = 0; i < MaxNChannels; i++ ){
|
||||
nextIndex[i] = -1;
|
||||
loopIndex[i] = 0;
|
||||
chExhaused[i] = false;
|
||||
}
|
||||
|
||||
|
@ -30,6 +31,11 @@ void OnlineEventBuilder::ClearEvents(){
|
|||
nExhaushedCh = 0;
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::PrintStat(){
|
||||
|
||||
printf("========= Total Event built : %lu, last built : %lu, index: %lu \n", totalEventBuilt, eventBuilt, eventIndex);
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::FindEarlistTimeAndCh(){
|
||||
|
||||
earlistTime = -1;
|
||||
|
@ -41,7 +47,7 @@ void OnlineEventBuilder::FindEarlistTimeAndCh(){
|
|||
}
|
||||
|
||||
for(unsigned int ch = 0; ch < nCh; ch ++){
|
||||
if( data->DataIndex[ch] == -1 || nextIndex[ch] > data->DataIndex[ch]) {
|
||||
if( data->DataIndex[ch] == -1 || loopIndex[ch] * MaxNData + nextIndex[ch] > data->LoopIndex[ch] * MaxNData + data->DataIndex[ch]) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[ch] = true;
|
||||
continue;
|
||||
|
@ -57,50 +63,51 @@ void OnlineEventBuilder::FindEarlistTimeAndCh(){
|
|||
}
|
||||
}
|
||||
|
||||
// printf("%s | ch : %d, %llu\n", __func__, earlistCh, earlistTime);
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::FindLatestTime(){
|
||||
latestTime = 0;
|
||||
// int latestCh = -1;
|
||||
for( unsigned ch = 0; ch < nCh; ch++ ){
|
||||
int index = data->DataIndex[ch];
|
||||
if( index == -1 ) continue;
|
||||
if( data->Timestamp[ch][index] > latestTime ) {
|
||||
latestTime = data->Timestamp[ch][index];
|
||||
//latestCh = ch;
|
||||
}
|
||||
}
|
||||
//printf("--- latest time %lld \n", latestTime);
|
||||
// printf("%s | ch : %d, %lld \n", __func__, latestCh, latestTime);
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
|
||||
|
||||
this->timeWindow = timeWindow;
|
||||
if( verbose ) data->PrintAllData();
|
||||
|
||||
FindLatestTime();
|
||||
FindEarlistTimeAndCh();
|
||||
|
||||
if( earlistCh == -1 || nExhaushedCh == nCh) return; /// no data
|
||||
|
||||
eventbuilt = 0;
|
||||
|
||||
data->PrintAllData();
|
||||
eventBuilt = 0;
|
||||
|
||||
//======= Start building event
|
||||
do{
|
||||
|
||||
eventIndex ++;
|
||||
if( eventIndex >= MaxNEvent ) eventIndex = 0;
|
||||
|
||||
events[eventIndex].clear();
|
||||
|
||||
eventbuilt ++;
|
||||
|
||||
unsigned long long dT =0;
|
||||
eventBuilt ++;
|
||||
totalEventBuilt ++;
|
||||
|
||||
unsigned long long dT = 0;
|
||||
dataPoint dp = {0, 0, 0};
|
||||
for( unsigned int i = 0; i < nCh; i++){
|
||||
int ch = (i + earlistCh ) % nCh;
|
||||
//printf("------ %d | %d | %d | %d\n", ch, data->DataIndex[ch], nextIndex[ch], chExhaused[ch]);
|
||||
if( chExhaused[ch] ) continue;
|
||||
if( nextIndex[ch] > data->DataIndex[ch]) {
|
||||
if( loopIndex[ch] * MaxNData + nextIndex[ch] > data->LoopIndex[ch] * MaxNData + data->DataIndex[ch]) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[ch] = true;
|
||||
continue;
|
||||
|
@ -117,7 +124,10 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
|
|||
|
||||
events[eventIndex].push_back(dp);
|
||||
nextIndex[ch]++;
|
||||
if( nextIndex[ch] >= MaxNData) nextIndex[ch] = 0;
|
||||
if( nextIndex[ch] >= MaxNData) {
|
||||
loopIndex[ch] ++;
|
||||
nextIndex[ch] = 0;
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
|
@ -134,7 +144,7 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
|
|||
FindEarlistTimeAndCh();
|
||||
|
||||
if( verbose ){
|
||||
printf(">>>>>>>>>>>>>>>>>>>>>>>>> Event ID : %ld, multiplicity : %ld\n", eventIndex, events[eventIndex].size());
|
||||
printf(">>>>>>>>>>>>>>>>> Event ID : %ld, total built: %ld, multiplicity : %ld\n", eventIndex, totalEventBuilt, events[eventIndex].size());
|
||||
for( int i = 0; i <(int) events[eventIndex].size(); i++){
|
||||
int chxxx = events[eventIndex][i].ch;
|
||||
printf("%02d | %d | %5d %llu \n", chxxx, nextIndex[chxxx], events[eventIndex][i].energy, events[eventIndex][i].timeStamp);
|
||||
|
|
|
@ -32,17 +32,21 @@ public:
|
|||
void BuildEvents(unsigned short timeWindow, bool verbose = false);
|
||||
|
||||
long eventIndex;
|
||||
long eventbuilt;
|
||||
long eventBuilt; // reset once call BuildEvents()
|
||||
long totalEventBuilt;
|
||||
std::vector<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy
|
||||
|
||||
unsigned short GetTimeWindow() const { return timeWindow;}
|
||||
|
||||
void PrintStat();
|
||||
|
||||
private:
|
||||
|
||||
unsigned short nCh;
|
||||
Data * data;
|
||||
|
||||
unsigned short timeWindow;
|
||||
int loopIndex[MaxNChannels];
|
||||
int nextIndex[MaxNChannels];
|
||||
|
||||
int nExhaushedCh;
|
||||
|
|
14
test.cpp
14
test.cpp
|
@ -56,19 +56,19 @@ int main(int argc, char* argv[]){
|
|||
|
||||
dig[0]->StartACQ();
|
||||
|
||||
for( int i = 0; i < 3; i ++ ){
|
||||
usleep(100*1000);
|
||||
for( int i = 0; i < 9; i ++ ){
|
||||
usleep(1000*1000);
|
||||
dig[0]->ReadData();
|
||||
data->DecodeBuffer(false, 1);
|
||||
data->PrintStat();
|
||||
data->DecodeBuffer(false, 0);
|
||||
//data->PrintStat();
|
||||
|
||||
data->SaveData();
|
||||
//data->SaveData();
|
||||
|
||||
// int index = data->NumEventsDecoded[0];
|
||||
// printf("-------------- %ld \n", data->Waveform1[0][index].size());
|
||||
|
||||
data->PrintAllData();
|
||||
eb->BuildEvents(100);
|
||||
//data->PrintAllData();
|
||||
eb->BuildEvents(100, false);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user