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