use quick sort in pxi-fsu-time-sort. 4 times slower

This commit is contained in:
Ryan Tang 2022-02-10 13:45:05 -05:00
parent 5d5047b972
commit d34cd5c771
2 changed files with 372 additions and 208 deletions

View File

@ -44,15 +44,22 @@
#define M2_SUB_EVENTS 5000 #define M2_SUB_EVENTS 5000
#define M3_SUB_EVENTS 20000 #define M3_SUB_EVENTS 20000
#define M4_SUB_EVENTS 50000 #define M4_SUB_EVENTS 50000
#define M5_SUB_EVENTS 100000 #define M5_SUB_EVENTS 100000
#define MAX_SUB_EVENTS 200000 #define MAX_SUB_EVENTS 200000
#define MAX_MALLOC 4000*1024*1024L //2GB #define MAX_MALLOC 4000*1024*1024L //2GB
#define MAXLONGLONGINT 9223372036854775807
//TODO change to load file
#include "../mapping.h"
struct subevent struct subevent
{ {
long long int timestamp; long long int timestamp;
int length; //unit = words with 4 bytes per word int length; //unit = words with 4 bytes per word
int detID;
unsigned int *data; unsigned int *data;
}; };
@ -61,6 +68,44 @@ int nevts[MAX_ID], iptr[MAX_ID];
int maxevts[MAX_ID]; int maxevts[MAX_ID];
void swap64(long long int * a, long long int *b){
long long int t = *a;
*a = *b;
*b = t;
}
void swapInt(int * a, int *b){
int t = *a;
*a = *b;
*b = t;
}
int partition(long long int arr[], int index [], int low, int high){
long long int pivot = arr[high];
int i = (low -1);
for(int j = low; j <= high -1 ; j++){
if( arr[j] < pivot ){
i++;
swap64(&arr[i], &arr[j]);
swapInt(&index[i], &index[j]);
}
}
swap64(&arr[i+1], &arr[high]);
swapInt(&index[i+1], &index[high]);
return i+1;
}
void quickSort(long long int arr[], int index[], int low, int high){
if (low < high){
int pi = partition(arr, index, low, high);
quickSort(arr, index, low, pi - 1);
quickSort(arr, index, pi + 1, high);
}
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
FILE *fpr, *fpw; FILE *fpr, *fpw;
@ -73,6 +118,7 @@ int main(int argc, char **argv) {
int pause=0; int pause=0;
long long int nwords=0, evts_tot_read=0, evts_tot_write=0; long long int nwords=0, evts_tot_read=0, evts_tot_write=0;
long long int evts_tot_drop = 0;
long long int time=0,time_old=0; long long int time=0,time_old=0;
int length=0; int length=0;
@ -91,11 +137,13 @@ int main(int argc, char **argv) {
int min_id = -1; int min_id = -1;
memset(nevts, 0, sizeof(nevts)); memset(nevts, 0, sizeof(nevts));
memset(iptr, 0, sizeof(iptr)); memset(iptr, 0, sizeof(iptr)); /// index of time
long long int timeIndex[MAX_ID];
int index[MAX_ID];
int fillSize = 0;
int i=0, j=0; int i=0, j=0;
div_t e_div;
//open input event file //open input event file
if ((fpr = fopen(argv[1], "r")) == NULL) { if ((fpr = fopen(argv[1], "r")) == NULL) {
@ -114,6 +162,14 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
printf("open : \033[1;31m%s\033[m\n", argv[1]);
printf("save : \033[1;34m%s\033[m\n", filenameto);
int eventWindow = 0;
if( argc >= 3 ) eventWindow = atoi(argv[2]);
printf(" event build time window : %d ticks = %d ns \n", eventWindow, 10* eventWindow);
//check for lockfile, active PID, and event file for auto "online" mode detection //check for lockfile, active PID, and event file for auto "online" mode detection
FILE *FPLOCK; FILE *FPLOCK;
@ -143,15 +199,11 @@ int main(int argc, char **argv) {
fgets(line, 1024, FPPATH); //need second line fgets(line, 1024, FPPATH); //need second line
sscanf(line,"%s\n", onlinefile); sscanf(line,"%s\n", onlinefile);
fclose(FPPATH); fclose(FPPATH);
if (filename == NULL) { if (filename == NULL) {
if (strcmp(onlinefile,argv[1]) == 0) { if (strcmp(onlinefile,argv[1]) == 0) online = 1;
online = 1; }else {
} if (strcmp(onlinefile,filename+1) == 0) online = 1;
}else { }
if (strcmp(onlinefile,filename+1) == 0) {
online = 1;
}
}
} }
} }
} }
@ -164,11 +216,8 @@ int main(int argc, char **argv) {
fprsize = fprsize_orig = ftell(fpr); fprsize = fprsize_orig = ftell(fpr);
fseek(fpr, fprpos, SEEK_SET); fseek(fpr, fprpos, SEEK_SET);
//Get memory for default number of subevents per channel id //Get memory for default number of subevents per channel id
for (i=0; i<MAX_ID; i++){ for (i=0; i < MAX_ID; i++){
subevents[i] = (struct subevent *) malloc(sizeof(struct subevent)*DEF_SUB_EVENTS); subevents[i] = (struct subevent *) malloc(sizeof(struct subevent)*DEF_SUB_EVENTS);
if (subevents[i] == NULL) { if (subevents[i] == NULL) {
printf("malloc failed\n"); printf("malloc failed\n");
@ -180,69 +229,71 @@ int main(int argc, char **argv) {
subevents[i][j].data = NULL; subevents[i][j].data = NULL;
subevents[i][j].length = 0; subevents[i][j].length = 0;
subevents[i][j].timestamp = 0; subevents[i][j].timestamp = 0;
subevents[i][j].detID = -1;
} }
} }
int count = 0;
int debugCount = 0;
printf("Static Memory = %ld KB (cf. MAX_ID=%d)\n", sizeof(subevents)/1024, MAX_ID); printf("Static Memory = %ld KB (cf. MAX_ID=%d)\n", sizeof(subevents)/1024, MAX_ID);
while (1) { //main while loop while (1) { //main while loop
///////// /////////
while (1) { //fill buffers until (A) maxevents or (maxevents and 2GB) is reached for any ID while (1) { //fill buffers until (A) maxevents or (maxevents and 2GB) is reached for any ID
//(B) EOF // (B) EOF
//(C) auto online mode will wait for updates and break out of fill buffers for narrow time window // (C) auto online mode will wait for updates and break out of fill buffers for narrow time window
//read 4-byte header // read 4-byte header
if (pause == 1) { if (pause == 1) {
pause = 0; pause = 0;
} }else {
else {
////////////// //////////////
//auto online //auto online
while ( (fprsize - nwords*sizeof(int) < MAX_SUB_LENGTH*sizeof(int)) && online == 1) { while ( (fprsize - nwords*sizeof(int) < MAX_SUB_LENGTH*sizeof(int)) && online == 1) {
online = 0; online = 0;
usleep(100000); //wait 0.1 seconds before checking (prevents excessive cpu usage) usleep(100000); //wait 0.1 seconds before checking (prevents excessive cpu usage)
//check new file size //check new file size
fprpos = ftell(fpr); fprpos = ftell(fpr);
fseek(fpr, 0L, SEEK_END); fseek(fpr, 0L, SEEK_END);
fprsize = ftell(fpr); fprsize = ftell(fpr);
fseek(fpr, fprpos, SEEK_SET); fseek(fpr, fprpos, SEEK_SET);
//check for lock file and active PID //check for lock file and active PID
FPLOCK = fopen(lockfile, "r"); FPLOCK = fopen(lockfile, "r");
if (FPLOCK != NULL) { if (FPLOCK != NULL) {
fscanf(FPLOCK, "%d", &lockpid); fscanf(FPLOCK, "%d", &lockpid);
fclose(FPLOCK); fclose(FPLOCK);
if (getpgid(lockpid) >= 0) { if (getpgid(lockpid) >= 0) {
FPPATH = fopen(pathfile, "r"); FPPATH = fopen(pathfile, "r");
if (FPPATH != NULL) { if (FPPATH != NULL) {
fgets(line, 1024, FPPATH); //skip first line fgets(line, 1024, FPPATH); //skip first line
fgets(line, 1024, FPPATH); //need second line fgets(line, 1024, FPPATH); //need second line
sscanf(line,"%s\n", onlinefile); sscanf(line,"%s\n", onlinefile);
fclose(FPPATH); fclose(FPPATH);
if (filename == NULL) { if (filename == NULL) {
if (strcmp(onlinefile,argv[1]) == 0) online = 1; if (strcmp(onlinefile,argv[1]) == 0) online = 1;
} }else {
else { if (strcmp(onlinefile,filename+1) == 0) online = 1;
if (strcmp(onlinefile,filename+1) == 0) online = 1; }
} }
} }
} }
} } //end auto online
} //end auto online
//read 4-byte header //read 4-byte header
if (fread(subhead, sizeof(subhead), 1, fpr) != 1) break; if (fread(subhead, sizeof(subhead), 1, fpr) != 1) break;
nwords = nwords + HEADER_LENGTH; nwords = nwords + HEADER_LENGTH;
chn = subhead[0] & 0xF; chn = subhead[0] & 0xF;
sln = (subhead[0] & 0xF0) >> 4; sln = (subhead[0] & 0xF0) >> 4;
crn = (subhead[0] & 0xF00) >> 8; crn = (subhead[0] & 0xF00) >> 8;
id = crn*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (sln-BOARD_START)*MAX_CHANNELS_PER_BOARD + chn; id = crn*MAX_BOARDS_PER_CRATE*MAX_CHANNELS_PER_BOARD + (sln-BOARD_START)*MAX_CHANNELS_PER_BOARD + chn;
length = (subhead[0] & 0x7FFE0000) >> 17; //unit = words with 4 bytes per word length = (subhead[0] & 0x7FFE0000) >> 17; //unit = words with 4 bytes per word
time = ( (long long int)(subhead[2] & 0xFFFF) << 32) + subhead[1]; time = ( (long long int)(subhead[2] & 0xFFFF) << 32) + subhead[1];
if (id > idmax) idmax = id; if (id > idmax) idmax = id;
} }
@ -252,53 +303,56 @@ int main(int argc, char **argv) {
//Expand memory for more events (careful when final is to left of initial in circular buffer) //Expand memory for more events (careful when final is to left of initial in circular buffer)
if ( maxevts[id] - nevts[id] == 1 && totmem < MAX_MALLOC) { if ( maxevts[id] - nevts[id] == 1 && totmem < MAX_MALLOC) {
if (maxevts[id] == DEF_SUB_EVENTS) {evts_old = DEF_SUB_EVENTS; evts_new = M1_SUB_EVENTS;} if (maxevts[id] == DEF_SUB_EVENTS) {evts_old = DEF_SUB_EVENTS; evts_new = M1_SUB_EVENTS;}
if (maxevts[id] == M1_SUB_EVENTS) {evts_old = M1_SUB_EVENTS; evts_new = M2_SUB_EVENTS;} if (maxevts[id] == M1_SUB_EVENTS) {evts_old = M1_SUB_EVENTS; evts_new = M2_SUB_EVENTS;}
if (maxevts[id] == M2_SUB_EVENTS) {evts_old = M2_SUB_EVENTS; evts_new = M3_SUB_EVENTS;} if (maxevts[id] == M2_SUB_EVENTS) {evts_old = M2_SUB_EVENTS; evts_new = M3_SUB_EVENTS;}
if (maxevts[id] == M3_SUB_EVENTS) {evts_old = M3_SUB_EVENTS; evts_new = M4_SUB_EVENTS;} if (maxevts[id] == M3_SUB_EVENTS) {evts_old = M3_SUB_EVENTS; evts_new = M4_SUB_EVENTS;}
if (maxevts[id] == M4_SUB_EVENTS) {evts_old = M4_SUB_EVENTS; evts_new = M5_SUB_EVENTS;} if (maxevts[id] == M4_SUB_EVENTS) {evts_old = M4_SUB_EVENTS; evts_new = M5_SUB_EVENTS;}
if (maxevts[id] == M5_SUB_EVENTS) {evts_old = M5_SUB_EVENTS; evts_new = MAX_SUB_EVENTS;} if (maxevts[id] == M5_SUB_EVENTS) {evts_old = M5_SUB_EVENTS; evts_new = MAX_SUB_EVENTS;}
if (maxevts[id]==evts_old && totmem + (evts_new-evts_old)*(sizeof(struct subevent) + sizeof(unsigned int)*length) < MAX_MALLOC) { if (maxevts[id]==evts_old && totmem + (evts_new-evts_old)*(sizeof(struct subevent) + sizeof(unsigned int)*length) < MAX_MALLOC) {
subevents[id] = (struct subevent *) realloc(subevents[id], sizeof(struct subevent)*evts_new); subevents[id] = (struct subevent *) realloc(subevents[id], sizeof(struct subevent)*evts_new);
if (subevents[id] == NULL) { if (subevents[id] == NULL) {
printf("realloc failed\n"); printf("realloc failed\n");
return -1; return -1;
} }
totmem = totmem - sizeof(struct subevent)*evts_old + sizeof(struct subevent)*evts_new; totmem = totmem - sizeof(struct subevent)*evts_old + sizeof(struct subevent)*evts_new;
maxevts[id] = evts_new; maxevts[id] = evts_new;
for (j=evts_old; j<evts_new; j++) { for (j=evts_old; j<evts_new; j++) {
subevents[id][j].data = NULL; subevents[id][j].data = NULL;
subevents[id][j].length = 0; subevents[id][j].length = 0;
subevents[id][j].timestamp = 0; subevents[id][j].timestamp = 0;
} subevents[id][j].detID = -1;
}
// if circular buffer is wrapped around (i.e., final is to left of intial, move data to right of initial) // if circular buffer is wrapped around (i.e., final is to left of intial, move data to right of initial)
if (iptr[id] + nevts[id] > evts_old) { if (iptr[id] + nevts[id] > evts_old) {
for (j=0; j<iptr[id] + nevts[id] - evts_old; j++) { for (j=0; j<iptr[id] + nevts[id] - evts_old; j++) {
if (subevents[id][evts_old+j].data == NULL) { if (subevents[id][evts_old+j].data == NULL) {
subevents[id][evts_old+j].data = (unsigned int *) malloc(sizeof(unsigned int)*subevents[id][j].length); subevents[id][evts_old+j].data = (unsigned int *) malloc(sizeof(unsigned int)*subevents[id][j].length);
if (subevents[id][evts_old+j].data == NULL) { if (subevents[id][evts_old+j].data == NULL) {
printf("malloc failed\n"); printf("malloc failed\n");
return -1; return -1;
} }
totmem += sizeof(unsigned int)*subevents[id][j].length; totmem += sizeof(unsigned int)*subevents[id][j].length;
} }
subevents[id][evts_old+j].length = subevents[id][j].length; subevents[id][evts_old+j].length = subevents[id][j].length;
subevents[id][evts_old+j].timestamp = subevents[id][j].timestamp; subevents[id][evts_old+j].timestamp = subevents[id][j].timestamp;
for (i=0; i<subevents[id][evts_old+j].length; i++) { subevents[id][evts_old+j].detID = subevents[id][j].detID;
subevents[id][evts_old+j].data[i]=subevents[id][j].data[i]; for (i=0; i<subevents[id][evts_old+j].length; i++) {
} subevents[id][evts_old+j].data[i]=subevents[id][j].data[i];
//free data memory until it's needed again }
free(subevents[id][j].data); //free data memory until it's needed again
subevents[id][j].data = NULL; free(subevents[id][j].data);
totmem -= sizeof(unsigned int)*subevents[id][j].length; subevents[id][j].data = NULL;
subevents[id][j].length = 0; totmem -= sizeof(unsigned int)*subevents[id][j].length;
subevents[id][j].timestamp = 0; subevents[id][j].length = 0;
} subevents[id][j].timestamp = 0;
} subevents[id][j].detID = -1;
}
}
} }
} }
@ -309,102 +363,181 @@ int main(int argc, char **argv) {
//fill buffers until full (online mode will stop filling buffers after 2.5 sec lag betweeen output/input) //fill buffers until full (online mode will stop filling buffers after 2.5 sec lag betweeen output/input)
if ( nevts[id] < maxevts[id] && ( (time - time_old)/10000000 < 25 || online == 0 ) ) { if ( nevts[id] < maxevts[id] && ( (time - time_old)/10000000 < 25 || online == 0 ) ) {
j = nevts[id] + iptr[id];
if (j >= maxevts[id]) j -= maxevts[id];
subevents[id][j].timestamp = time;
subevents[id][j].detID = mapping[id];
j = nevts[id] + iptr[id]; if (subevents[id][j].data == NULL) {
if (j >= maxevts[id]) j -= maxevts[id]; subevents[id][j].data = (unsigned int *) malloc(sizeof(unsigned int)*length);
if (subevents[id][j].data == NULL) {
printf("malloc failed\n");
return -1;
}
totmem += sizeof(unsigned int)*length;
}else if (length != subevents[id][j].length) { //not needed anymore since always free data after use now. Keep for future ...
subevents[id][j].data = (unsigned int *) realloc(subevents[id][j].data, sizeof(unsigned int)*length);
if (subevents[id][j].data == NULL) {
printf("realloc failed\n");
return -1;
}
totmem = totmem - sizeof(unsigned int)*subevents[id][j].length + sizeof(unsigned int)*length;
}
subevents[id][j].timestamp = time; subevents[id][j].length = length;
if (subevents[id][j].data == NULL) { if (length>HEADER_LENGTH) {
subevents[id][j].data = (unsigned int *) malloc(sizeof(unsigned int)*length); if (fread(subevents[id][j].data + HEADER_LENGTH, (length-HEADER_LENGTH)*sizeof(int), 1, fpr) != 1) break;
if (subevents[id][j].data == NULL) { nwords = nwords + (length-HEADER_LENGTH);
printf("malloc failed\n"); }
return -1;
}
totmem += sizeof(unsigned int)*length;
}
else if (length != subevents[id][j].length) { //not needed anymore since always free data after use now. Keep for future ...
subevents[id][j].data = (unsigned int *) realloc(subevents[id][j].data, sizeof(unsigned int)*length);
if (subevents[id][j].data == NULL) {
printf("realloc failed\n");
return -1;
}
totmem = totmem - sizeof(unsigned int)*subevents[id][j].length + sizeof(unsigned int)*length;
}
subevents[id][j].length = length; for (i=0; i < HEADER_LENGTH; i++) {
subevents[id][j].data[i] = subhead[i];
}
if (length>HEADER_LENGTH) { nevts[id]++;
if (fread(subevents[id][j].data + HEADER_LENGTH, (length-HEADER_LENGTH)*sizeof(int), 1, fpr) != 1) break; evts_tot_read++;
nwords = nwords + (length-HEADER_LENGTH);
}
for (i=0; i < HEADER_LENGTH; i++) { }else {
subevents[id][j].data[i] = subhead[i]; pause = 1;
} break;
nevts[id]++;
evts_tot_read++;
}
else {
pause = 1;
break;
} }
} // end while for fill buffers } // end while for fill buffers maxevts[id]
///////// /////////
///////// //######################## FSU
// write event with minimum time to file // find group of event within timewindow, check is contain gamma. if not, throw away all.
timemin_old = timemin;
timemin = -1; if( eventWindow > 0 ){
for (i=0; i < idmax + 1; i++) { //could be MAX_ID but limit ourselves to current max, idmax
if (nevts[i] > 0) { //quick sort of subevents[i][iptr[i]].timestamp, i = 0 , idmax +1
if (timemin == -1) { for( i = 0 ; i < idmax + 1; i++) {
timemin = subevents[i][iptr[i]].timestamp;
time_old = timemin; if( nevts[i] > 0 ){
min_id = i; timeIndex[i] = subevents[i][iptr[i]].timestamp;
} }else{
else if (subevents[i][iptr[i]].timestamp < timemin) { timeIndex[i] = MAXLONGLONGINT;
timemin = subevents[i][iptr[i]].timestamp; }
time_old = timemin; index[i] = i;
min_id = i; //printf("%3d , %llu, %d \n", i, timeIndex[i], index[i] );
}
} }
quickSort(timeIndex, index, 0, idmax);
for( i = 0 ; i < idmax + 1; i++) {
//printf("%3d , %llu , %d\n", i, timeIndex[i], index[i]);
}
//reduce the index size
fillSize = 1;
for( i = 1; i < idmax + 1; i++){
if( timeIndex[i] - timeIndex[0] < eventWindow) fillSize ++;
}
// display
if ( count < debugCount) {
//if ( count < debugCount || timeIndex[10] == MAXLONGLONGINT) {
printf("===============================================\n");
for( int i = 0; i < idmax+1; i++) {
printf("%3d, %llu, %d \n", i, timeIndex[i], index[i]);
if( i == fillSize - 1 ) printf("------------------- %d \n", fillSize);
}
}
if( timeIndex[0] == MAXLONGLONGINT ) break;
//CHeck if fill evt.to for the data.
bool fillFlag = false;
for( i = 0 ; i < fillSize; i++ ){
if( count < debugCount ) printf("********************* %llu , detID : %d\n", timeIndex[0], subevents[index[i]][iptr[index[i]]].detID);
if( subevents[index[i]][iptr[index[i]]].detID < 100 ) fillFlag = true;
}
if( count < debugCount ) printf("=============== fillFlag : %d \n", fillFlag);
for( i = 0; i < fillSize; i++){
min_id = index[i];
if( fillFlag ){
fwrite(subevents[min_id][iptr[min_id]].data, sizeof(unsigned int)*subevents[min_id][iptr[min_id]].length, 1, fpw);
if( count < debugCount ) printf("filling subevents[%d][iprt[%d]] \n", min_id, min_id);
evts_tot_write++;
}else{
evts_tot_drop++;
}
//free data memory up until it's needed again
if( count < debugCount ) printf(" Free subevents[%d][iprt[%d]] \n", min_id, min_id);
free(subevents[min_id][iptr[min_id]].data);
subevents[min_id][iptr[min_id]].data = NULL;
totmem -= sizeof(unsigned int)*subevents[min_id][iptr[min_id]].length;
subevents[min_id][iptr[min_id]].length = 0;
subevents[min_id][iptr[min_id]].timestamp = 0;
subevents[min_id][iptr[min_id]].detID = -1;
nevts[min_id]--;
if (++iptr[min_id] >= maxevts[min_id]) iptr[min_id] -= maxevts[min_id];
}
count ++;
}else{
/////////
// write event with minimum time to file
timemin_old = timemin;
timemin = -1;
for (i=0; i < idmax + 1; i++) { //could be MAX_ID but limit ourselves to current max, idmax
if (nevts[i] > 0) {
if (timemin == -1) {
timemin = subevents[i][iptr[i]].timestamp;
time_old = timemin;
min_id = i;
}else if (subevents[i][iptr[i]].timestamp < timemin) {
timemin = subevents[i][iptr[i]].timestamp;
time_old = timemin;
min_id = i;
}
}
}
if (timemin > -1) {
if (timemin < timemin_old) {
printf("\nWarning!!! timemin = %lld and timemin_old = %lld and min_id = %d\n", timemin, timemin_old, min_id);
outoforder++;
}
if (subevents[min_id][iptr[min_id]].data == NULL) {printf("Error: data = NULL\n"); return -1;}
fwrite(subevents[min_id][iptr[min_id]].data, sizeof(unsigned int)*subevents[min_id][iptr[min_id]].length, 1, fpw);
//free data memory up until it's needed again
free(subevents[min_id][iptr[min_id]].data);
subevents[min_id][iptr[min_id]].data = NULL;
totmem -= sizeof(unsigned int)*subevents[min_id][iptr[min_id]].length;
subevents[min_id][iptr[min_id]].length = 0;
subevents[min_id][iptr[min_id]].timestamp = 0;
nevts[min_id]--;
if (++iptr[min_id] >= maxevts[min_id]) iptr[min_id] -= maxevts[min_id];
evts_tot_write++;
}else break;
/////////
} }
if (timemin > -1) {
if (timemin < timemin_old) {
printf("\nWarning!!! timemin = %lld and timemin_old = %lld and min_id = %d\n", timemin, timemin_old, min_id);
outoforder++;
}
if (subevents[min_id][iptr[min_id]].data == NULL) {printf("Error: data = NULL\n"); return -1;}
fwrite(subevents[min_id][iptr[min_id]].data, sizeof(unsigned int)*subevents[min_id][iptr[min_id]].length, 1, fpw);
//free data memory up until it's needed again
free(subevents[min_id][iptr[min_id]].data);
subevents[min_id][iptr[min_id]].data = NULL;
totmem -= sizeof(unsigned int)*subevents[min_id][iptr[min_id]].length;
subevents[min_id][iptr[min_id]].length = 0;
subevents[min_id][iptr[min_id]].timestamp = 0;
nevts[min_id]--;
if (++iptr[min_id] >= maxevts[min_id]) iptr[min_id] -= maxevts[min_id];
evts_tot_write++;
}
else break;
/////////
//print statistics //print statistics
//e_div=div(evts_tot_read,10000);
//if ( e_div.rem == 0)
if( evts_tot_read % 10000 == 0 ) if( evts_tot_read % 10000 == 0 )
printf("Malloc (%d MB) : evts in (\x1B[34m%lld\x1B[0m) : evts out (\x1B[32m%lld\x1B[0m) : diff (\x1B[31m%lld\x1B[0m)\r", (totmem)/1024/1024, evts_tot_read, evts_tot_write, evts_tot_read-evts_tot_write); printf("Malloc (%d MB) : evts in (\x1B[34m%lld\x1B[0m) : evts out (\x1B[32m%lld\x1B[0m) : evts drop (\x1B[32m%lld\x1B[0m) : diff (\x1B[31m%lld\x1B[0m)\r",
(totmem)/1024/1024, evts_tot_read, evts_tot_write, evts_tot_drop, evts_tot_read-evts_tot_write - evts_tot_drop);
} //end main while } //end main while

View File

@ -102,13 +102,14 @@ int main(int argc, char **argv) {
int countGP = 0; //gamma-particle coincident int countGP = 0; //gamma-particle coincident
double totalDataSize = 0; double totalDataSize = 0;
int outFileCount = 0;
for( int i = 0; i < nFile; i++){ for( int i = 0; i < nFile; i++){
evt->OpenFile(inFileName[i]); evt->OpenFile(inFileName[i]);
if( evt->IsOpen() == false ) continue; if( evt->IsOpen() == false ) continue;
printf("==================================================== %d / %d\n", i, nFile); printf("==================================================== %d / %d\n", i+1, nFile);
printf("\033[1;31m%s \033[m\n", inFileName[i].Data()); printf("\033[1;31m%s \033[m\n", inFileName[i].Data());
int pos = inFileName[i].Last('/'); int pos = inFileName[i].Last('/');
@ -141,13 +142,13 @@ int main(int argc, char **argv) {
if (tdif > timeWindow) { if (tdif > timeWindow) {
//Gate //Gate
if( multiCry > 0 && multiGagg > 0 ) { //if( multiCry > 2 && multiGagg ==0 ) {
//
outRootFile->cd(); outRootFile->cd();
tree->Fill(); tree->Fill();
//
countGP++; // countGP++;
} //}
evID ++; evID ++;
@ -200,7 +201,37 @@ int main(int argc, char **argv) {
printf(" ----------- root file size : %.3f GB\n", rootFileSize); printf(" ----------- root file size : %.3f GB\n", rootFileSize);
printf(" ---------- total read size : %.3f GB\n", totalDataSize); printf(" ---------- total read size : %.3f GB\n", totalDataSize);
printf(" ----------- reduction rate : %.3f %%\n", rootFileSize*100./totalDataSize); printf(" ----------- reduction rate : %.3f %%\n", rootFileSize*100./totalDataSize);
if( rootFileSize > 3.0 ) break;
if( rootFileSize > 3.0 ) {
break;
}
///try to open a new root file when file size > 2 GB
/*if( rootFileSize > 2.0 ) {
outRootFile->Close();
delete outRootFile;
delete tree;
outFileCount += 1;
if( outFileCount > 5 ) break;
TString outFileName2 = outFileName;
outFileName2.Insert(outFileName.Sizeof() - 6, Form("_%03d",outFileCount));
outRootFile = new TFile( outFileName2, "recreate");
tree = new TTree("tree", "tree");
tree->Branch("evID", &evID, "event_ID/l");
tree->Branch("multi", &multi, "multi/I");
tree->Branch("detID", id, "detID[multi]/I");
tree->Branch("e", e, "e[multi]/D");
tree->Branch("e_t", e_t, "e_timestamp[multi]/l");
tree->Branch("qdc", qdc, "qdc[multi][8]/I");
tree->Branch("multiCry", &multiCry, "multiplicity_crystal/I");
tree->Branch("multiGagg", &multiGagg, "multiplicity_GAGG/I");
tree->Branch("runID", &runID, "runID/I");
}*/
} }