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