#include "stdio.h" //#include "TH1I.h" #include "TH1F.h" //#include "TH1D.h" //#include "TH2I.h" #include "TH2F.h" #include "TF1.h" //#include "TFile.h" //#include "TBenchmark.h" #include "TStyle.h" #include "TCanvas.h" #define NCHAINS 4 #define NCHIPS 6 #define NCH 18 #define HAPDCH NCHAINS*NCHIPS*NCH #define READBUFFERLENGTH 50000 // data format #define MAXDATA 200 #define RUNREC_ID 1 #define ENDREC_ID 2 #define POSREC_ID 3 #define EVTREC_ID 4 #define THRREC_ID 5 typedef struct { UInt_t id,len; UInt_t time; UInt_t fver; UInt_t nev,nch,thr,xy; Int_t nx,x0,dx,ny,y0,dy; Int_t nth,th0,dth; } RUNREC; RUNREC *runrec; RUNREC run; typedef struct { UInt_t id,len; UInt_t time; } ENDREC; ENDREC *endrec; typedef struct { UInt_t id,len; UInt_t time; Int_t ix,x,xset,iy,y,yset; } POSREC; POSREC *posrec; POSREC pos; typedef struct { UInt_t id,len; UInt_t time; UInt_t nev; UInt_t data[MAXDATA]; } EVTREC; EVTREC *evtrec; typedef struct { UInt_t id,len; UInt_t time; Int_t ith,th; } THRREC; THRREC *thrrec; THRREC thr; // ------------------------------------------------------------------------------ UInt_t Swap4(UInt_t *i) { //printf("IN : i = %u, bytes = %u %u %u %u\n", *i, (*i>>24)&0xff, (*i>>16)&0xff, (*i>>8)&0xff, (*i)&0xff); *i = ((*i & 0xff000000) >> 24) + ((*i & 0x00ff0000) >> 8) + ((*i & 0x0000ff00) << 8) + ((*i & 0x000000ff) << 24); //printf("OUT: i = %u, bytes = %u %u %u %u\n", *i, (*i>>24)&0xff, (*i>>16)&0xff, (*i>>8)&0xff, (*i)&0xff); return *i; } // ------------------------------------------------------------------------------ // shows treshold scan results and creates param file to align sigma_mult // position of noise int runinfo(char* datfile="run094") { int dbg = 0; //data file FILE *fp; char fulldatname[256]; // opens data file sprintf(fulldatname, "data/%s.dat", datfile); if( (fp=fopen(fulldatname, "rb")) == NULL ) { printf(" Cannot open data file: %s !!!\n", fulldatname); return -1; } else printf(" Opened data file: %s\n", fulldatname); //data buffer char readbuf[READBUFFERLENGTH]; runrec = (RUNREC *) readbuf; endrec = (ENDREC *) readbuf; posrec = (POSREC *) readbuf; evtrec = (EVTREC *) readbuf; thrrec = (THRREC *) readbuf; // ----------------------------------------------- // loop trough records UInt_t rec_id, rec_len; unsigned ulsize = sizeof(UInt_t); int iw, io, ih, ii; int ceve=0; while(1) { if( fread(&rec_id, 1, ulsize, fp) < ulsize ) break; Swap4(&rec_id); if( fread(&rec_len, 1, ulsize, fp) < ulsize ) break; Swap4(&rec_len); fseek(fp, -2*(int)(ulsize), SEEK_CUR); if(dbg) printf("\n-----------------------------------------------\n"); if(dbg) printf("[%d] rec_id = %d | rec_len = %d\n", ceve, rec_id, rec_len); switch(rec_id) { case RUNREC_ID: if( fread(readbuf, 1, rec_len, fp) < rec_len ) break; for(int i=0; i< (READBUFFERLENGTH - 4); i+=4) Swap4((UInt_t*)&readbuf[i]); run = *runrec; printf("RUNREC\n"); printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); printf("nev = %d, nch = %d, thr = %d\n", run.nev, run.nch, run.thr); printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); printf("nth = %d, th0 = %d, dth = %d\n", run.nth , run.th0, run.dth); printf("-----------------------------------------------\n"); break; case POSREC_ID: if( fread(readbuf, 1, rec_len, fp) < rec_len ) break; for(int i=0; i< (READBUFFERLENGTH - 4); i+=4) Swap4((UInt_t*)&readbuf[i]); pos = *posrec; printf("POSREC: %d, %d\n", posrec->xset, posrec->yset); break; case THRREC_ID: if( fread(readbuf, 1, rec_len, fp) < rec_len ) break; for(int i=0; i< (READBUFFERLENGTH - 4); i+=4) Swap4((UInt_t*)&readbuf[i]); thr = *thrrec; printf("THRREC: ith = %d, th = %d\n", thrrec->ith, thrrec->th); break; case EVTREC_ID: if( fread(readbuf, 1, rec_len, fp) < rec_len ) break; /* for(int i=0; i< (READBUFFERLENGTH - 4); i+=4) Swap4((UInt_t*)&readbuf[i]); if(dbg) { printf("EVTREC_ID\n");s printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); for(int datai = 0; datai < MAXDATA; datai++) printf("%u ", evtrec->data[datai]); printf("\n"); } // events ------------------ // fill histograms for(int j=0; jdata[iw]>>(4*io))&0xf; if(ih != 0) { //printf("NOT ZERO"); } } } // events ------------------ */ break; case ENDREC_ID: if( fread(readbuf, 1, rec_len, fp) < rec_len ) break; for(int i=0; i< (READBUFFERLENGTH - 4); i+=4) Swap4((UInt_t*)&readbuf[i]); printf("-----------------------------------------------\nENDREC: id = %d, len = %d, (end-run)time = %d\n", endrec->id, endrec->len, endrec->time - run.time); break; default: printf("switch(rec_id): default !!!\n"); break; } ceve++; if( (ceve%50000) == 0) printf(" Current event = %d\n", ceve); if(dbg) if( ceve>6 ) break; if(feof(fp)) break; } fclose(fp); // ----------------------------------------------- return 0; }