fixed pxi-time-order.c for g++ compiler. add tDiff (commented out) for evt2root.cpp

This commit is contained in:
Ryan Tang 2021-12-21 19:43:24 -05:00
parent bbb58ecc09
commit 3e19117a49
3 changed files with 36 additions and 22 deletions

View File

@ -31,6 +31,8 @@ public:
UShort_t trace_length; UShort_t trace_length;
Bool_t trace_out_of_range; Bool_t trace_out_of_range;
Long64_t timeDiff;
UShort_t id; UShort_t id;
measurment(){}; measurment(){};
@ -46,6 +48,7 @@ public:
energy = 0; energy = 0;
trace_length = 0; trace_length = 0;
trace_out_of_range = 0; trace_out_of_range = 0;
timeDiff = 0;
id = 0; id = 0;
} }
@ -72,12 +75,12 @@ int main(int argn, char **argv) {
outFileName.Remove(inFileName.First('.')); outFileName.Remove(inFileName.First('.'));
outFileName.Append("_raw.root"); outFileName.Append("_raw.root");
long int inFilePos; long int inFilePos = 0;
TBenchmark gClock; TBenchmark gClock;
gClock.Reset(); gClock.Reset();
gClock.Start("timer"); gClock.Start("timer");
ULong64_t measureID = 0; Long64_t measureID = -1;
measurment data; measurment data;
@ -102,19 +105,22 @@ int main(int argn, char **argv) {
TFile * outFile = new TFile(outFileName, "recreate"); TFile * outFile = new TFile(outFileName, "recreate");
TTree * tree = new TTree("tree", "tree"); TTree * tree = new TTree("tree", "tree");
tree->Branch("evID", &measureID, "data_ID/l"); tree->Branch("evID", &measureID, "data_ID/L");
tree->Branch("detID", &data.id, "det_ID/s"); tree->Branch("detID", &data.id, "det_ID/s");
tree->Branch("e", &data.energy, "energy/s"); tree->Branch("e", &data.energy, "energy/s");
tree->Branch("t", &data.time, "time_stamp/l"); tree->Branch("t", &data.time, "time_stamp/l");
//tree->Branch("tdiff", &data.timeDiff, "time_Diff/L");
//=======TODO online event building //=======TODO online event building
unsigned int header[4]; //read 4 header, unsigned int = 4 byte = 32 bits. unsigned int header[4]; //read 4 header, unsigned int = 4 byte = 32 bits.
unsigned long long nWords = 0; unsigned long long nWords = 0;
ULong64_t timeLast = 0;
//=============== Read File //=============== Read File
/// while ( ! feof(inFile) ){ /// while ( ! feof(inFile) ){
while ( inFilePos <= inFileSize ){ // need to check is the last data included. while ( inFilePos <= inFileSize ){
fread(header, sizeof(header), 1, inFile); fread(header, sizeof(header), 1, inFile);
inFilePos = ftell(inFile); inFilePos = ftell(inFile);
@ -137,11 +143,20 @@ int main(int argn, char **argv) {
nWords += data.eventLength; nWords += data.eventLength;
///printf("----------------------nWords: %llu, inFilePos: %llu\n", nWords, inFilePos); //if( measureID == 0 ) {
///for(int i = 0; i < 4; i++){ // data.timeDiff = 0;
/// printf(" %x\n", header[i]); //}else{
///} // data.timeDiff = (Long64_t) data.time - timeLast;
///data.Print(); //}
//timeLast = data.time;
//if( data.timeDiff == false ){
// printf("----------------------nWords: %llu, inFilePos: %lu\n", nWords, inFilePos);
// for(int i = 0; i < 4; i++){
// printf(" %x\n", header[i]);
// }
// data.Print();
//}
//=== jump to next measurement //=== jump to next measurement
if( data.eventLength > 4 ){ if( data.eventLength > 4 ){
@ -156,7 +171,7 @@ int main(int argn, char **argv) {
gClock.Stop("timer"); gClock.Stop("timer");
double time = gClock.GetRealTime("timer"); double time = gClock.GetRealTime("timer");
gClock.Start("timer"); gClock.Start("timer");
printf("Total measurements: \x1B[32m%llu \x1B[0m\nPercent Complete: \x1B[32m%ld%% of %.3f GB\x1B[0m\nTime used:%3.0f min %5.2f sec\033[A\033[A\r", printf("Total measurements: \x1B[32m%lld \x1B[0m\nPercent Complete: \x1B[32m%ld%% of %.3f GB\x1B[0m\nTime used:%3.0f min %5.2f sec\033[A\033[A\r",
measureID, (100*inFilePos/inFileSize), tempf, TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60.); measureID, (100*inFilePos/inFileSize), tempf, TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60.);
} }
@ -171,7 +186,7 @@ int main(int argn, char **argv) {
double time = gClock.GetRealTime("timer"); double time = gClock.GetRealTime("timer");
gClock.Start("timer"); gClock.Start("timer");
float tempf = (float)inFileSize/(1024.*1024.*1024.); float tempf = (float)inFileSize/(1024.*1024.*1024.);
printf("Total measurements: \x1B[32m%llu \x1B[0m\nPercent Complete: \x1B[32m%ld%% of %.3f GB\x1B[0m\nTime used:%3.0f min %5.2f sec\033[A\r", printf("Total measurements: \x1B[32m%lld \x1B[0m\nPercent Complete: \x1B[32m%ld%% of %.3f GB\x1B[0m\nTime used:%3.0f min %5.2f sec\033[A\r",
measureID, (100*inFilePos/inFileSize), tempf, TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60.); measureID, (100*inFilePos/inFileSize), tempf, TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60.);
fclose(inFile); fclose(inFile);

View File

@ -170,7 +170,7 @@ int main(int argc, char **argv) {
//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] = 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");
return -1; return -1;
@ -261,7 +261,7 @@ int main(int argc, char **argv) {
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] = 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;
@ -278,7 +278,7 @@ int main(int argc, char **argv) {
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 = 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;
@ -318,7 +318,7 @@ int main(int argc, char **argv) {
subevents[id][j].timestamp = time; subevents[id][j].timestamp = time;
if (subevents[id][j].data == NULL) { if (subevents[id][j].data == NULL) {
subevents[id][j].data = malloc(sizeof(unsigned int)*length); subevents[id][j].data = (unsigned int * )malloc(sizeof(unsigned int)*length);
if (subevents[id][j].data == NULL) { if (subevents[id][j].data == NULL) {
printf("malloc failed\n"); printf("malloc failed\n");
return -1; return -1;
@ -326,7 +326,7 @@ int main(int argc, char **argv) {
totmem += sizeof(unsigned int)*length; 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 ... else if (length != subevents[id][j].length) { //not needed anymore since always free data after use now. Keep for future ...
subevents[id][j].data = realloc(subevents[id][j].data, sizeof(unsigned int)*length); subevents[id][j].data = (unsigned int *)realloc(subevents[id][j].data, sizeof(unsigned int)*length);
if (subevents[id][j].data == NULL) { if (subevents[id][j].data == NULL) {
printf("realloc failed\n"); printf("realloc failed\n");
return -1; return -1;
@ -402,8 +402,7 @@ int main(int argc, char **argv) {
//print statistics //print statistics
e_div=div(evts_tot_read,10000); if ( evts_tot_read % 10000 == 0)
if ( e_div.rem == 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) : diff (\x1B[31m%lld\x1B[0m)\r", (totmem)/1024/1024, evts_tot_read, evts_tot_write, evts_tot_read-evts_tot_write);
} //end main while } //end main while

View File

@ -2,7 +2,7 @@ CC=g++
#all: xia2root xia2ev2_nopart pixie2root scan pxi-time-order #all: xia2root xia2ev2_nopart pixie2root scan pxi-time-order
#all: xia2root xia2ev2_nopart pixie2root scan evt2root evt2hist #all: xia2root xia2ev2_nopart pixie2root scan evt2root evt2hist
all: xia2root pixie2root evt2root evt2hist all: xia2root pixie2root evt2root evt2hist pxi-time-order
#this is FSU evt to root #this is FSU evt to root
xia2root: armory/xia2root.cpp xia2root: armory/xia2root.cpp
@ -23,5 +23,5 @@ evt2root: armory/evt2root.cpp
evt2hist: armory/evt2hist.cpp evt2hist: armory/evt2hist.cpp
$(CC) armory/evt2hist.cpp -o evt2hist `root-config --cflags --glibs` $(CC) armory/evt2hist.cpp -o evt2hist `root-config --cflags --glibs`
#pxi-time-order: pxi-time-order.c pxi-time-order: armory/pxi-time-order.c
# $(CC) pxi-time-order.c -o pxi-time-order $(CC) armory/pxi-time-order.c -o pxi-time-order