]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/src/AliHLTTPCBeamTestMemHandler.cxx
Bogdan: new version of MUON visualization.
[u/mrichter/AliRoot.git] / HLT / src / AliHLTTPCBeamTestMemHandler.cxx
CommitLineData
0167aa42 1// @(#) $Id$
2
4aa41877 3/** \class AliHLTTPCBeamTestMemHandler
0167aa42 4<pre>
5//_____________________________________________________________
4aa41877 6// AliHLTTPCBeamTestMemHandler
0167aa42 7//
08a8b491 8// Class for converting the test beam data of May 2004
9// to the HLT file format using R. Bramms tables.
10//
0167aa42 11// Author: C. Loizides <loizides@ikf.uni-frankfurt.de>
a340b024 12// -- Copyright &copy ALICE HLT Group
0167aa42 13</pre>
14*/
15
4aa41877 16#include "AliHLTStandardIncludes.h"
17#include "AliHLTRootTypes.h"
18#include "AliHLTLogging.h"
19#include "AliHLTTransform.h"
20#include "AliHLTMemHandler.h"
21#include "AliHLTDigitData.h"
22#include "AliHLTTPCBeamTestMemHandler.h"
0167aa42 23
5929c18d 24#if __GNUC__ >= 3
0167aa42 25using namespace std;
26#endif
27
28
4aa41877 29ClassImp(AliHLTTPCBeamTestMemHandler)
0167aa42 30
4aa41877 31AliHLTTPCBeamTestMemHandler::AliHLTTPCBeamTestMemHandler(Char_t *fPathToMappingFile) : AliHLTMemHandler()
08a8b491 32{
33 //constructor
0167aa42 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);
0a8ce496 42#if defined(__HP_aCC) || defined(__DECCXX)
c0ea2865 43 if(!in->rdbuf()->is_open()){
0a8ce496 44#else
0167aa42 45 if(!in->is_open()){
0a8ce496 46#endif
4aa41877 47 LOG(AliHLTLog::kFatal,"AliHLTTPCBeamTestMemHandler","Mapping File")
0167aa42 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
4aa41877 77AliHLTTPCBeamTestMemHandler::~AliHLTTPCBeamTestMemHandler()
08a8b491 78{
79 //destructor
0167aa42 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
4aa41877 87AliHLTDigitRowData* AliHLTTPCBeamTestMemHandler::RawData2Memory(UInt_t &nrow,Int_t /*event*/)
08a8b491 88{
89 //convert the raw data
4aa41877 90 AliHLTDigitRowData *data = 0;
0167aa42 91 nrow=0;
92
4aa41877 93 Int_t nrowsdummy=AliHLTTransform::GetNRows(fPatch);
08a8b491 94 fRows = new AliRowStructure[nrowsdummy];
0167aa42 95 for(Int_t i=0;i<nrowsdummy;i++){
96 fRows[i].fRow=-1;
97 fRows[i].fNDigits=0;
4aa41877 98 fRows[i].fPadPos= new Int_t[AliHLTTransform::GetNPads(i+fRowMin)];
99 for(Int_t p=0;p<AliHLTTransform::GetNPads(i+fRowMin);p++)
0167aa42 100 fRows[i].fPadPos[p]=-1;
101 }
102
4aa41877 103 Int_t ntimebins=AliHLTTransform::GetNTimeBins();
0167aa42 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
4aa41877 132 if(dig <= AliHLTTransform::GetZeroSup()) continue;
133 if(dig >= AliHLTTransform::GetADCSat())
134 dig = AliHLTTransform::GetADCSat();
0167aa42 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;
4aa41877 147 for(Int_t i=0;i<AliHLTTransform::GetNRows(fPatch);i++){
0167aa42 148 if(fRows[i].fRow!=-1) nrows++;
149 }
4aa41877 150 if(nrows!=AliHLTTransform::GetNRows(fPatch))
151 LOG(AliHLTLog::kError,"AliHLTTPCBeamTestMemHandler::RawData2Memory","nrows")
152 <<AliHLTLog::kDec<<"Found Inconsistency "<<nrows<<" != "<<AliHLTTransform::GetNRows(fPatch)<<ENDLOG;
0167aa42 153
154 //allocate memory
4aa41877 155 Int_t size = sizeof(AliHLTDigitData)*ndigitcount
156 + nrows*sizeof(AliHLTDigitRowData);
157 LOG(AliHLTLog::kDebug,"AliHLTTPCBeamTestMemHandler::RawData2Memory","Digits")
158 <<AliHLTLog::kDec<<"Found "<<ndigitcount<<" Digits on "<<nrows<<" rows"<<ENDLOG;
0167aa42 159
4aa41877 160 data=(AliHLTDigitRowData*)Allocate(size);
0167aa42 161 nrow = (UInt_t)nrows;
162 //memset(data,1,size); //for debugging
163
164 Int_t ndigitcounttest=0;
4aa41877 165 AliHLTDigitRowData *tempPt = data;
166 for(Int_t i=0;i<AliHLTTransform::GetNRows(fPatch);i++){
0167aa42 167 Int_t slrow=i+fRowMin;
168
169 if(slrow!=fRows[i].fRow){
4aa41877 170 LOG(AliHLTLog::kFatal,"AliHLTTPCBeamTestMemHandler::RawData2Memory","Row Mismatch")
171 <<AliHLTLog::kDec<<"Mismatch: slrow "<<slrow<<" row "
0167aa42 172 <<fRows[i].fRow<<ENDLOG;
173 }
174
175 tempPt->fRow = slrow;
176 tempPt->fNDigit = fRows[i].fNDigits;
177
178 Int_t localcount=0;
4aa41877 179 for(Int_t pad=0;pad<AliHLTTransform::GetNPads(slrow);pad++){
0167aa42 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
4aa41877 195 if(dig <= AliHLTTransform::GetZeroSup()) continue;
196 if(dig >= AliHLTTransform::GetADCSat())
197 dig = AliHLTTransform::GetADCSat();
0167aa42 198
199 //Exclude data outside cone:
4aa41877 200 //AliHLTTransform::Raw2Local(xyz,sector,row,pad,time);
0167aa42 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)
4aa41877 218 LOG(AliHLTLog::kFatal,"AliHLTTPCBeamTestMemHandler::RawData2Memory","Memory")
219 <<AliHLTLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
0167aa42 220 <<fRows[i].fNDigits<<ENDLOG;
221
222 Byte_t *tmp = (Byte_t*)tempPt;
4aa41877 223 Int_t size = sizeof(AliHLTDigitRowData)
224 + localcount*sizeof(AliHLTDigitData);
0167aa42 225 tmp += size;
4aa41877 226 tempPt = (AliHLTDigitRowData*)tmp;
0167aa42 227 }//row
228
229 if(ndigitcount!=ndigitcounttest)
4aa41877 230 LOG(AliHLTLog::kError,"AliHLTTPCBeamTestMemHandler::RawData2Memory","Digits")
231 <<AliHLTLog::kDec<<"Found Inconsistency "<<ndigitcount<<" != "<<ndigitcounttest<<ENDLOG;
0167aa42 232
233 for(Int_t i=0;i<nrowsdummy;i++){
234 delete[] fRows[i].fPadPos;
235 }
236 delete[] fRows;
237 return data;
238}
239
4aa41877 240Bool_t AliHLTTPCBeamTestMemHandler::RawData2CompBinary(Int_t event)
08a8b491 241{
242 //raw data to memory
0167aa42 243 Bool_t out = kTRUE;
244 UInt_t ndigits=0;
4aa41877 245 AliHLTDigitRowData *digits=0;
0167aa42 246 digits = RawData2Memory(ndigits,event);
247 out = Memory2CompBinary(ndigits,digits);
248 Free();
249 return out;
250}
251