]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCAltro.C
Correction in Binaries().
[u/mrichter/AliRoot.git] / TPC / AliTPCAltro.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <fstream.h>
3 #include "AliTPCBuffer160.h"
4 #include <alles.h>
5 #endif
6
7 int AliTPCAltro(char* FileName,Int_t eth=0){
8   //eth is a threshold.
9   //Digits stored into a file have an amplitude value greater than "eth"
10   Int_t offset=1; //this should be equal to the threshold
11   /*
12     NB the amplitude values stored in the ALTRO file are shifted  by offset 
13     because the range for each word goes from 0 to 1023, now due to zero suppression 
14     values lower that the threshold never appear.
15    */
16   TFile *cf=TFile::Open(FileName);
17   // old geometry (3.07)
18   //AliTPCParamSR *param =(AliTPCParamSR *)cf->Get("75x40_100x60");
19   // if new geometry comment out the line above and uncomment the one below
20   AliTPCParamSR *param =(AliTPCParamSR *)cf->Get("75x40_100x60_150x60");
21   AliTPCDigitsArray *digarr=new AliTPCDigitsArray;
22   digarr->Setup(param);
23   
24   char  cname[100];
25   //old geometry
26   //sprintf(cname,"TreeD_75x40_100x60_%d",eventn);
27   // if new geometry comment out the line above and uncomment the one below
28   Int_t eventn=0;
29   sprintf(cname,"TreeD_75x40_100x60_150x60_%d",eventn);
30   digarr->ConnectTree(cname);
31
32   Int_t PSecNumber=-1;  //Previous Sector number
33   Int_t PRowNumber=-1;  //Previous Row number  
34   Int_t PPadNumber=-1;  //Previous Pad number
35   Int_t PTimeBin=-1;    //Previous Time-Bin
36   Int_t BunchLength=0;
37
38   //AliTPCBuffer160 is used in write mode to generate AltroFormat.dat file
39   AliTPCBuffer160 Buffer("AltroFormat.dat",1); 
40   //number of entries in the tree
41   Int_t nrows=Int_t(digarr->GetTree()->GetEntries());
42   cout<<"Number of entries "<<nrows<<endl;
43   ULong_t Count=0;
44   Int_t nwords=0;
45   Int_t numPackets=0;
46   //ofstream ftxt("Data.txt");
47   for (Int_t n=0; n<nrows; n++) {
48     AliSimDigits *digrow=(AliSimDigits*)digarr->LoadEntry(n);
49     Int_t sec,row; // sector and row number (in the TPC)
50     param->AdjustSectorRow(digrow->GetID(),sec,row);   
51     //cout<<"Sector:"<<sec<<" Row:"<<row<<endl;
52     digrow->First();
53     do{
54       Short_t dig=digrow->CurrentDigit(); //adc
55       Int_t time=digrow->CurrentRow(); //time
56       Int_t pad =digrow->CurrentColumn(); // pad 
57       if(dig>eth){
58         Count++;
59         //ftxt<<"Sec: "<<sec<<" Row: "<<row<<" Pad:"<<pad<<" Time: "<<time<<" ADC:"<<dig<<endl;
60         //cout<<"Sec: "<<sec<<" Row: "<<row<<" Pad:"<<pad<<" Time: "<<time<<" ADC:"<<dig<<endl;
61         if (PPadNumber==-1){
62           PSecNumber=sec;
63           PRowNumber=row;
64           PPadNumber=pad;
65           // PAmplitude=dig;
66           PTimeBin=time;
67           BunchLength=1;
68           Buffer.FillBuffer(dig-offset);
69           nwords++;
70         }//end if
71         else{
72           if ( (time==(PTimeBin+1)) &&
73                (PPadNumber==pad) &&
74                (PRowNumber==row) &&
75                (PSecNumber==sec)){
76             BunchLength++;
77           }//end if
78           else{
79             Buffer.FillBuffer(PTimeBin);
80             Buffer.FillBuffer(BunchLength+2);
81             nwords+=2;
82             if ((PPadNumber!=pad)||(PRowNumber!=row)||(PSecNumber!=sec)){
83               //Trailer is formatted and inserted!!
84               Buffer.WriteTrailer(nwords,PPadNumber,PRowNumber,PSecNumber);
85               numPackets++;
86               nwords=0;
87             }//end if
88             
89             BunchLength=1;
90             PPadNumber=pad;
91             PRowNumber=row;
92             PSecNumber=sec;
93           }//end else
94           PTimeBin=time;
95           Buffer.FillBuffer(dig-offset);
96           nwords++;
97         }//end else
98       }//end if
99     } while (digrow->Next());
100   }//end for
101   Buffer.FillBuffer(PTimeBin);
102   Buffer.FillBuffer(BunchLength+2);
103   nwords+=2;
104   Buffer.WriteTrailer(nwords,PPadNumber,PRowNumber,PSecNumber);
105   numPackets++;
106   cout<<"There are "<<Count<<" Digits\n";
107   cout<<"Packets "<<numPackets<<"\n";
108   //ftxt.close();
109   return 0;
110 }//end macro