T0time -clock added
[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
11b06725 29#include <TSystem.h>
8309c1ab 30#include "AliZDCRawStream.h"
31#include "AliRawReader.h"
1ee299a5 32#include "AliRawDataHeader.h"
33#include "AliRawEventHeaderBase.h"
cc2abffd 34#include "AliLog.h"
8309c1ab 35
36ClassImp(AliZDCRawStream)
37
38
39//_____________________________________________________________________________
40AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
41 fRawReader(rawReader),
1ee299a5 42 fBuffer(0),
43 fEvType(0),
44 fPosition(0),
45 fIsCalib(kFALSE),
46 fIsDARCHeader(kFALSE),
47 fIsChMapping(kFALSE),
48 fIsADCDataWord(kFALSE),
49 fIsADCHeader(kFALSE),
50 fIsADCEOB(kFALSE),
fee50699 51 fSODReading(kFALSE),
52 fIsMapRead(kFALSE),
1ee299a5 53 fDARCEvBlockLenght(0),
54 fDARCBlockAttributes(0),
55 fDeadfaceOffset(0),
56 fDeadbeefOffset(0),
57 fDataOffset(0),
58 fModType(-1),
59 fADCModule(-1),
60 fADCNChannels(-1),
786b72f5 61 fADCChannel(-1),
cc2abffd 62 fADCValue(-1),
1ee299a5 63 fADCGain(-1),
c33b6ca6 64 fIsUnderflow(kFALSE),
65 fIsOverflow(kFALSE),
e42bdf10 66 fScNWords(0),
fee50699 67 fScGeo(0),
e42bdf10 68 fScTS(0),
69 fScTriggerNumber(0),
70 fIsScEventGood(kFALSE),
58671297 71 fNChannelsOn(0),
1ee299a5 72 fNConnCh(-1),
73 fCabledSignal(-1)
8309c1ab 74{
abf60186 75 // Create an object to read ZDC raw digits
1ee299a5 76 fRawReader->Reset();
362c9d61 77 fRawReader->Select("ZDC");
1ee299a5 78 //
58671297 79 const int kNch = 48;
80 for(Int_t i=0; i<kNch; i++){
c93c022b 81 for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
1ee299a5 82 }
83
8309c1ab 84}
85
86//_____________________________________________________________________________
87AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
a718c993 88 TObject(stream),
c61a7285 89 fRawReader(stream.fRawReader),
1ee299a5 90 fBuffer(stream.GetRawBuffer()),
91 fEvType(stream.fEvType),
92 fPosition(stream.fPosition),
93 fIsCalib(stream.fIsCalib),
94 fIsDARCHeader(stream.fIsDARCHeader),
95 fIsChMapping(stream.fIsChMapping),
96 fIsADCDataWord(stream.fIsADCDataWord),
97 fIsADCHeader(stream.fIsADCHeader),
98 fIsADCEOB(stream.fIsADCEOB),
fee50699 99 fSODReading(stream.fSODReading),
100 fIsMapRead(stream.fIsMapRead),
1ee299a5 101 fDARCEvBlockLenght(stream.fDARCEvBlockLenght),
102 fDARCBlockAttributes(stream.fDARCBlockAttributes),
103 fDeadfaceOffset(stream.GetDeadfaceOffset()),
104 fDeadbeefOffset(stream.GetDeadbeefOffset()),
105 fDataOffset(stream.GetDataOffset()),
106 fModType(stream.GetModType()),
a718c993 107 fADCModule(stream.GetADCModule()),
1ee299a5 108 fADCNChannels(stream.GetADCNChannels()),
a718c993 109 fADCChannel(stream.GetADCChannel()),
110 fADCValue(stream.GetADCValue()),
111 fADCGain(stream.GetADCGain()),
c33b6ca6 112 fIsUnderflow(stream.fIsUnderflow),
113 fIsOverflow(stream.fIsOverflow),
e42bdf10 114 fScNWords(stream.GetScNWords()),
115 fScGeo(stream.GetScGeo()),
116 fScTS(stream.GetScTS()),
22fe5e66 117 fScTriggerNumber(stream.fScTriggerNumber),
e42bdf10 118 fIsScEventGood(stream.fIsScEventGood),
9d0b658a 119 fNChannelsOn(stream.fNChannelsOn),
1ee299a5 120 fNConnCh(stream.fNConnCh),
121 fCabledSignal(stream.GetCabledSignal())
8309c1ab 122{
abf60186 123 // Copy constructor
58671297 124 const int kNch = 48;
c0aec6f6 125 for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);
58671297 126 for(Int_t i=0; i<kNch; i++){
c93c022b 127 for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
1ee299a5 128 }
8309c1ab 129}
130
131//_____________________________________________________________________________
132AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
133 /* stream */)
134{
abf60186 135 // Assignment operator
8309c1ab 136 Fatal("operator =", "assignment operator not implemented");
137 return *this;
138}
139
140//_____________________________________________________________________________
141AliZDCRawStream::~AliZDCRawStream()
142{
abf60186 143// Destructor
8309c1ab 144
145}
146
1ee299a5 147//_____________________________________________________________________________
c93c022b 148void AliZDCRawStream::ReadChMap()
149{
150 // Reading channel map
58671297 151 const int kNch = 48;
152 printf("\n\t Reading ZDC ADC mapping from OCDB\n");
fee50699 153 AliZDCChMap * chMap = GetChMap();
6d653649 154 //chMap->Print("");
58671297 155 for(Int_t i=0; i<kNch; i++){
fee50699 156 fMapADC[i][0] = chMap->GetADCModule(i);
157 fMapADC[i][1] = chMap->GetADCChannel(i);
158 fMapADC[i][2] = -1;
159 fMapADC[i][3] = chMap->GetDetector(i);
160 fMapADC[i][4] = chMap->GetSector(i);
161 }
162 fIsMapRead = kTRUE;
c93c022b 163}
164
165//_____________________________________________________________________________
1ee299a5 166void AliZDCRawStream::ReadCDHHeader()
167{
168 // Reading CDH
169 const AliRawDataHeader* header = fRawReader->GetDataHeader();
170 if(!header) {
9d0b658a 171 AliError(" No CDH in raw data streaming");
1ee299a5 172 fRawReader->AddMajorErrorLog(kCDHError);
fee50699 173 return;
1ee299a5 174 }
175 else{
176 //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
177
178 fDARCEvBlockLenght = header->fSize;
179 //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
180
ac84d2fc 181 UChar_t message = header->GetAttributes();
1ee299a5 182 //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
183
58671297 184 if(message & 0x0){ // PHYSICS RUN
185 //printf("\t PHYSICS RUN raw data found\n");
186 }
187 else if(message & 0x10){ // COSMIC RUN
65448375 188 //printf("\t STANDALONE_COSMIC RUN raw data found\n");
1ee299a5 189 }
190 else if(message & 0x20){ // PEDESTAL RUN
65448375 191 //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
1ee299a5 192 }
193 else if(message & 0x30){ // LASER RUN
65448375 194 //printf("\t STANDALONE_LASER RUN raw data found\n");
ac84d2fc 195 }
58671297 196 else if(message & 0x40){ // CALIBRATION_CENTRAL RUN
197 //printf("\t CALIBRATION_CENTRAL RUN raw data found\n");
198 }
199 else if(message & 0x50){ // CALIBRATION_SEMICENTRAL
200 //printf("\t CALIBRATION_SEMICENTRAL RUN raw data found\n");
201 }
202 else if(message & 0x60){ // CALIBRATION_MB
203 //printf("\t CALIBRATION_MB RUN raw data found\n");
204 }
205 else if(message & 0x70){ // CALIBRATION_EMD
206 //printf("\t CALIBRATION_EMD RUN raw data found\n");
207 }
1ee299a5 208
209 if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
210 fIsCalib = kTRUE;
211 }
212 //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
c93c022b 213 //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);
1ee299a5 214
215 UInt_t status = header->GetStatus();
216 //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
f9f99efb 217 if((status & 0x000f) == 0x0001){
9d0b658a 218 AliWarning("CDH -> DARC trg0 overlap error");
1ee299a5 219 fRawReader->AddMajorErrorLog(kDARCError);
220 }
f9f99efb 221 if((status & 0x000f) == 0x0002){
9d0b658a 222 AliWarning("CDH -> DARC trg0 missing error");
1ee299a5 223 fRawReader->AddMajorErrorLog(kDARCError);
224 }
f9f99efb 225 if((status & 0x000f) == 0x0004){
9d0b658a 226 AliWarning("CDH -> DARC data parity error");
1ee299a5 227 fRawReader->AddMajorErrorLog(kDARCError);
228 }
f9f99efb 229 if((status & 0x000f) == 0x0008){
9d0b658a 230 AliWarning("CDH -> DARC ctrl parity error");
1ee299a5 231 fRawReader->AddMajorErrorLog(kDARCError);
232 }
233 //
f9f99efb 234 if((status & 0x00f0) == 0x0010){
9d0b658a 235 AliWarning("CDH -> DARC trg unavailable");
1ee299a5 236 fRawReader->AddMajorErrorLog(kDARCError);
237 }
f9f99efb 238 if((status & 0x00f0) == 0x0020){
9d0b658a 239 AliWarning("CDH -> DARC FEE error");
1ee299a5 240 fRawReader->AddMajorErrorLog(kDARCError);
241 }
242 //
f9f99efb 243 if((status & 0x0f00) == 0x0200){
9d0b658a 244 AliWarning("CDH -> DARC L1 time violation");
1ee299a5 245 fRawReader->AddMajorErrorLog(kDARCError);
246 }
f9f99efb 247 if((status & 0x0f00) == 0x0400){
9d0b658a 248 AliWarning("CDH -> DARC L2 time-out");
1ee299a5 249 fRawReader->AddMajorErrorLog(kDARCError);
250 }
f9f99efb 251 if((status & 0x0f00) == 0x0800){
9d0b658a 252 AliWarning("CDH -> DARC prepulse time violation");
1ee299a5 253 fRawReader->AddMajorErrorLog(kDARCError);
254 }
255 //
f9f99efb 256 if((status & 0xf000) == 0x1000){
9d0b658a 257 AliWarning("CDH -> DARC other error");
1ee299a5 258 fRawReader->AddMajorErrorLog(kDARCError);
259 }
260 }
261 //
262 fIsDARCHeader = kTRUE;
263}
264
8309c1ab 265//_____________________________________________________________________________
266Bool_t AliZDCRawStream::Next()
267{
abf60186 268 // Read the next raw digit
269 // Returns kFALSE if there is no digit left
8309c1ab 270
1ee299a5 271 if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
58671297 272 const int kNch = 48;
273 Bool_t readScaler = kFALSE;
1ee299a5 274 fIsChMapping = kFALSE; fIsADCHeader = kFALSE;
275 fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
c33b6ca6 276 fIsUnderflow = kFALSE;
277 fIsOverflow = kFALSE;
58671297 278 fSector[0] = fSector[1] = -1;
1ee299a5 279
280 fEvType = fRawReader->GetType();
58671297 281 // CH. debug
1ee299a5 282 //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
ac84d2fc 283 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
1ee299a5 284
285 if(fPosition==0){
286 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
287 //ReadEventHeader();
288 ReadCDHHeader();
289 //}
290 fNConnCh=0;
291 }
ac84d2fc 292
9d0b658a 293 // *** End of ZDC event
ac84d2fc 294 if(fBuffer == 0xcafefade){
295 //printf("\n-> AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
296 return kFALSE;
297 }
1ee299a5 298
299 // -------------------------------------------
1069e28d 300 // --- DARC header
1ee299a5 301 // -------------------------------------------
fee50699 302 // If the CDH has been read then
303 // the DARC header must follow
1ee299a5 304 if(fIsDARCHeader){
84d2abc2 305 //printf("\t ---- DARC header ----\n");
1ee299a5 306 if(fIsCalib){
307 fDeadfaceOffset = 9;
308 fDeadbeefOffset = 25;
58671297 309 readScaler = kTRUE;
1ee299a5 310 }
311 else{
312 fDeadfaceOffset = 1;
313 fDeadbeefOffset = 7;
314 }
315 fDataOffset = 1+fDeadbeefOffset;
316 fIsDARCHeader = kFALSE;
abf60186 317 }
ac84d2fc 318
1ee299a5 319
320 // -------------------------------------------
321 // --- Start of data event
322 // --- decoding mapping of connected ADC ch.
323 // -------------------------------------------
fee50699 324 // In the SOD event ADC ch. mapping is written
325 if(fEvType==10 && fSODReading){
ac84d2fc 326 //printf("\n-> AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
fee50699 327
1ee299a5 328 if(fPosition>fDataOffset){
329 if((fBuffer&0xff000000) == 0xff000000){
330 if(fPosition==(fDataOffset+1)){
9d0b658a 331 printf("\n\n\t AliZDCRawStream -> Reading mapping from StartOfData event\n");
1ee299a5 332 fNConnCh=0;
6006df88 333 }
1ee299a5 334 else{
58671297 335 //printf("\n\t AliZDCRawStream -> End of ZDC StartOfData event\n\n");
fee50699 336 //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
337 return kFALSE;
1ee299a5 338 }
339 }
340 else if((fBuffer&0x80000000)>>31 == 1){
341 // Mapping identification
342 fADCModule = ((fBuffer & 0x7f000000)>>24);
9d0b658a 343 fModType = ((fBuffer & 0x7ff00)>>8);
1ee299a5 344 fADCNChannels = (fBuffer & 0xff);
345 //
ac84d2fc 346 //printf(" ******** GEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
6006df88 347 }
fee50699 348 else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
1ee299a5 349 // Channel signal
350 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
351 fIsChMapping = kTRUE;
352 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
353 fCabledSignal = (fBuffer&0xffff);
fee50699 354 //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
355 //
1ee299a5 356 fMapADC[fNConnCh][0] = fADCModule;
357 fMapADC[fNConnCh][1] = fADCChannel;
358 fMapADC[fNConnCh][2] = fCabledSignal;
c93c022b 359 //
360 // Determining detector and sector
361 // -----------------------------------------
362 // For the decoding of the following lines
363 // look the enum in AliZDCRawStream.h file
364 // -----------------------------------------
365 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
366 || fCabledSignal==24 || fCabledSignal==48){
c677d80e 367 fMapADC[fNConnCh][3] = 4; //ZNA
c93c022b 368 //
fee50699 369 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
370 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
371 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
372 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
373 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
c93c022b 374 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
375 }
376 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
c677d80e 377 fMapADC[fNConnCh][3] = 5; //ZPA
c93c022b 378 //
fee50699 379 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
380 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
381 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
c93c022b 382 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
383 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
384 }
385 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
386 || fCabledSignal==25 || fCabledSignal==49){
c677d80e 387 fMapADC[fNConnCh][3] = 1; //ZNC
c93c022b 388 //
fee50699 389 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
c93c022b 390 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
391 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
392 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
393 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
394 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
395 }
396 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
c677d80e 397 fMapADC[fNConnCh][3] = 2; //ZPC
c93c022b 398 //
fee50699 399 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
c93c022b 400 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
401 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
402 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
403 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
404 }
405 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
c677d80e 406 fMapADC[fNConnCh][3] = 3;
c93c022b 407 //
fee50699 408 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
c93c022b 409 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
410 }
411 //
1ee299a5 412 fNConnCh++;
58671297 413 if(fNConnCh>=kNch){
414 // Protection manually set since it returned:
1ee299a5 415 // RawData48 mod. 3 ch. 2048 signal 515
416 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
58671297 417 AliDebug(2," No. of cabled channels > kNch !!!");
ac84d2fc 418 fPosition++;
fee50699 419 return kTRUE;
1ee299a5 420 }
421 }
fee50699 422 }// ModType=1 (ADC mapping)
58671297 423 //else if(fModType!=1){
424
425 //}
1ee299a5 426 }
427 fPosition++;
428 return kTRUE;
fee50699 429 } // SOD event
1ee299a5 430
431 // -------------------------------------------
432 // --- DARC data
433 // -------------------------------------------
434 if(fPosition<fDeadfaceOffset){
435 fPosition++;
436 return kTRUE;
437 }
438 else if(fPosition==fDeadfaceOffset){
439 if(fBuffer != 0xdeadface){
6d653649 440 AliWarning(" NO deadface after DARC data");
1ee299a5 441 fRawReader->AddMajorErrorLog(kDARCError);
442 }
443 else{
444 fPosition++;
445 return kTRUE;
446 }
447 }
448
449 // -------------------------------------------
450 // --- DARC global data
451 // -------------------------------------------
452 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
453 fPosition++;
454 return kTRUE;
455 }
456 else if(fPosition==fDeadbeefOffset){
457 if(fBuffer != 0xdeadbeef){
6d653649 458 AliWarning(" NO deadbeef after DARC global data");
1ee299a5 459 fRawReader->AddMajorErrorLog(kDARCError);
460 }
461 else{
462 fPosition++;
463 return kTRUE;
464 }
465 }
466
467 // -------------------------------------------
468 // --- ZDC data
469 // --- ADC buffer + scaler
470 // -------------------------------------------
471 else if(fPosition>=fDataOffset){
fee50699 472
473 //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
474 if(!fSODReading && !fIsMapRead) ReadChMap();
475
1ee299a5 476 // Not valid datum before the event
477 // there MUST be a NOT valid datum before the event!!!
478 if(fPosition==fDataOffset){
84d2abc2 479 //printf("\t **** ZDC data begin ****\n");
58671297 480 if((fBuffer & 0x07000000) != 0x06000000){
481 fRawReader->AddMajorErrorLog(kZDCDataError);
482 }
483 /*else{
1ee299a5 484 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
485 // "position %d in word data buffer\n",fADCModule,fPosition);
58671297 486 }*/
1ee299a5 487 }
488
489 // If the not valid datum isn't followed by the 1st ADC header
490 // the event is corrupted (i.e., 2 gates arrived before trigger)
491 else if(fPosition==fDataOffset+1){
492 if((fBuffer & 0x07000000) != 0x02000000){
9d0b658a 493 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!");
1ee299a5 494 fRawReader->AddMajorErrorLog(kZDCDataError);
495 }
496 }
497
58671297 498 // Get geo address of current word to determine if:
499 // - it is a scaler word (geo address == kScalerAddress)
500 // - it is an ADC word (geo address <= 3)
1ee299a5 501 Int_t kScalerAddress=8;
502 fADCModule = ((fBuffer & 0xf8000000)>>27);
503 if(fADCModule == kScalerAddress){
504 DecodeScaler();
c33b6ca6 505 }
58671297 506 else if(fADCModule>=0 && fADCModule<=3){//ADC modules (0,1,2,3)
1ee299a5 507 // *** ADC header
ac84d2fc 508 if((fBuffer & 0x07000000) == 0x02000000){
1ee299a5 509 fIsADCHeader = kTRUE;
510 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
58671297 511 if(fADCModule==0) fNChannelsOn = fADCNChannels;
512 else fNChannelsOn += fADCNChannels;
513 //printf(" AliZDCRawStream -> ADC HEADER: mod.%d has %d ch. \n",fADCModule,fADCNChannels);
1ee299a5 514 }
515 // *** ADC data word
516 else if((fBuffer & 0x07000000) == 0x00000000){
517 fIsADCDataWord = kTRUE;
518 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
519 fADCGain = ((fBuffer & 0x10000) >> 16);
520 fADCValue = (fBuffer & 0xfff);
521
84d2abc2 522 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
523 // fADCModule,fADCChannel,fADCGain,fADCValue);
c93c022b 524
c33b6ca6 525 // Checking if the channel map for the ADCs has been provided/read
526 if(fMapADC[0][0]==-1){
527 printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
528 return kFALSE;
529 }
530 //
58671297 531 /*for(Int_t ci=0; ci<kNch; ci++){
9d0b658a 532 printf(" %d mod %d ch %d det %d sec %d\n",ci,fMapADC[ci][0],
c33b6ca6 533 fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
534 }*/
535
536 // Scan of the map to assign the correct volumes
537 Int_t foundMapEntry = kFALSE;
58671297 538 for(Int_t k=0; k<kNch; k++){
c33b6ca6 539 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
540 fSector[0] = fMapADC[k][3];
541 fSector[1] = fMapADC[k][4];
542 foundMapEntry = kTRUE;
543 break;
544 }
545 }
546 if(foundMapEntry==kFALSE){
9d0b658a 547 AliWarning(Form(" No valid entry found in ADC mapping for raw data %d ADCmod. %d ch. %d gain %d\n",
c33b6ca6 548 fPosition,fADCModule,fADCChannel,fADCGain));
549 }
550 //
551 //printf("AliZDCRawStream -> ADCmod. %d ch. %d gain %d -> det %d sec %d\n",
552 // fADCModule,fADCChannel,fADCGain,fSector[0],fSector[1]);
553
554 // Final checks
6d653649 555 if(foundMapEntry==kTRUE){
556 if(fSector[0]<1 || fSector[0]>5){
557 AliWarning(Form(" No valid detector assignment: %d",fSector[0]));
558 fRawReader->AddMajorErrorLog(kInvalidSector);
559 }
560 //
561 if(fSector[1]<0 || fSector[1]>5){
562 AliWarning(Form(" No valid sector assignment: %d",fSector[1]));
563 fRawReader->AddMajorErrorLog(kInvalidSector);
564 }
565 //
566 if(fADCModule<0 || fADCModule>3){
567 AliError(Form(" No valid ADC module: %d",fADCModule));
568 fRawReader->AddMajorErrorLog(kInvalidADCModule);
569 }
c33b6ca6 570 }
1ee299a5 571
c33b6ca6 572 // Checking the underflow and overflow bits
573 if(fBuffer & 0x1000) fIsUnderflow = kTRUE;
574 else if (fBuffer & 0x2000) fIsOverflow = kTRUE;
575
1ee299a5 576 }//ADC data word
577 // *** ADC EOB
578 else if((fBuffer & 0x07000000) == 0x04000000){
579 fIsADCEOB = kTRUE;
580 //printf(" AliZDCRawStream -> EOB --------------------------\n");
581 }
582 }//ADC module
583
584
585 }
586 fPosition++;
83347831 587
8309c1ab 588 return kTRUE;
589}
e42bdf10 590
591//_____________________________________________________________________________
592void AliZDCRawStream::DecodeScaler()
593{
594 // Decoding scaler event
595
596 if(!fBuffer & 0x04000000){
9d0b658a 597 AliWarning(" Scaler header corrupted");
e42bdf10 598 fIsScEventGood = kFALSE;
599 }
22fe5e66 600 Int_t scNwords = (Int_t) fScNWords;
601 if(fPosition==scNwords && fBuffer != 0x0){
9d0b658a 602 AliWarning(" Scaler trailer corrupted");
e42bdf10 603 fIsScEventGood = kFALSE;
604 }
605 fIsScEventGood = kTRUE;
606
607 if(fPosition==0){
608 fScNWords = (fBuffer & 0x00fc0000)>>18;
609 fScGeo = (fBuffer & 0xf8000000)>>27;
610 fScTS = (fBuffer & 0x00030000)>>16;
611 fScTriggerNumber = (fBuffer & 0x0000ffff);
612 }
613
614 fPosition++;
615
616}
fee50699 617
618//_____________________________________________________________________________
619AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri)
620{
621 // Setting the storage
622
623 AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri);
624
625 return storage;
626}
627
628
629//_____________________________________________________________________________
630AliZDCChMap* AliZDCRawStream::GetChMap() const
631{
632
633 // Getting calibration object for ZDC
634
635 AliCDBEntry *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
636 if(!entry) AliFatal("No calibration data loaded!");
637
638 AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
639 if(!calibdata) AliFatal("Wrong calibration object in calibration file!");
640
641 return calibdata;
642}