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