3 /** \class AliL3TPCBeamTestMemHandler
5 //_____________________________________________________________
6 // AliL3TPCBeamTestMemHandler
8 // Class for converting the test beam data of May 2004
9 // to the HLT file format using R. Bramms tables.
11 // Author: C. Loizides <loizides@ikf.uni-frankfurt.de>
12 // -- Copyright © ALICE HLT Group
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"
29 ClassImp(AliL3TPCBeamTestMemHandler)
31 AliL3TPCBeamTestMemHandler::AliL3TPCBeamTestMemHandler(Char_t *fPathToMappingFile) : AliL3MemHandler()
35 fNumOfChannels=7807+1; //must be big enough to contain all channels (per patch)
37 Char_t readcarry[255];
40 ifstream *in = new ifstream();
41 in->open(fPathToMappingFile);
42 #if defined(__HP_aCC) || defined(__DECCXX)
43 if(!in->rdbuf()->is_open()){
47 LOG(AliL3Log::kFatal,"AliL3TPCBeamTestMemHandler","Mapping File")
48 <<"Can't open file " << fPathToMappingFile << " !!!" <<ENDLOG;
50 fMapping = new short*[fNumOfChannels];
51 for ( Int_t i = 0; i < fNumOfChannels; i++ )
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;
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++) {
62 mappingRow[j] = atoi(readcarry);
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;
77 AliL3TPCBeamTestMemHandler::~AliL3TPCBeamTestMemHandler()
80 for(Int_t i = 0; i < 5504 ; i++) {
81 if(fMapping[i] != fMappingEmptyRow && fMapping[i]) delete[] fMapping[i];
83 delete [] fMappingEmptyRow;
87 AliL3DigitRowData* AliL3TPCBeamTestMemHandler::RawData2Memory(UInt_t &nrow,Int_t /*event*/)
89 //convert the raw data
90 AliL3DigitRowData *data = 0;
93 Int_t nrowsdummy=AliL3Transform::GetNRows(fPatch);
94 fRows = new AliRowStructure[nrowsdummy];
95 for(Int_t i=0;i<nrowsdummy;i++){
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;
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){
118 Bool_t isThereDataOnThisPad=kFALSE;
121 for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
122 Int_t dig=fInputPtr[pos+timebin];
125 digmean/=(ntimebins-fMinTimeBin+1);
129 for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
130 Int_t dig=fInputPtr[pos+timebin]-digmean;
132 if(dig <= AliL3Transform::GetZeroSup()) continue;
133 if(dig >= AliL3Transform::GetADCSat())
134 dig = AliL3Transform::GetADCSat();
136 fRows[lrow].fNDigits++; //for this row only
138 isThereDataOnThisPad=kTRUE;
141 if(isThereDataOnThisPad) {
142 fRows[lrow].fPadPos[pad]=pos;
147 for(Int_t i=0;i<AliL3Transform::GetNRows(fPatch);i++){
148 if(fRows[i].fRow!=-1) nrows++;
150 if(nrows!=AliL3Transform::GetNRows(fPatch))
151 LOG(AliL3Log::kError,"AliL3TPCBeamTestMemHandler::RawData2Memory","nrows")
152 <<AliL3Log::kDec<<"Found Inconsistency "<<nrows<<" != "<<AliL3Transform::GetNRows(fPatch)<<ENDLOG;
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;
160 data=(AliL3DigitRowData*)Allocate(size);
161 nrow = (UInt_t)nrows;
162 //memset(data,1,size); //for debugging
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;
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;
175 tempPt->fRow = slrow;
176 tempPt->fNDigit = fRows[i].fNDigits;
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;
184 for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
185 Int_t dig=fInputPtr[pos+timebin];
188 digmean/=(ntimebins-fMinTimeBin+1);
192 for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
193 Int_t dig=fInputPtr[pos+timebin]-digmean;
195 if(dig <= AliL3Transform::GetZeroSup()) continue;
196 if(dig >= AliL3Transform::GetADCSat())
197 dig = AliL3Transform::GetADCSat();
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;
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;
208 tempPt->fDigitData[localcount].fTrackID[0] = 0;
209 tempPt->fDigitData[localcount].fTrackID[1] = 0;
210 tempPt->fDigitData[localcount].fTrackID[2] = 0;
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;
222 Byte_t *tmp = (Byte_t*)tempPt;
223 Int_t size = sizeof(AliL3DigitRowData)
224 + localcount*sizeof(AliL3DigitData);
226 tempPt = (AliL3DigitRowData*)tmp;
229 if(ndigitcount!=ndigitcounttest)
230 LOG(AliL3Log::kError,"AliL3TPCBeamTestMemHandler::RawData2Memory","Digits")
231 <<AliL3Log::kDec<<"Found Inconsistency "<<ndigitcount<<" != "<<ndigitcounttest<<ENDLOG;
233 for(Int_t i=0;i<nrowsdummy;i++){
234 delete[] fRows[i].fPadPos;
240 Bool_t AliL3TPCBeamTestMemHandler::RawData2CompBinary(Int_t event)
245 AliL3DigitRowData *digits=0;
246 digits = RawData2Memory(ndigits,event);
247 out = Memory2CompBinary(ndigits,digits);