]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3TPCBeamTestMemHandler.cxx
e5d53fa906b043429956c143446916c0d7e436c6
[u/mrichter/AliRoot.git] / HLT / src / AliL3TPCBeamTestMemHandler.cxx
1 // @(#) $Id$
2
3 /** \class AliL3TPCBeamTestMemHandler 
4 <pre>
5 //_____________________________________________________________
6 // AliL3TPCBeamTestMemHandler
7 //
8 // Author: C. Loizides <loizides@ikf.uni-frankfurt.de>
9 // -- Copyright &copy ALICE HLT Group
10 </pre>
11 */
12
13 #include "AliL3StandardIncludes.h"
14 #include "AliL3RootTypes.h"
15 #include "AliL3Logging.h"
16 #include "AliL3Transform.h"
17 #include "AliL3MemHandler.h"
18 #include "AliL3DigitData.h"
19 #include "AliL3TPCBeamTestMemHandler.h"
20
21 #if __GNUC__ == 3
22 using namespace std;
23 #endif
24
25
26 ClassImp(AliL3TPCBeamTestMemHandler)
27
28 AliL3TPCBeamTestMemHandler::AliL3TPCBeamTestMemHandler(Char_t *fPathToMappingFile) : AliL3MemHandler()
29 { //constructor
30   fMinTimeBin=1;
31   fNumOfChannels=7807+1; //must be big enough to contain all channels (per patch)
32
33   Char_t readcarry[255];
34   Int_t actPos=0;
35   Int_t oldPos=0;
36   ifstream *in = new ifstream();
37   in->open(fPathToMappingFile); 
38   if(!in->is_open()){
39     LOG(AliL3Log::kFatal,"AliL3TPCBeamTestMemHandler","Mapping File")
40         <<"Can't open file " << fPathToMappingFile << " !!!" <<ENDLOG;
41   }
42   fMapping = new short*[fNumOfChannels];
43   for ( Int_t i = 0; i < fNumOfChannels; i++ )
44       fMapping[i] = 0;
45   fMappingEmptyRow = new short[11]; //11 colums per row in mapping file
46   for(Int_t i = 0; i < 11 ; i++){
47       fMappingEmptyRow[i] = 0;
48   }
49   Short_t *mappingRow;
50   for(Int_t i = 0; i < 5504 ; i++) { //5504 is size of irorc mapping at the moment only for irorc
51       mappingRow = new Short_t[11];
52       for(Int_t j = 0 ; j < 11 ; j++) {
53           *in >> readcarry;
54           mappingRow[j] = atoi(readcarry);
55      }
56       actPos = mappingRow[0];
57       fMapping[actPos] = mappingRow;
58       if( (actPos - oldPos) > 1){
59           for(Int_t j = (oldPos+1); j < actPos; j++){
60               fMapping[j] = fMappingEmptyRow;
61           }
62       }
63       oldPos = actPos;
64   }
65   in->close();
66   delete in;
67 }
68
69 AliL3TPCBeamTestMemHandler::~AliL3TPCBeamTestMemHandler()
70 { //destructor
71   for(Int_t i = 0; i < 5504 ; i++) { 
72         if(fMapping[i] != fMappingEmptyRow && fMapping[i]) delete[] fMapping[i];
73   }
74   delete [] fMappingEmptyRow;
75  delete[] fMapping;
76 }
77
78 AliL3DigitRowData* AliL3TPCBeamTestMemHandler::RawData2Memory(UInt_t &nrow,Int_t /*event*/)
79 { //convert the raw data
80   AliL3DigitRowData *data = 0;
81   nrow=0;
82
83   Int_t nrowsdummy=AliL3Transform::GetNRows(fPatch);
84   fRows = new RowStructure[nrowsdummy];
85   for(Int_t i=0;i<nrowsdummy;i++){
86    fRows[i].fRow=-1;
87    fRows[i].fNDigits=0;
88    fRows[i].fPadPos= new Int_t[AliL3Transform::GetNPads(i+fRowMin)];
89    for(Int_t p=0;p<AliL3Transform::GetNPads(i+fRowMin);p++)
90      fRows[i].fPadPos[p]=-1;
91   }
92
93   Int_t ntimebins=AliL3Transform::GetNTimeBins();
94   Int_t npads=fInputSize/(ntimebins+1);
95   Int_t ndigitcount=0; //total number of digits to be published
96   for(Int_t i=0;i<npads;i++){
97     Int_t pos=i*(ntimebins+1);
98     Short_t hw=fInputPtr[pos];
99     if(hw>=fNumOfChannels) continue;
100     Int_t pad=MappingGetPad(hw);
101     Int_t lrow=MappingGetPadRow(hw);
102     if((lrow<0) ||(pad<0)) continue;
103     if(lrow+fRowMin>fRowMax) continue;
104     fRows[lrow].fRow=lrow+fRowMin;
105     if(fRows[lrow].fPadPos[pad]!=-1){
106       continue;
107     }
108     Bool_t isThereDataOnThisPad=kFALSE;
109     Int_t digmean=0;
110 #if 1
111     for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
112       Int_t dig=fInputPtr[pos+timebin];
113       digmean+=dig;
114     }
115     digmean/=(ntimebins-fMinTimeBin+1);
116 #else
117     digmean = 40;
118 #endif
119     for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
120       Int_t dig=fInputPtr[pos+timebin]-digmean;
121     
122       if(dig <= AliL3Transform::GetZeroSup()) continue;
123       if(dig >= AliL3Transform::GetADCSat())
124         dig = AliL3Transform::GetADCSat();
125
126         fRows[lrow].fNDigits++; //for this row only
127         ndigitcount++;  
128         isThereDataOnThisPad=kTRUE;
129       }
130
131     if(isThereDataOnThisPad) {
132       fRows[lrow].fPadPos[pad]=pos;
133     }
134   }
135
136   Int_t nrows=0;
137   for(Int_t i=0;i<AliL3Transform::GetNRows(fPatch);i++){
138       if(fRows[i].fRow!=-1) nrows++;
139   }
140   if(nrows!=AliL3Transform::GetNRows(fPatch))
141     LOG(AliL3Log::kError,"AliL3TPCBeamTestMemHandler::RawData2Memory","nrows")
142       <<AliL3Log::kDec<<"Found Inconsistency "<<nrows<<" != "<<AliL3Transform::GetNRows(fPatch)<<ENDLOG;
143
144   //allocate memory
145   Int_t size = sizeof(AliL3DigitData)*ndigitcount
146     + nrows*sizeof(AliL3DigitRowData);
147   LOG(AliL3Log::kDebug,"AliL3TPCBeamTestMemHandler::RawData2Memory","Digits")
148     <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits on "<<nrows<<" rows"<<ENDLOG;
149
150   data=(AliL3DigitRowData*)Allocate(size);
151   nrow = (UInt_t)nrows;
152   //memset(data,1,size); //for debugging
153
154   Int_t ndigitcounttest=0;
155   AliL3DigitRowData *tempPt = data;
156   for(Int_t i=0;i<AliL3Transform::GetNRows(fPatch);i++){
157     Int_t slrow=i+fRowMin;
158     
159     if(slrow!=fRows[i].fRow){
160       LOG(AliL3Log::kFatal,"AliL3TPCBeamTestMemHandler::RawData2Memory","Row Mismatch")
161         <<AliL3Log::kDec<<"Mismatch: slrow "<<slrow<<" row "
162         <<fRows[i].fRow<<ENDLOG;
163     }
164
165     tempPt->fRow = slrow;
166     tempPt->fNDigit = fRows[i].fNDigits;
167
168     Int_t localcount=0;
169     for(Int_t pad=0;pad<AliL3Transform::GetNPads(slrow);pad++){
170       Int_t pos=fRows[i].fPadPos[pad];
171       if(pos==-1) continue; //no data on that pad;
172       Int_t digmean=0;
173 #if 1
174       for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
175         Int_t dig=fInputPtr[pos+timebin];
176         digmean+=dig;
177       }
178       digmean/=(ntimebins-fMinTimeBin+1);
179 #else
180     digmean = 40;
181 #endif
182       for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
183         Int_t dig=fInputPtr[pos+timebin]-digmean;
184     
185         if(dig <= AliL3Transform::GetZeroSup()) continue;
186         if(dig >= AliL3Transform::GetADCSat())
187             dig = AliL3Transform::GetADCSat();
188
189         //Exclude data outside cone:
190         //AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
191         //if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) continue;
192
193         tempPt->fDigitData[localcount].fCharge=(UShort_t)dig;
194         tempPt->fDigitData[localcount].fPad=(UChar_t)pad;
195         tempPt->fDigitData[localcount].fTime=(UShort_t)timebin-1;
196         //cout << slrow << " " << pad << " " << timebin << " " << dig << endl;
197 #ifdef do_mc
198         tempPt->fDigitData[localcount].fTrackID[0] = 0;
199         tempPt->fDigitData[localcount].fTrackID[1] = 0;
200         tempPt->fDigitData[localcount].fTrackID[2] = 0;
201 #endif
202         localcount++;
203         ndigitcounttest++;
204       } //time
205     } //pad 
206
207     if(localcount != fRows[i].fNDigits)
208       LOG(AliL3Log::kFatal,"AliL3TPCBeamTestMemHandler::RawData2Memory","Memory")
209         <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
210         <<fRows[i].fNDigits<<ENDLOG;
211
212     Byte_t *tmp = (Byte_t*)tempPt;
213     Int_t size = sizeof(AliL3DigitRowData)
214       + localcount*sizeof(AliL3DigitData);
215     tmp += size;
216     tempPt = (AliL3DigitRowData*)tmp;
217   }//row
218
219   if(ndigitcount!=ndigitcounttest)
220     LOG(AliL3Log::kError,"AliL3TPCBeamTestMemHandler::RawData2Memory","Digits")
221       <<AliL3Log::kDec<<"Found Inconsistency "<<ndigitcount<<" != "<<ndigitcounttest<<ENDLOG;
222
223   for(Int_t i=0;i<nrowsdummy;i++){
224     delete[] fRows[i].fPadPos;
225   }
226   delete[] fRows;
227   return data;
228 }
229
230 Bool_t AliL3TPCBeamTestMemHandler::RawData2CompBinary(Int_t event)
231 { //raw data to memory
232   Bool_t out = kTRUE;
233   UInt_t ndigits=0;
234   AliL3DigitRowData *digits=0;
235   digits = RawData2Memory(ndigits,event);
236   out = Memory2CompBinary(ndigits,digits);
237   Free();
238   return out;
239 }
240