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