Blame | Last modification | View Log | RSS feed
//root [1] .x read.C("../../guest/datoteka.dat")
const int BSIZE=10000;
unsigned int gBuf[BSIZE];
const int MAXCH=32;
TH1F* gHisto[MAXCH];
int read(char *fname="datoteka.dat", int fDebug=1){
FILE *fp= fopen(fname,"r");
if (!fp) {
printf("Error! File %s not found\n", fname);
return 0;
}
for (int i=0;i<MAXCH;i++){
char hname[50];
sprintf(hname,"TDC Ch. %d;TDC;N",i);
char hn[50];
sprintf(hn,"ch%d",i);
gHisto[i] = new TH1F(hn,hname,128,-0.5,1024*8-0.5);
}
int hdr[4];
int n=0;
while (!feof(fp)){
fread(hdr,sizeof(int),4,fp);
if (hdr[0]!=1) {
printf("error\n");
return -1;
}
int nb = hdr[1]-4*sizeof(int);
fread(gBuf,sizeof(int),nb,fp);
unsigned int *data= gBuf;
int evsize=0;
int events=0;
int ib=1,count=0;
events = data[0];
evsize = data[1]&0xffff;
if (evsize<2){
continue;
}
n=hdr[3];
const unsigned int END_MARKER=0xFAF5;
if (fDebug) printf("nb=%d Event:%d events=%d EvSize:%d\n",nb,n, events, evsize);
for (int i=0;i<evsize;i++) {
//if (fDebug) printf("%d\t%08x\n", ib, data[ib]);
if (data[ib]== END_MARKER) break;
if (ib%2==0) {
unsigned short word1 =data[ib ]&0xFFFF;
unsigned short word2 =data[ib+1]&0xFFFF;
unsigned short tdc = word1;
unsigned short ch = (word2 >> 1 ) &0x1F;
unsigned short edge = word2 & 0x1;
unsigned short q = (word2 >> 8) &0x1;
unsigned short x = (word2 >> 9) &0x1;
if (edge && ch < MAXCH) gHisto[ch]->Fill(tdc);
if (fDebug) printf("%d. [ch=%2d] edge=%d data=%d q=%d x=%d\n",count,ch,edge,tdc, q, x);
count++;
}
ib++;
}
if (data[evsize+1]!=END_MARKER) printf("Error! END_MARKER not found\n");
//*****************
}
for (int i=0;i<MAXCH;i++){
if (gHisto[i]->GetEntries()>0) gHisto[i]->Draw();
}
}