1 /**************************************************************************
2 * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 #include "AliPHOSCpvRawStream.h"
17 #include "AliRawReader.h"
20 ClassImp(AliPHOSCpvRawStream);
22 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 AliPHOSCpvRawStream::AliPHOSCpvRawStream(AliRawReader* rawReader) :
32 fRawReader(rawReader),
46 Int_t kNDDL = AliPHOSCpvParam::kNDDL;
47 fNumOfErr = new Int_t*[kNDDL]; // Store the number of errors for a given error type and a given DD
48 for(Int_t iddl=0; iddl<kNDDL; iddl++) {
49 fNumOfErr[iddl] = new Int_t [kSumErr];
50 for(Int_t ierr=0; ierr < kSumErr; ierr++) {
51 fNumOfErr[iddl][ierr]=0; // reset errors
55 fnDDLInStream = new Int_t[kNDDL];
56 fnDDLOutStream = new Int_t[kNDDL];
57 for(Int_t i=0; i<kNDDL; i++) {
58 fnDDLInStream [i] = -1;
59 fnDDLOutStream[i] = -1;
63 fRawReader->Select("CPV");
66 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67 AliPHOSCpvRawStream::AliPHOSCpvRawStream() :
88 // Default constructor
90 Int_t kNDDL = AliPHOSCpvParam::kNDDL;
91 fNumOfErr = new Int_t*[kNDDL]; // Store the number of errors for a given error type and a given DD
92 for(Int_t iddl=0; iddl<kNDDL; iddl++) {
93 fNumOfErr[iddl] = new Int_t [kSumErr];
94 for(Int_t ierr=0; ierr < kSumErr; ierr++) {
95 fNumOfErr[iddl][ierr]=0; // reset errors
99 fnDDLInStream = new Int_t[kNDDL];
100 fnDDLOutStream = new Int_t[kNDDL];
101 for(Int_t i=0; i<kNDDL; i++) {
102 fnDDLInStream [i] = -1;
103 fnDDLOutStream[i] = -1;
105 } // Default constructor
106 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107 AliPHOSCpvRawStream::~AliPHOSCpvRawStream()
122 for(Int_t i=0; i<AliPHOSCpvParam::kNDDL; i++) delete [] fNumOfErr[i];
124 delete [] fnDDLInStream;
125 delete [] fnDDLOutStream;
127 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128 void AliPHOSCpvRawStream::Reset()
130 // reset raw stream params
131 // Reinitalize the containers
137 if (fRawReader) fRawReader->Reset();
139 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140 Bool_t AliPHOSCpvRawStream::Turbo()
144 Int_t cntGlob = fRawReader->GetDataSize()/4;
148 //std::cout<<"words to be read: "<<cntGlob<<std::endl;
150 for(Int_t i=1; i<cntGlob; i++) {
151 if (!GetWord(1)) return kFALSE;
152 //std::cout<<"i've passed getWord(1)"<<std::endl;
153 if (fPosition/4 <= 5) continue; // Skip first 5 words
155 row = ((fWord >> kbit22) & 0x1f) - 1;
156 _3G = ((fWord >> kbit18) & 0xf) - 1; // 3GASSIPLEX info in raw word is between bits: 18...21
157 pad = (fWord >> kbit12) & 0x3f; // pad info in raw word is between bits: 12...17
158 //std::cout<<"row = "<<row<<", 3Gassiplex = "<<_3G<<", pad info = "<<pad<<std::endl;
160 Int_t charge, abs, eType;
161 if(!AliPHOSCpvParam::DecodeRawWord(fDDLNumber,fWord,abs,charge,eType)) {
162 if(eType > 0){ fNumOfErr[fDDLNumber][eType]++;
163 //std::cout<<"AliPHOSCpvRawStream::Turbo(): I cannot decode word!"<<std::endl;
164 //cout<<"DDL = "<< fDDLNumber << "; word = "<< fWord <<"; abs = " << abs
165 // <<"; charge = "<< charge <<"; etype = "<< eType << endl;
171 fCharge[fNPads] = charge;
173 if(charge==0) fNumOfErr[fDDLNumber][kPedQZero]++;
174 //Printf("Size: %i DDL %i row %i 3G %i pad %i fPos %i fNPads: %i Charge: %d fWord %4.4x",cntGlob,fDDLNumber,row,_3G,pad,fPosition,fNPads,fCharge[fNPads-1],fWord);
179 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
180 Bool_t AliPHOSCpvRawStream::Next()
182 // read next DDL raw data from the CPV raw data stream
183 // return kFALSE in case of error or no data left
185 AliDebug(1,"Start.");
187 if (!fRawReader->ReadNextData(fData)) return kFALSE;
188 } while (fRawReader->GetDataSize() == 0);
191 Event type is selected as in $ALICE_ROOT/RAW/event.h
192 #define START_OF_RUN ((eventTypeType) 1)
193 #define END_OF_RUN ((eventTypeType) 2)
194 #define START_OF_RUN_FILES ((eventTypeType) 3)
195 #define END_OF_RUN_FILES ((eventTypeType) 4)
196 #define START_OF_BURST ((eventTypeType) 5)
197 #define END_OF_BURST ((eventTypeType) 6)
198 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
199 #define CALIBRATION_EVENT ((eventTypeType) 8)
200 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
201 #define START_OF_DATA ((eventTypeType)10)
202 #define END_OF_DATA ((eventTypeType)11)
203 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
204 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
205 #define EVENT_TYPE_MIN 1
206 #define EVENT_TYPE_MAX 13
210 Bool_t status=kFALSE;
213 if (fRawReader->GetDDLID()>=0)
214 fDDLNumber = fRawReader->GetDDLID();
220 AliWarning(Form("fDDLNumber not a acceptable value %i",fDDLNumber));
224 if(fRawReader->GetType() == 7 || fRawReader->GetType() == 8 ) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
225 fnDDLInStream[fDDLNumber]=1;
226 fnDDLOutStream[fDDLNumber]=0;
228 fLDCNumber = fRawReader->GetLDCId();
229 fTimeStamp = fRawReader->GetTimestamp();
231 fRawDataSize=fRawReader->GetDataSize()/4;
232 DelVars(); //We have to delete the variables initialized in the InitVars before recall InitVars!!!
233 InitVars(fRawDataSize); //To read the charge and pads we cannot delete before the status return
235 if(fTurbo==kTRUE) status=Turbo();
236 else status = ReadCPVRawData(); // If there is any error in raw event, the whole event is thrown away
238 if(status) AliDebug(1,Form("Event DDL %i successfully decoded!.",fDDLNumber));
239 else AliDebug(1,Form("Event DDL %i ERROR in decoding!.",fDDLNumber));
240 //DumpData(fRawReader->GetDataSize());
241 } // if(Select Physics events)
243 if(status==kTRUE) fnDDLOutStream[fDDLNumber]++; //Count the number of events when the DDL was succesfully decoded
247 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
248 void AliPHOSCpvRawStream::InitVars(Int_t n)
251 fCharge = new Int_t[n];
253 fPos = new Int_t[4*n]; //reset debug
254 for(Int_t ie = 0 ; ie < 4*n; ie++) fPos[ie] = 0; //initialize for 0, otherwise the position is considered filled and will not be updated for the dump
257 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
258 void AliPHOSCpvRawStream::DelVars()
260 //Clean the initvars!!!!!!!!
262 if (fCharge) { delete [] fCharge; fCharge = 0x0; }
263 if (fPad) { delete [] fPad; fPad = 0x0; }
264 if (fPos) { delete [] fPos; fPos = 0x0; }
268 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
269 Bool_t AliPHOSCpvRawStream::ReadCPVRawData()
271 //Here the loop on the decoding the raw bank
272 //for one ddl starts.
273 //It returns: kFALSE if any error occurs
275 Int_t cntGlob = fRawReader->GetDataSize()/4;
276 if(cntGlob==0) {fNumOfErr[fDDLNumber][kRawDataSizeErr]++; return kFALSE; }
282 if(!GetWord(cnt)) return kFALSE;
285 while (cnt>20) { //counter limit is changed from 0 to 20 to take into account (skip) the 5 extra words in the equipment header
286 nwSeg = (fWord >> kbit8) & 0xfff;
287 if(!CheckSegment()) return kFALSE;
288 if(!ReadSegment(cntSegment)) return kFALSE;
289 AliDebug(1,"ReadCPVRawData(): ReadSegment() passed");
290 if(nwSeg != cntSegment) return kFALSE;
291 if(!GetWord(cntSegment+1,kBwd)) return kFALSE;
295 } // ReadCPVRawData()
296 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
297 Bool_t AliPHOSCpvRawStream::ReadSegment(Int_t &cntSegment)
300 //It returns: kFALSE if any error occurs
302 cntSegment = (fWord >> kbit8) & 0xfff;
303 Int_t cnt = cntSegment;
307 if(!GetWord(cnt,kBwd)) return kFALSE;
310 // cntRow = (fWord >> kbit16) & 0xfff;
312 if(!CheckRowMarker()) return kFALSE;
313 if(!ReadRow(nwRow)) return kFALSE;
314 if(nwRow != cntRow) {AliDebug(1,Form("Error in Row counters: %i different wrt %i",nwRow,cntRow)); return kFALSE;}
315 if(!GetWord(cntRow+1)) return kFALSE;
321 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
322 Bool_t AliPHOSCpvRawStream::ReadRow(Int_t &cntRow)
325 //It returns: kFALSE if any error occurs
333 // cntRow = (fWord >> kbit16) & 0xfff;
337 if(!GetWord(cntRow)) return kFALSE;
340 if(!CheckEoE(nw3G)) return kFALSE;
341 if(!Read3G(cnt3G)) return kFALSE;
342 if(nw3G != cnt3G) {AliDebug(1,Form("Error in 3gassiplex counters: %i different wrt %i",nw3G,cnt3G));return kFALSE;}
343 if(!GetWord(1,kBwd)) return kFALSE; // go to next 3gassiplex...
351 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
352 Bool_t AliPHOSCpvRawStream::Read3G(Int_t &cnt3G)
354 // Read the 3gassiplex
355 //It returns: kFALSE if any error occurs
358 cnt3G = fWord & 0x7f;
362 for(Int_t i3G=0; i3G<cnt3G; i3G++) {
363 UInt_t _3G = 0, row = 0;
364 if(!GetWord(1,kBwd)) return kFALSE;
365 //check on row number
367 row = ((fWord >> kbit22) & 0x1f) - 1;
368 if(!CheckRow(row)) continue;
369 //check 3gassiplex number
370 _3G = ((fWord >> kbit18) & 0xf) - 1; //3gassiplex info in raw word is between bits: 18...21
371 if(!Check3G(_3G)) continue;
373 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
374 if(!CheckPad(pad)) continue;
375 Int_t charge = fWord & 0xfff;
376 if(AliPHOSCpvParam::Abs(fDDLNumber,row,_3G,pad)<0) continue;
378 fPad[fNPads] = AliPHOSCpvParam::Abs(fDDLNumber,row,_3G,pad);
379 fCharge[fNPads] = charge;
384 AliDebug(1,Form("If PEDESTAL run -> WARNING: ZERO charge is read from DDL: %d row: %d 3G: %d pad: %d",fDDLNumber,row,_3G,pad));
385 fNumOfErr[fDDLNumber][kPedQZero]++;
393 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
394 Bool_t AliPHOSCpvRawStream::CheckSegment()
396 // Check the segment marker
397 // It returns: kFALSE if any error occurs
400 UInt_t markSegment = 0xAB0;
401 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
403 if (segMarker != markSegment ) {
404 AliDebug(1,Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
405 fNumOfErr[fDDLNumber][kWrongSegErr]++;
409 UInt_t segAddress = fWord & 0xff;
410 if (segAddress<1 ||segAddress>3) {
411 AliDebug(1,Form("Segment address %d not in the valid range [1-3]",segAddress));
412 fNumOfErr[fDDLNumber][kWrongSegErr]++;
417 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
418 Bool_t AliPHOSCpvRawStream::CheckRow(UInt_t row)
420 //check on row number
421 //It returns: kFALSE if any error occurs
423 if(row>=0 && row <AliPHOSCpvParam::kNRows) return kTRUE;
424 AliDebug(1,Form("Wrong row index: %d, expected (0 -> %d) word %0X at %i...",row,AliPHOSCpvParam::kNRows-1,fWord,fPosition));
425 fNumOfErr[fDDLNumber][kWrongRowErr]++;
428 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
429 Bool_t AliPHOSCpvRawStream::Check3G(UInt_t _3G)
431 //check 3gassiplex number
432 //It returns: kFALSE if any error occurs
434 if (_3G>= 0 && _3G <AliPHOSCpvParam::kN3GAdd) return kTRUE;
435 AliDebug(1,Form("Wrong 3GASSIPLEX index: %d, expected (0 -> %d)!",_3G,AliPHOSCpvParam::kN3GAdd-1));
436 fNumOfErr[fDDLNumber][kWrong3GErr]++;
439 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
440 Bool_t AliPHOSCpvRawStream::CheckPad(UInt_t pad)
443 //It returns: kFALSE if any error occurs
445 if (pad < AliPHOSCpvParam::kNPadAdd) return kTRUE;
446 AliDebug(1,Form("Wrong pad index: %d, expected (0 -> %d)!",pad,AliPHOSCpvParam::kNPadAdd - 1));
447 fNumOfErr[fDDLNumber][kWrongPadErr]++;
450 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
451 Bool_t AliPHOSCpvRawStream::CheckEoE(Int_t &nDil)
453 //check the End of Event
454 // "End of event" is not end of event. It checks subordinate words between 3gassiplex blocks
455 //It returns: kFALSE if any error occurs
458 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
459 AliDebug(1,Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition/4));
460 fNumOfErr[fDDLNumber][kEoEFlagErr]++;
463 nDil = fWord & 0x7f; //nDil=EoE word count
464 if(nDil < 0 || nDil > 48 ) {
465 AliDebug(1,Form("Wrong end-of-event word-count: %08X",fWord));
466 fNumOfErr[fDDLNumber][kEoESizeErr]++;
471 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
472 Bool_t AliPHOSCpvRawStream::CheckRowMarker()
474 //check the row marker
475 //It returns: kFALSE if any error occurs
477 UInt_t nMAXwordsInRow = 0x1EA;
478 UInt_t statusControlRow = 0x32A8; // 0x36A8 for zero suppression
479 //First check on row marker
480 UInt_t rowControlWord = fWord >> kbit0 & 0xffff;
482 if((fWord >> kbit27) & 0x1) return kTRUE;
484 if(rowControlWord != statusControlRow) {
485 AliDebug(1,Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
486 fNumOfErr[fDDLNumber][kRowMarkerErr]++;
490 //Second check on row marker
491 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker, bit 10 is skipped in this check
493 if (wordsInRow > nMAXwordsInRow) {
494 AliDebug(1,Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));
495 fNumOfErr[fDDLNumber][kRowMarkerSizeErr]++;
501 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
502 Bool_t AliPHOSCpvRawStream::GetWord(Int_t n,EDirection dir)
504 // This method returns the n-th 32 bit word
505 // inside the raw data payload.
506 // The method is supposed to be platform independent.
510 AliError("fPosition < 0 !!! Event skipped.");
511 fRawReader->AddMajorErrorLog(kRawDataSizeErr,"fPosition<0");
515 if(dir==kBwd) n = -n;
518 if(fPosition == -4) return kTRUE;
520 if(fPosition<0 || fPosition > fRawReader->GetDataSize()) {
521 AliWarning(Form("fPosition out of boundaries %i",fPosition));
527 fWord |= fData[fPosition++];
528 fWord |= fData[fPosition++] << 8;
529 fWord |= fData[fPosition++] << 16;
530 fWord |= fData[fPosition++] << 24;
534 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
535 void AliPHOSCpvRawStream::DumpData(Int_t nw)
537 //just a simple raw data dump
538 // in () is the position in bytes
540 for(Int_t i=0;i<nw;i+=4) {
541 if(!(i%16)) printf(" \n %8i) ",i);
542 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
544 Printf(" \n -----end of dump ----------- ");
546 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
547 void AliPHOSCpvRawStream::StorePosition()
549 //just for debug purpose
550 // it stores the position
551 //read for the first time
552 // Printf("@@@@@@@@@ fPos: %x fPosition: %d",fPos,fPosition);
553 if(fPos[fPosition]!=0) {
554 // Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
558 fPos[fPosition] = fiPos;
559 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);