added backward builder in MultiBuilder
This commit is contained in:
parent
8daeb362c5
commit
33e2a7ee56
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,6 +7,7 @@ test_indep
|
|||
programSettings.txt
|
||||
EventKenshikushi
|
||||
DataGenerator
|
||||
DataReaderScript
|
||||
|
||||
data
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#include "ClassData.h"
|
||||
#include "MultiBuilder.h"
|
||||
|
||||
|
||||
void DataReaderScript(){
|
||||
|
||||
Data * data = new Data();
|
||||
data->DPPType = V1730_DPP_PSD_CODE;
|
||||
|
||||
std::string fileName = "temp_030_089_PSD_000.fsu";
|
||||
std::string fileName = "data/temp_030_089_PSD_000.fsu";
|
||||
|
||||
FILE * haha = fopen(fileName.c_str(), "r");
|
||||
fseek(haha, 0L, SEEK_END);
|
||||
|
@ -15,6 +17,8 @@ void DataReaderScript(){
|
|||
|
||||
fseek(haha, 0, SEEK_SET);
|
||||
|
||||
MultiBuilder * mb = new MultiBuilder(data, V1730_DPP_PSD_CODE);
|
||||
|
||||
char * buffer = nullptr;
|
||||
int countBdAgg = 0;
|
||||
|
||||
|
@ -23,37 +27,52 @@ void DataReaderScript(){
|
|||
long fPos1 = ftell(haha);
|
||||
|
||||
unsigned int word[1]; /// 4 bytes
|
||||
size_t dump = fread(word, 4, 1, haha);
|
||||
size_t dummy = fread(word, 4, 1, haha);
|
||||
fseek(haha, -4, SEEK_CUR);
|
||||
short header = ((word[0] >> 28 ) & 0xF);
|
||||
if( header != 0xA ) break;
|
||||
|
||||
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
||||
buffer = new char[aggSize];
|
||||
dump = fread(buffer, aggSize, 1, haha);
|
||||
dummy = fread(buffer, aggSize, 1, haha);
|
||||
if( dummy != 1) printf("fread error, should read 4 bytes, but read %ld x 4 byte\n", dummy);
|
||||
|
||||
long fPos2 = ftell(haha);
|
||||
|
||||
countBdAgg ++;
|
||||
//printf("Board Agg. has %d word = %d bytes | %ld - %ld\n", aggSize/4, aggSize, fPos1, fPos2);
|
||||
//printf("==================== %d Agg\n", countBdAgg);
|
||||
printf("Board Agg. has %d word = %d bytes | %ld - %ld\n", aggSize/4, aggSize, fPos1, fPos2);
|
||||
printf("==================== %d Agg\n", countBdAgg);
|
||||
|
||||
data->DecodeBuffer(buffer, aggSize, false, 0); // data own the buffer
|
||||
data->ClearBuffer(); // this will clear the buffer.
|
||||
|
||||
if( !data->IsNotRollOverFakeAgg ) continue;
|
||||
|
||||
//if( countBdAgg % 100 == 0) data->PrintStat();
|
||||
//data->ClearData();
|
||||
|
||||
// if( countBdAgg > 10 ) break;
|
||||
if( countBdAgg > 10 ){
|
||||
data->PrintAllData();
|
||||
mb->BuildEventsBackWard(false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}while(!feof(haha) && ftell(haha) < inFileSize);
|
||||
|
||||
data->PrintAllData();
|
||||
data->PrintStat();
|
||||
|
||||
fclose(haha);
|
||||
|
||||
mb->PrintStat();
|
||||
|
||||
delete mb;
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
DataReaderScript();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
|
@ -170,7 +170,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
|
||||
//*====================================== build events
|
||||
MultiBuilder * mb = new MultiBuilder(data, typeList);
|
||||
MultiBuilder * mb = new MultiBuilder(data, typeList, snList);
|
||||
mb->SetTimeWindow(timeWindow);
|
||||
|
||||
///------------------ re data
|
||||
|
|
|
@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs`
|
|||
|
||||
OBJS = ClassDigitizer.o MultiBuilder.o
|
||||
|
||||
ALL = test test_indep DataGenerator EventKenshikushi
|
||||
ALL = test test_indep DataGenerator EventKenshikushi DataReaderScript
|
||||
|
||||
#########################################################################
|
||||
|
||||
|
@ -41,6 +41,10 @@ DataGenerator : DataGenerator.cpp ClassDigitizer.o
|
|||
@echo "--------- making DataGenerator"
|
||||
$(CC) $(COPTS) -o DataGenerator DataGenerator.cpp ClassDigitizer.o $(CAENLIBS)
|
||||
|
||||
DataReaderScript : DataReaderScript.cpp ClassData.h MultiBuilder.o
|
||||
@echo "--------- making DataReaderScript"
|
||||
$(CC) $(COPTS) -o DataReaderScript DataReaderScript.cpp ClassData.h MultiBuilder.o $(CAENLIBS)
|
||||
|
||||
EventKenshikushi : EventKenshikushi.cpp ClassData.h MultiBuilder.o
|
||||
@echo "--------- making EventKenshikushi"
|
||||
$(CC) $(COPTS) -o EventKenshikushi EventKenshikushi.cpp MultiBuilder.o $(CAENLIBS) $(ROOTLIBS)
|
|
@ -21,6 +21,7 @@ MultiBuilder::MultiBuilder(Digitizer ** digi, std::vector<int> id) : nData(id.si
|
|||
for( unsigned int i = 0; i < nData; i++){
|
||||
int k = idList[i];
|
||||
data[i] = digi[k]->GetData();
|
||||
//TODO type and sn should be inside data[i]
|
||||
typeList.push_back(digi[k]->GetDPPType());
|
||||
snList.push_back(digi[k]->GetSerialNumber());
|
||||
timeWindow = 100;
|
||||
|
@ -28,8 +29,8 @@ MultiBuilder::MultiBuilder(Digitizer ** digi, std::vector<int> id) : nData(id.si
|
|||
}
|
||||
}
|
||||
|
||||
MultiBuilder::MultiBuilder(Data ** inData, std::vector<int> type, std::vector<int> sn) : nData(type.size()){
|
||||
data = inData;
|
||||
MultiBuilder::MultiBuilder(Data ** multiData, std::vector<int> type, std::vector<int> sn) : nData(type.size()){
|
||||
data = multiData;
|
||||
typeList = type;
|
||||
snList = sn;
|
||||
for( int i = 0; i < (int) type.size(); i++) idList.push_back(i);
|
||||
|
@ -57,6 +58,16 @@ MultiBuilder::MultiBuilder(Digitizer * digi) : nData(1){
|
|||
ClearEvents();
|
||||
}
|
||||
|
||||
MultiBuilder::MultiBuilder(Data * singleData, int type): nData(1){
|
||||
data = new Data *[1];
|
||||
data[0] = singleData;
|
||||
typeList.push_back(type);
|
||||
snList.push_back(0);
|
||||
idList.push_back(0);
|
||||
timeWindow = 100;
|
||||
ClearEvents();
|
||||
}
|
||||
|
||||
MultiBuilder::~MultiBuilder(){
|
||||
|
||||
}
|
||||
|
@ -83,6 +94,17 @@ void MultiBuilder::ClearEvents(){
|
|||
}
|
||||
}
|
||||
|
||||
void MultiBuilder::PrintStat(){
|
||||
|
||||
printf("Total number of evet built : %ld\n", totalEventBuilt);
|
||||
for( int i = 0; i < nData ; i++){
|
||||
for( int ch = 0; ch < MaxNChannels ; ch++){
|
||||
printf("%d %d | %d \n", i, ch, nextIndex[i][ch]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
|
||||
|
||||
earlistTime = -1;
|
||||
|
@ -134,15 +156,17 @@ void MultiBuilder::FindLatestTimeAndCh(bool verbose){
|
|||
}
|
||||
|
||||
for(unsigned int ch = 0; ch < MaxNChannels; ch ++){
|
||||
if( data[i]->Timestamp[ch][data[i]->DataIndex[ch]] == 0 || data[i]->DataIndex[ch] == -1 ) {
|
||||
// printf(" %d, %d | %d", i, ch, nextIndex[i][ch]);
|
||||
if( nextIndex[i][ch] < 0 ) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[i][ch] = true;
|
||||
|
||||
// printf(", exhanshed. %d \n", nExhaushedCh);
|
||||
continue;
|
||||
}else{
|
||||
nextIndex[i][ch] = data[i]->DataIndex[ch];
|
||||
}
|
||||
|
||||
unsigned long long time = data[i]->Timestamp[ch][nextIndex[i][ch]];
|
||||
// printf(", time : %llu\n", time );
|
||||
if( time > latestTime ) {
|
||||
latestTime = time;
|
||||
latestDigi = i;
|
||||
|
@ -272,6 +296,13 @@ void MultiBuilder::BuildEventsBackWard(bool verbose){
|
|||
|
||||
//skip trace, and only build for 100 events max
|
||||
|
||||
// remember the end of DataIndex, prevent over build
|
||||
for( int k = 0; k < nData; k++){
|
||||
for( int i = 0; i < MaxNChannels; i++){
|
||||
nextIndex[k][i] = data[k]->DataIndex[i];
|
||||
}
|
||||
}
|
||||
|
||||
FindLatestTimeAndCh(verbose);
|
||||
|
||||
//========== build event
|
||||
|
@ -290,7 +321,8 @@ void MultiBuilder::BuildEventsBackWard(bool verbose){
|
|||
for( unsigned int i = 0; i < MaxNChannels; i++){
|
||||
int ch = (i + latestCh) % MaxNChannels;
|
||||
if( chExhaused[k][ch] ) continue;
|
||||
if( nextIndex[k][ch] <= lastBackWardIndex[k][ch] ){
|
||||
//if( nextIndex[k][ch] <= lastBackWardIndex[k][ch] || nextIndex[k][ch] < 0){
|
||||
if( nextIndex[k][ch] < 0){
|
||||
chExhaused[k][ch] = true;
|
||||
nExhaushedCh ++;
|
||||
continue;
|
||||
|
@ -309,7 +341,7 @@ void MultiBuilder::BuildEventsBackWard(bool verbose){
|
|||
|
||||
events[eventIndex].push_back(em);
|
||||
nextIndex[k][ch]--;
|
||||
if( nextIndex[k][ch] < 0) nextIndex[k][ch] = MaxNData - 1;
|
||||
if( nextIndex[k][ch] < 0 && data[k]->LoopIndex[ch] > 0 ) nextIndex[k][ch] = MaxNData - 1;
|
||||
|
||||
}else{
|
||||
break;
|
||||
|
@ -321,7 +353,9 @@ void MultiBuilder::BuildEventsBackWard(bool verbose){
|
|||
if( timeWindow == 0 ) break;
|
||||
}
|
||||
|
||||
//skip sorting by timestamp
|
||||
std::sort(events[eventIndex].begin(), events[eventIndex].end(), [](const EventMember& a, const EventMember& b) {
|
||||
return a.timestamp < b.timestamp;
|
||||
});
|
||||
|
||||
FindLatestTimeAndCh(verbose);
|
||||
|
||||
|
@ -337,17 +371,17 @@ void MultiBuilder::BuildEventsBackWard(bool verbose){
|
|||
printf("######################### no more event to be built\n");
|
||||
break;
|
||||
}
|
||||
printf("----- next ch : %d, next earlist Time : %llu.\n", earlistCh, earlistTime);
|
||||
printf("----- next ch : %d, next latest Time : %llu.\n", latestCh, latestTime);
|
||||
|
||||
}
|
||||
|
||||
}while(nExhaushedCh < nData * MaxNChannels || eventBuilt > 100);
|
||||
}while(nExhaushedCh < nData * MaxNChannels && eventBuilt < 100);
|
||||
|
||||
// remember the end of DataIndex, prevent over build
|
||||
for( int k = 0; k < nData; k++){
|
||||
for( int i = 0; i < MaxNChannels; i++){
|
||||
lastBackWardIndex[k][i] = data[k]->DataIndex[i];
|
||||
}
|
||||
}
|
||||
// // remember the end of DataIndex, prevent over build
|
||||
// for( int k = 0; k < nData; k++){
|
||||
// for( int i = 0; i < MaxNChannels; i++){
|
||||
// lastBackWardIndex[k][i] = data[k]->DataIndex[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -41,11 +41,12 @@ class MultiBuilder {
|
|||
public:
|
||||
MultiBuilder(Digitizer ** digi, unsigned int nDigi);
|
||||
MultiBuilder(Digitizer ** digi, std::vector<int> id);
|
||||
MultiBuilder(Data ** inData, std::vector<int> type, std::vector<int> sn);
|
||||
MultiBuilder(Data ** multiData, std::vector<int> type, std::vector<int> sn);
|
||||
|
||||
//for signal digitizer
|
||||
MultiBuilder(Digitizer ** digi, int digiID);
|
||||
MultiBuilder(Digitizer * digi);
|
||||
MultiBuilder(Data * singleData, int type);
|
||||
~MultiBuilder();
|
||||
|
||||
void SetTimeWindow(int ticks) {timeWindow = ticks;}
|
||||
|
@ -58,7 +59,7 @@ public:
|
|||
void BuildEventsBackWard(bool verbose = false); // always skip trace, for faster online building
|
||||
|
||||
void ClearEvents();
|
||||
// void PrintStat();
|
||||
void PrintStat();
|
||||
|
||||
long eventIndex;
|
||||
long eventBuilt; // reset once call BuildEvents()
|
||||
|
|
Loading…
Reference in New Issue
Block a user