By default, propagate picked element to its projectable.
[u/mrichter/AliRoot.git] / ZDC / AliZDCRawStream.cxx
CommitLineData
8309c1ab 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
83347831 19// //
20// This class provides access to ZDC digits in raw data. //
21// //
22// It loops over all ZDC digits in the raw data given by the AliRawReader. //
23// The Next method goes to the next digit. If there are no digits left //
24// it returns kFALSE. //
25// Getters provide information about the current digit. //
26// //
8309c1ab 27///////////////////////////////////////////////////////////////////////////////
28
29#include "AliZDCRawStream.h"
30#include "AliRawReader.h"
1ee299a5 31#include "AliRawDataHeader.h"
32#include "AliRawEventHeaderBase.h"
cc2abffd 33#include "AliLog.h"
8309c1ab 34
35ClassImp(AliZDCRawStream)
36
37
38//_____________________________________________________________________________
39AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
40 fRawReader(rawReader),
1ee299a5 41 fBuffer(0),
42 fEvType(0),
43 fPosition(0),
44 fIsCalib(kFALSE),
45 fIsDARCHeader(kFALSE),
46 fIsChMapping(kFALSE),
47 fIsADCDataWord(kFALSE),
48 fIsADCHeader(kFALSE),
49 fIsADCEOB(kFALSE),
50 fDARCEvBlockLenght(0),
51 fDARCBlockAttributes(0),
52 fDeadfaceOffset(0),
53 fDeadbeefOffset(0),
54 fDataOffset(0),
55 fModType(-1),
56 fADCModule(-1),
57 fADCNChannels(-1),
786b72f5 58 fADCChannel(-1),
cc2abffd 59 fADCValue(-1),
1ee299a5 60 fADCGain(-1),
61 fNConnCh(-1),
62 fCabledSignal(-1)
8309c1ab 63{
abf60186 64 // Create an object to read ZDC raw digits
1ee299a5 65 fRawReader->Reset();
362c9d61 66 fRawReader->Select("ZDC");
1ee299a5 67 //
68 for(Int_t i=0; i<48; i++){
c93c022b 69 for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
1ee299a5 70 }
71
8309c1ab 72}
73
74//_____________________________________________________________________________
75AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
a718c993 76 TObject(stream),
c61a7285 77 fRawReader(stream.fRawReader),
1ee299a5 78 fBuffer(stream.GetRawBuffer()),
79 fEvType(stream.fEvType),
80 fPosition(stream.fPosition),
81 fIsCalib(stream.fIsCalib),
82 fIsDARCHeader(stream.fIsDARCHeader),
83 fIsChMapping(stream.fIsChMapping),
84 fIsADCDataWord(stream.fIsADCDataWord),
85 fIsADCHeader(stream.fIsADCHeader),
86 fIsADCEOB(stream.fIsADCEOB),
87 fDARCEvBlockLenght(stream.fDARCEvBlockLenght),
88 fDARCBlockAttributes(stream.fDARCBlockAttributes),
89 fDeadfaceOffset(stream.GetDeadfaceOffset()),
90 fDeadbeefOffset(stream.GetDeadbeefOffset()),
91 fDataOffset(stream.GetDataOffset()),
92 fModType(stream.GetModType()),
a718c993 93 fADCModule(stream.GetADCModule()),
1ee299a5 94 fADCNChannels(stream.GetADCNChannels()),
a718c993 95 fADCChannel(stream.GetADCChannel()),
96 fADCValue(stream.GetADCValue()),
97 fADCGain(stream.GetADCGain()),
1ee299a5 98 fNConnCh(stream.fNConnCh),
99 fCabledSignal(stream.GetCabledSignal())
8309c1ab 100{
abf60186 101 // Copy constructor
c0aec6f6 102 for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);
1ee299a5 103 for(Int_t i=0; i<48; i++){
c93c022b 104 for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
1ee299a5 105 }
8309c1ab 106}
107
108//_____________________________________________________________________________
109AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
110 /* stream */)
111{
abf60186 112 // Assignment operator
8309c1ab 113 Fatal("operator =", "assignment operator not implemented");
114 return *this;
115}
116
117//_____________________________________________________________________________
118AliZDCRawStream::~AliZDCRawStream()
119{
abf60186 120// Destructor
8309c1ab 121
122}
123
1ee299a5 124//_____________________________________________________________________________
c93c022b 125void AliZDCRawStream::ReadChMap()
126{
127 // Reading channel map
128}
129
130//_____________________________________________________________________________
1ee299a5 131void AliZDCRawStream::ReadCDHHeader()
132{
133 // Reading CDH
134 const AliRawDataHeader* header = fRawReader->GetDataHeader();
135 if(!header) {
136 AliError("\t No CDH in raw data streaming\n");
137 fRawReader->AddMajorErrorLog(kCDHError);
138 //
139 // For the moment to debug the classe the event is read
140 // also if the CDH is not present in the data buffer
141 // ******* TO BE CHANGED!!! ***************************
142 //return;
143 }
144 else{
145 //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
146
147 fDARCEvBlockLenght = header->fSize;
148 //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
149
150 //UChar_t message = header->GetAttributes();
151 //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
152
153 /*if(message & 0x10){ // COSMIC RUN
154 printf("\t STANDALONE_COSMIC RUN raw data found\n");
155 }
156 else if(message & 0x20){ // PEDESTAL RUN
157 printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
158 }
159 else if(message & 0x30){ // LASER RUN
160 printf("\t STANDALONE_LASER RUN raw data found\n");
161 }*/
162
163 if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
164 fIsCalib = kTRUE;
165 }
166 //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
c93c022b 167 //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);
1ee299a5 168
169 UInt_t status = header->GetStatus();
170 //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
171 if(status & 0x000f == 0x0001){
172 AliWarning("CDH -> DARC trg0 overlap error\n");
173 fRawReader->AddMajorErrorLog(kDARCError);
174 }
175 if(status & 0x000f == 0x0002){
176 AliWarning("CDH -> DARC trg0 missing error\n");
177 fRawReader->AddMajorErrorLog(kDARCError);
178 }
179 if(status & 0x000f == 0x0004){
180 AliWarning("CDH -> DARC data parity error\n");
181 fRawReader->AddMajorErrorLog(kDARCError);
182 }
183 if(status & 0x000f == 0x0008){
184 AliWarning("CDH -> DARC ctrl parity error\n");
185 fRawReader->AddMajorErrorLog(kDARCError);
186 }
187 //
188 if(status & 0x00f0 == 0x0010){
189 AliWarning("CDH -> DARC trg unavailable\n");
190 fRawReader->AddMajorErrorLog(kDARCError);
191 }
192 if(status & 0x00f0 == 0x0020){
193 AliWarning("CDH -> DARC FEE error\n");
194 fRawReader->AddMajorErrorLog(kDARCError);
195 }
196 //
197 if(status & 0x0f00 == 0x0200){
198 AliWarning("CDH -> DARC L1 time violation\n");
199 fRawReader->AddMajorErrorLog(kDARCError);
200 }
201 if(status & 0x0f00 == 0x0400){
202 AliWarning("CDH -> DARC L2 time-out\n");
203 fRawReader->AddMajorErrorLog(kDARCError);
204 }
205 if(status & 0x0f00 == 0x0800){
206 AliWarning("CDH -> DARC prepulse time violation\n");
207 fRawReader->AddMajorErrorLog(kDARCError);
208 }
209 //
210 if(status & 0xf000 == 0x1000){
211 AliWarning("CDH -> DARC other error\n");
212 fRawReader->AddMajorErrorLog(kDARCError);
213 }
214 }
215 //
216 fIsDARCHeader = kTRUE;
217}
218
8309c1ab 219
220//_____________________________________________________________________________
221Bool_t AliZDCRawStream::Next()
222{
abf60186 223 // Read the next raw digit
224 // Returns kFALSE if there is no digit left
8309c1ab 225
1ee299a5 226 if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
227 fIsChMapping = kFALSE; fIsADCHeader = kFALSE;
228 fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
229
230 fEvType = fRawReader->GetType();
231 //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
232
233 if(fPosition==0){
234 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
235 //ReadEventHeader();
236 ReadCDHHeader();
237 //}
238 fNConnCh=0;
239 }
240 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
241
242 // -------------------------------------------
1069e28d 243 // --- DARC header
1ee299a5 244 // -------------------------------------------
245 if(fIsDARCHeader){
84d2abc2 246 //printf("\t ---- DARC header ----\n");
1ee299a5 247 if(fIsCalib){
248 fDeadfaceOffset = 9;
249 fDeadbeefOffset = 25;
250 }
251 else{
252 fDeadfaceOffset = 1;
253 fDeadbeefOffset = 7;
254 }
255 fDataOffset = 1+fDeadbeefOffset;
256 fIsDARCHeader = kFALSE;
abf60186 257 }
1ee299a5 258
259
260 // -------------------------------------------
261 // --- Start of data event
262 // --- decoding mapping of connected ADC ch.
263 // -------------------------------------------
264 if(fEvType==10){
265 if(fPosition>fDataOffset){
266 if((fBuffer&0xff000000) == 0xff000000){
267 if(fPosition==(fDataOffset+1)){
268 printf("\n\n\t Reading ZDC mapping from StartOfData event\n");
269 fNConnCh=0;
6006df88 270 }
1ee299a5 271 else{
84d2abc2 272 //printf("\n\t End of StartOfData event\n\n");
1ee299a5 273 return kTRUE;
274 }
275 }
276 else if((fBuffer&0x80000000)>>31 == 1){
277 // Mapping identification
278 fADCModule = ((fBuffer & 0x7f000000)>>24);
279 fModType = ((fBuffer & 0xfff000)>>8);
280 fADCNChannels = (fBuffer & 0xff);
281 //
282 //printf("\tGEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
6006df88 283 }
1ee299a5 284 else if(fModType==0 && (fBuffer&0x80000000)>>31 == 0){
285 // Channel signal
286 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
287 fIsChMapping = kTRUE;
288 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
289 fCabledSignal = (fBuffer&0xffff);
290 fMapADC[fNConnCh][0] = fADCModule;
291 fMapADC[fNConnCh][1] = fADCChannel;
292 fMapADC[fNConnCh][2] = fCabledSignal;
c93c022b 293 //
294 // Determining detector and sector
295 // -----------------------------------------
296 // For the decoding of the following lines
297 // look the enum in AliZDCRawStream.h file
298 // -----------------------------------------
299 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
300 || fCabledSignal==24 || fCabledSignal==48){
301 fMapADC[fNConnCh][3] = 4;
302 //
303 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
304 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
305 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
306 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
307 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
308 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
309 }
310 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
311 fMapADC[fNConnCh][3] = 5;
312 //
313 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
314 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
315 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
316 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
317 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
318 }
319 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
320 || fCabledSignal==25 || fCabledSignal==49){
321 fMapADC[fNConnCh][3] = 3;
322 //
323 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
324 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
325 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
326 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
327 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
328 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
329 }
330 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
331 fMapADC[fNConnCh][3] = 1;
332 //
333 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
334 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
335 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
336 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
337 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
338 }
339 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
340 fMapADC[fNConnCh][3] = 2;
341 //
342 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
343 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
344 }
345 //
346 //printf("AliZDCRawStream -> datum %d mod. %d ch. %d signal %d, det %d, tow %d\n",
347 // fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
1ee299a5 348 //
349 fNConnCh++;
350 if(fNConnCh>48){
351 // Protection manually set since it returns:
352 // RawData48 mod. 3 ch. 2048 signal 515
353 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
354 AliWarning("\t AliZDCRawStream -> ERROR: no. of cabled channels > 48!!!\n");
355 return kFALSE;
356 }
357 }
1069e28d 358 }
1ee299a5 359 }
360 fPosition++;
361 return kTRUE;
362 }
363
364 // -------------------------------------------
365 // --- DARC data
366 // -------------------------------------------
367 if(fPosition<fDeadfaceOffset){
368 fPosition++;
369 return kTRUE;
370 }
371 else if(fPosition==fDeadfaceOffset){
372 if(fBuffer != 0xdeadface){
373 AliWarning("AliZDCRawStream -> NO deadface after DARC data\n");
374 fRawReader->AddMajorErrorLog(kDARCError);
375 }
376 else{
377 fPosition++;
378 return kTRUE;
379 }
380 }
381
382 // -------------------------------------------
383 // --- DARC global data
384 // -------------------------------------------
385 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
386 fPosition++;
387 return kTRUE;
388 }
389 else if(fPosition==fDeadbeefOffset){
390 if(fBuffer != 0xdeadbeef){
391 AliWarning("AliZDCRawStream -> NO deadbeef after DARC global data\n");
392 fRawReader->AddMajorErrorLog(kDARCError);
393 }
394 else{
395 fPosition++;
396 return kTRUE;
397 }
398 }
399
400 // -------------------------------------------
401 // --- ZDC data
402 // --- ADC buffer + scaler
403 // -------------------------------------------
404 else if(fPosition>=fDataOffset){
405
406 // Not valid datum before the event
407 // there MUST be a NOT valid datum before the event!!!
408 if(fPosition==fDataOffset){
84d2abc2 409 //printf("\t **** ZDC data begin ****\n");
1ee299a5 410 if((fBuffer & 0x07000000) == 0x06000000){
411 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
412 // "position %d in word data buffer\n",fADCModule,fPosition);
413 }
414 else fRawReader->AddMajorErrorLog(kZDCDataError);
415 }
416
417 // If the not valid datum isn't followed by the 1st ADC header
418 // the event is corrupted (i.e., 2 gates arrived before trigger)
419 else if(fPosition==fDataOffset+1){
420 if((fBuffer & 0x07000000) != 0x02000000){
421 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!\n");
422 fRawReader->AddMajorErrorLog(kZDCDataError);
423 }
424 }
425
426 // Get geo address of current word to determine
427 // if it is a scaler word (geo address == kScalerAddress)
428 // if it is an ADC word (geo address != 8)
429 Int_t kScalerAddress=8;
430 fADCModule = ((fBuffer & 0xf8000000)>>27);
431 if(fADCModule == kScalerAddress){
432 DecodeScaler();
433 }
434 else{//ADC module
435 // *** End of event
436 if(fBuffer == 0xcafefade){
84d2abc2 437 //printf(" AliZDCRawStream -> End of ZDC event!\n");
1ee299a5 438 }
439 // *** ADC header
440 else if((fBuffer & 0x07000000) == 0x02000000){
441 fIsADCHeader = kTRUE;
442 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
84d2abc2 443 //printf(" AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
1ee299a5 444 }
445 // *** ADC data word
446 else if((fBuffer & 0x07000000) == 0x00000000){
447 fIsADCDataWord = kTRUE;
448 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
449 fADCGain = ((fBuffer & 0x10000) >> 16);
450 fADCValue = (fBuffer & 0xfff);
451
84d2abc2 452 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
453 // fADCModule,fADCChannel,fADCGain,fADCValue);
1ee299a5 454
455 // Valid ADC data (not underflow nor overflow)
456 if(!(fBuffer & 0x1000) && !(fBuffer & 0x2000)){
c93c022b 457
458 // Checking if the channel map for the ADCs has been provided/read
459 if(fMapADC[0][0]==-1){
460 printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
461 return kFALSE;
462 }
463 //
464 //printf("\n Reading map!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
465 /*for(Int_t ci=0; ci<48; ci++){
466 printf(" %d mod. %d ch. %d signal %d\n",ci,fMapADC[ci][0],
467 fMapADC[ci][1], fMapADC[ci][2]);
468 }
469 */
1ee299a5 470 for(Int_t k=0; k<48; k++){
c93c022b 471 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
472 fSector[0] = fMapADC[k][3];
473 fSector[1] = fMapADC[k][4];
1ee299a5 474 break;
475 }
476 }
1ee299a5 477 //
c93c022b 478 //printf("AliZDCRawStream -> ADCmod. %d ADCch %d det %d, sec %d\n",
479 // fADCModule,fADCChannel,fSector[0],fSector[1]);
1ee299a5 480
481 if(fADCModule<0 || fADCModule>3){
482 AliWarning(Form(" AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
483 fRawReader->AddMajorErrorLog(kInvalidADCModule);
484 }
485
486 }//No underflow nor overflow
487 }//ADC data word
488 // *** ADC EOB
489 else if((fBuffer & 0x07000000) == 0x04000000){
490 fIsADCEOB = kTRUE;
491 //printf(" AliZDCRawStream -> EOB --------------------------\n");
492 }
493 }//ADC module
494
495
496 }
497 fPosition++;
83347831 498
8309c1ab 499 return kTRUE;
500}