]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCAltro.C
Now uses the simplified interface of RawStreamTracker to loop over raw data
[u/mrichter/AliRoot.git] / TPC / AliTPCAltro.C
CommitLineData
b62e2a95 1#if !defined(__CINT__)
2#include <Riostream.h>
3#include <TFile.h>
4#include <TTree.h>
5#include "AliTPCParamSR.h"
6#include "AliTPCDigitsArray.h"
7#include "AliSimDigits.h"
2e9f335b 8#include "AliTPCBuffer160.h"
2e9f335b 9#endif
10
04fa961a 11int AliTPCAltro(Int_t eth=0){
2e9f335b 12 //eth is a threshold.
a79660fb 13 //Digits stored into a file have an amplitude value greater than "eth"
2e9f335b 14 Int_t offset=1; //this should be equal to the threshold
15 /*
a79660fb 16 NB the amplitude values stored in the ALTRO file are shifted by offset
2e9f335b 17 because the range for each word goes from 0 to 1023, now due to zero suppression
18 values lower that the threshold never appear.
19 */
2e9f335b 20
21 Int_t PSecNumber=-1; //Previous Sector number
22 Int_t PRowNumber=-1; //Previous Row number
23 Int_t PPadNumber=-1; //Previous Pad number
24 Int_t PTimeBin=-1; //Previous Time-Bin
25 Int_t BunchLength=0;
2e9f335b 26 //AliTPCBuffer160 is used in write mode to generate AltroFormat.dat file
27 AliTPCBuffer160 Buffer("AltroFormat.dat",1);
2e9f335b 28 ULong_t Count=0;
29 Int_t nwords=0;
30 Int_t numPackets=0;
04fa961a 31
32 const char * inFile_new = "galice.root";
33 AliRunLoader *rl = AliRunLoader::Open(inFile_new,"Event","read");
34
35 Int_t nevents=rl->GetNumberOfEvents();
36 cout<<"Number of Events:"<<nevents<<endl;
37 Int_t choice=0;
38 do{
39 cout<<"Insert the event number: ";
40 cin>>choice;
41 }while (choice<=0 || choice>nevents);
42 rl->GetEvent(choice-1);
43 AliLoader *tpcloader=rl->GetLoader("TPCLoader");
44 tpcloader->LoadDigits();
45 TTree *digitsTree=tpcloader->TreeD();
46
47 AliSimDigits digrows, *dummy=&digrows;
48 digitsTree->GetBranch("Segment")->SetAddress(&dummy);
49 Stat_t nrows = digitsTree->GetEntries();
50 cout<<"Number of entries (rows):"<<nrows<<endl;
51 // get the TPC parameters
52 rl->CdGAFile();
53 AliTPCParamSR* param = AliTPC::LoadTPCParam(gFile);
54 if (!param)
55 cout<<"No TPC parameter"<<endl;
56 AliTPCDigitsArray *digarr=new AliTPCDigitsArray;
57 digarr->Setup(param);
58 digarr->ConnectTree(digitsTree);
2e9f335b 59 //ofstream ftxt("Data.txt");
60 for (Int_t n=0; n<nrows; n++) {
2e9f335b 61 Int_t sec,row; // sector and row number (in the TPC)
04fa961a 62 AliSimDigits *digrow=(AliSimDigits*)digarr->LoadEntry(n);
2e9f335b 63 param->AdjustSectorRow(digrow->GetID(),sec,row);
04fa961a 64
2e9f335b 65 //cout<<"Sector:"<<sec<<" Row:"<<row<<endl;
66 digrow->First();
67 do{
04fa961a 68 Short_t dig=digrow->CurrentDigit(); //adc
69 Int_t time=digrow->CurrentRow(); //time
70 Int_t pad =digrow->CurrentColumn(); // pad
71 //cout<<"dig:"<<dig<<" time:"<<time<<" pad:"<<pad<<endl;
72 if(dig>eth){
2e9f335b 73 Count++;
74 //ftxt<<"Sec: "<<sec<<" Row: "<<row<<" Pad:"<<pad<<" Time: "<<time<<" ADC:"<<dig<<endl;
75 //cout<<"Sec: "<<sec<<" Row: "<<row<<" Pad:"<<pad<<" Time: "<<time<<" ADC:"<<dig<<endl;
76 if (PPadNumber==-1){
77 PSecNumber=sec;
78 PRowNumber=row;
79 PPadNumber=pad;
80 // PAmplitude=dig;
81 PTimeBin=time;
82 BunchLength=1;
83 Buffer.FillBuffer(dig-offset);
84 nwords++;
85 }//end if
86 else{
87 if ( (time==(PTimeBin+1)) &&
88 (PPadNumber==pad) &&
89 (PRowNumber==row) &&
90 (PSecNumber==sec)){
91 BunchLength++;
92 }//end if
93 else{
94 Buffer.FillBuffer(PTimeBin);
95 Buffer.FillBuffer(BunchLength+2);
96 nwords+=2;
97 if ((PPadNumber!=pad)||(PRowNumber!=row)||(PSecNumber!=sec)){
98 //Trailer is formatted and inserted!!
99 Buffer.WriteTrailer(nwords,PPadNumber,PRowNumber,PSecNumber);
100 numPackets++;
101 nwords=0;
102 }//end if
103
104 BunchLength=1;
105 PPadNumber=pad;
106 PRowNumber=row;
107 PSecNumber=sec;
108 }//end else
109 PTimeBin=time;
110 Buffer.FillBuffer(dig-offset);
111 nwords++;
112 }//end else
113 }//end if
114 } while (digrow->Next());
115 }//end for
04fa961a 116
2e9f335b 117 Buffer.FillBuffer(PTimeBin);
118 Buffer.FillBuffer(BunchLength+2);
119 nwords+=2;
120 Buffer.WriteTrailer(nwords,PPadNumber,PRowNumber,PSecNumber);
04fa961a 121
2e9f335b 122 numPackets++;
123 cout<<"There are "<<Count<<" Digits\n";
124 cout<<"Packets "<<numPackets<<"\n";
125 //ftxt.close();
126 return 0;
127}//end macro