Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

  1. //root [1] .x read.C("../../guest/datoteka.dat")
  2.  
  3. const int BSIZE=10000;
  4. unsigned int gBuf[BSIZE];
  5. const int MAXCH=32;
  6. TH1F* gHisto[MAXCH];
  7.  
  8. int read(char *fname="datoteka.dat", int fDebug=1){
  9. FILE *fp= fopen(fname,"r");
  10. if (!fp) {
  11.   printf("Error! File %s not found\n", fname);
  12.   return 0;
  13. }
  14.  
  15.  
  16. for (int i=0;i<MAXCH;i++){
  17.     char hname[50];
  18.     sprintf(hname,"TDC Ch. %d;TDC;N",i);
  19.     char hn[50];
  20.     sprintf(hn,"ch%d",i);
  21.     gHisto[i]   = new TH1F(hn,hname,128,-0.5,1024*8-0.5);
  22. }
  23.  
  24. int hdr[4];
  25. int n=0;
  26. while (!feof(fp)){
  27.   fread(hdr,sizeof(int),4,fp);
  28.   if (hdr[0]!=1) {
  29.     printf("error\n");
  30.     return -1;
  31.   }
  32.   int nb = hdr[1]-4*sizeof(int);
  33.   fread(gBuf,sizeof(int),nb,fp);
  34.   unsigned int *data= gBuf;
  35.     int evsize=0;
  36.     int events=0;  
  37.     int ib=1,count=0;
  38.     events = data[0];
  39.     evsize = data[1]&0xffff;
  40.     if (evsize<2){
  41.       continue;
  42.     }
  43.     n=hdr[3];
  44.     const unsigned int  END_MARKER=0xFAF5;
  45.     if (fDebug) printf("nb=%d Event:%d events=%d EvSize:%d\n",nb,n,  events, evsize);
  46.     for (int i=0;i<evsize;i++)  {
  47.        //if (fDebug) printf("%d\t%08x\n", ib, data[ib]);
  48.      
  49.        if (data[ib]== END_MARKER) break;
  50.        if (ib%2==0) {
  51.           unsigned short word1 =data[ib  ]&0xFFFF;
  52.           unsigned short word2 =data[ib+1]&0xFFFF;
  53.           unsigned short tdc =  word1;                 
  54.           unsigned short ch  =  (word2 >> 1 ) &0x1F;
  55.           unsigned short edge =  word2   & 0x1;
  56.           unsigned short q    = (word2 >> 8)  &0x1;
  57.           unsigned short x    = (word2 >> 9)  &0x1;
  58.          
  59.           if (edge && ch < MAXCH) gHisto[ch]->Fill(tdc);
  60.    
  61.           if (fDebug) printf("%d. [ch=%2d] edge=%d data=%d q=%d x=%d\n",count,ch,edge,tdc, q, x);
  62.          
  63.           count++;
  64.        }
  65.        ib++;
  66.     }
  67.     if (data[evsize+1]!=END_MARKER) printf("Error! END_MARKER not found\n");
  68. //*****************
  69. }
  70. for (int i=0;i<MAXCH;i++){
  71. if (gHisto[i]->GetEntries()>0) gHisto[i]->Draw();
  72.  
  73. }
  74.  
  75. }
  76.