3 /** \class AliL3TPCBeamTestMemHandler
5 //_____________________________________________________________
6 // AliL3TPCBeamTestMemHandler
8 // Author: C. Loizides <loizides@ikf.uni-frankfurt.de>
9 // -- Copyright © ALICE HLT Group
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"
26 ClassImp(AliL3TPCBeamTestMemHandler)
28 AliL3TPCBeamTestMemHandler::AliL3TPCBeamTestMemHandler(Char_t *fPathToMappingFile) : AliL3MemHandler()
31 fNumOfChannels=7807+1; //must be big enough to contain all channels (per patch)
33 Char_t readcarry[255];
36 ifstream *in = new ifstream();
37 in->open(fPathToMappingFile);
39 LOG(AliL3Log::kFatal,"AliL3TPCBeamTestMemHandler","Mapping File")
40 <<"Can't open file " << fPathToMappingFile << " !!!" <<ENDLOG;
42 fMapping = new short*[fNumOfChannels];
43 for ( Int_t i = 0; i < fNumOfChannels; i++ )
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;
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++) {
54 mappingRow[j] = atoi(readcarry);
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;
69 AliL3TPCBeamTestMemHandler::~AliL3TPCBeamTestMemHandler()
71 for(Int_t i = 0; i < 5504 ; i++) {
72 if(fMapping[i] != fMappingEmptyRow && fMapping[i]) delete[] fMapping[i];
74 delete [] fMappingEmptyRow;
78 AliL3DigitRowData* AliL3TPCBeamTestMemHandler::RawData2Memory(UInt_t &nrow,Int_t /*event*/)
79 { //convert the raw data
80 AliL3DigitRowData *data = 0;
83 Int_t nrowsdummy=AliL3Transform::GetNRows(fPatch);
84 fRows = new RowStructure[nrowsdummy];
85 for(Int_t i=0;i<nrowsdummy;i++){
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;
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){
108 Bool_t isThereDataOnThisPad=kFALSE;
111 for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
112 Int_t dig=fInputPtr[pos+timebin];
115 digmean/=(ntimebins-fMinTimeBin+1);
119 for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
120 Int_t dig=fInputPtr[pos+timebin]-digmean;
122 if(dig <= AliL3Transform::GetZeroSup()) continue;
123 if(dig >= AliL3Transform::GetADCSat())
124 dig = AliL3Transform::GetADCSat();
126 fRows[lrow].fNDigits++; //for this row only
128 isThereDataOnThisPad=kTRUE;
131 if(isThereDataOnThisPad) {
132 fRows[lrow].fPadPos[pad]=pos;
137 for(Int_t i=0;i<AliL3Transform::GetNRows(fPatch);i++){
138 if(fRows[i].fRow!=-1) nrows++;
140 if(nrows!=AliL3Transform::GetNRows(fPatch))
141 LOG(AliL3Log::kError,"AliL3TPCBeamTestMemHandler::RawData2Memory","nrows")
142 <<AliL3Log::kDec<<"Found Inconsistency "<<nrows<<" != "<<AliL3Transform::GetNRows(fPatch)<<ENDLOG;
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;
150 data=(AliL3DigitRowData*)Allocate(size);
151 nrow = (UInt_t)nrows;
152 //memset(data,1,size); //for debugging
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;
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;
165 tempPt->fRow = slrow;
166 tempPt->fNDigit = fRows[i].fNDigits;
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;
174 for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
175 Int_t dig=fInputPtr[pos+timebin];
178 digmean/=(ntimebins-fMinTimeBin+1);
182 for(Int_t timebin = fMinTimeBin ; timebin <= ntimebins ; timebin++){
183 Int_t dig=fInputPtr[pos+timebin]-digmean;
185 if(dig <= AliL3Transform::GetZeroSup()) continue;
186 if(dig >= AliL3Transform::GetADCSat())
187 dig = AliL3Transform::GetADCSat();
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;
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;
198 tempPt->fDigitData[localcount].fTrackID[0] = 0;
199 tempPt->fDigitData[localcount].fTrackID[1] = 0;
200 tempPt->fDigitData[localcount].fTrackID[2] = 0;
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;
212 Byte_t *tmp = (Byte_t*)tempPt;
213 Int_t size = sizeof(AliL3DigitRowData)
214 + localcount*sizeof(AliL3DigitData);
216 tempPt = (AliL3DigitRowData*)tmp;
219 if(ndigitcount!=ndigitcounttest)
220 LOG(AliL3Log::kError,"AliL3TPCBeamTestMemHandler::RawData2Memory","Digits")
221 <<AliL3Log::kDec<<"Found Inconsistency "<<ndigitcount<<" != "<<ndigitcounttest<<ENDLOG;
223 for(Int_t i=0;i<nrowsdummy;i++){
224 delete[] fRows[i].fPadPos;
230 Bool_t AliL3TPCBeamTestMemHandler::RawData2CompBinary(Int_t event)
231 { //raw data to memory
234 AliL3DigitRowData *digits=0;
235 digits = RawData2Memory(ndigits,event);
236 out = Memory2CompBinary(ndigits,digits);