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