1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 /// This is a class for reading the VZERO DDL raw data
19 /// The format of the raw data corresponds to the one
20 /// implemented in AliVZEROBuffer class.
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliVZERORawStream.h"
25 #include "AliRawReader.h"
29 ClassImp(AliVZERORawStream)
31 //_____________________________________________________________________________
32 AliVZERORawStream::AliVZERORawStream(AliRawReader* rawReader) :
36 fRawReader(rawReader),
39 // create an object to read VZERO raw data
41 // select the raw data corresponding to
42 // the VZERO detector id
44 AliDebug(1,Form("Selecting raw data for detector %d",AliDAQ::DetectorID("VZERO")));
45 fRawReader->Select("VZERO");
47 // Initalize the containers
48 for(Int_t i = 0; i < kNChannels; i++) {
49 fTime[i] = fWidth[i] = 0;
50 for(Int_t j = 0; j < kNEvOfInt; j++) {
52 fIsInt[i][j] = fIsBB[i][j] = fIsBG[i][j] = kFALSE;
54 fBBScalers[i] = fBGScalers[i] = 0;
55 for(Int_t j = 0; j < kNBunches; j++) {
57 fIsIntMB[i][j] = fIsBBMB[i][j] = fIsBGMB[i][j] = kFALSE;
60 for(Int_t i = 0; i < kNScalers; i++) fScalers[i] = 0;
61 for(Int_t i = 0; i < kNBunches; i++) fBunchNumbers[i] = 0;
64 //_____________________________________________________________________________
65 AliVZERORawStream::~AliVZERORawStream()
70 //_____________________________________________________________________________
71 void AliVZERORawStream::Reset()
73 // reset raw stream params
75 // Reinitalize the containers
76 for(Int_t i = 0; i < kNChannels; i++) {
77 fTime[i] = fWidth[i] = 0;
78 for(Int_t j = 0; j < kNEvOfInt; j++) {
80 fIsInt[i][j] = fIsBB[i][j] = fIsBG[i][j] = kFALSE;
82 fBBScalers[i] = fBGScalers[i] = 0;
83 for(Int_t j = 0; j < kNBunches; j++) {
85 fIsIntMB[i][j] = fIsBBMB[i][j] = fIsBGMB[i][j] = kFALSE;
88 for(Int_t i = 0; i < kNScalers; i++) fScalers[i] = 0;
89 for(Int_t i = 0; i < kNBunches; i++) fBunchNumbers[i] = 0;
91 fTrigger = fTriggerMask = 0;
95 if (fRawReader) fRawReader->Reset();
98 //_____________________________________________________________________________
99 Bool_t AliVZERORawStream::Next()
101 // read next digit from the VZERO raw data stream
102 // return kFALSE in case of error or no digits left
104 if (fPosition >= 0) return kFALSE;
106 if (!fRawReader->ReadNextData(fData)) return kFALSE;
107 if (fRawReader->GetDataSize() == 0) return kFALSE;
109 if (fRawReader->GetDataSize() != 5936) {
110 fRawReader->AddFatalErrorLog(kRawDataSizeErr,Form("size %d != 5936",fRawReader->GetDataSize()));
111 AliWarning(Form("Wrong VZERO raw data size: %d, expected 5936 bytes!",fRawReader->GetDataSize()));
117 fTrigger = GetNextWord() & 0xffff;
118 fTriggerMask = GetNextWord() & 0xffff;
120 for(Int_t iScaler = 0; iScaler < kNScalers; iScaler++)
121 fScalers[iScaler] = GetNextWord();
123 for(Int_t iBunch = 0; iBunch < kNBunches; iBunch++)
124 fBunchNumbers[iBunch] = GetNextWord();
126 for (Int_t iCIU = 0; iCIU < 8; iCIU++) {
128 // decoding of one Channel Interface Unit numbered iCIU - there are 8 channels per CIU (and 8 CIUs) :
130 for (Int_t iChannel_Offset = iCIU*8; iChannel_Offset < (iCIU*8)+8; iChannel_Offset=iChannel_Offset+4) {
131 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
132 for(Int_t iEvOfInt = 0; iEvOfInt < kNEvOfInt; iEvOfInt++) {
133 UShort_t data = GetNextShort();
134 fADC[iChannel][iEvOfInt] = data & 0x3ff;
135 fIsInt[iChannel][iEvOfInt] = (data >> 10) & 0x1;
138 for(Int_t iEvOfInt = 0; iEvOfInt < kNEvOfInt; iEvOfInt=iEvOfInt+2) {
139 UShort_t data = GetNextShort();
140 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
141 fIsBB[iChannel][iEvOfInt] = (data >> 2*iChannel) & 0x1;
142 fIsBG[iChannel][iEvOfInt] = (data >> 2*iChannel+1) & 0x1;
143 fIsBB[iChannel][iEvOfInt+1] = (data >> (8+ 2*iChannel)) & 0x1;
144 fIsBG[iChannel][iEvOfInt+1] = (data >> (8+ 2*iChannel+1)) & 0x1;
150 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
151 for(Int_t iBunch = 0; iBunch < kNBunches; iBunch++) {
152 UShort_t data = GetNextShort();
153 fChargeMB[iChannel][iBunch] = data & 0x3ff;
154 fIsIntMB[iChannel][iBunch] = (data >> 10) & 0x1;
158 for(Int_t iBunch = 0; iBunch < kNBunches; iBunch=iBunch+2) {
159 UShort_t data = GetNextShort();
160 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
161 fIsBBMB[iChannel][iBunch] = (data >> 2*iBunch) & 0x1;
162 fIsBGMB[iChannel][iBunch] = (data >> 2*iBunch+1) & 0x1;
163 fIsBBMB[iChannel][iBunch+1] = (data >> (8+2*iBunch)) & 0x1;
164 fIsBGMB[iChannel][iBunch+1] = (data >> (8+2*iBunch+1)) & 0x1;
170 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
171 fBBScalers[iChannel] = ((ULong64_t)GetNextWord()) << 32;
172 fBBScalers[iChannel] |= GetNextWord();
173 fBGScalers[iChannel] = ((ULong64_t)GetNextWord()) << 32;
174 fBGScalers[iChannel] |= GetNextWord();
179 for(Int_t iChannel = iCIU*8; iChannel < (iCIU*8) + 8; iChannel++) {
180 UInt_t time = GetNextWord();
181 fTime[iChannel] = time & 0xfff;
182 fWidth[iChannel] = (time >> 12) & 0x7f; // HPTDC used in pairing mode
185 // End of decoding of one CIU card
186 // printf("Number of bytes used at end of reading CIU card number %d %d \n\n", iCIU+1, fPosition);
188 } // end of decoding the eight CIUs
193 //_____________________________________________________________________________
194 UInt_t AliVZERORawStream::GetNextWord()
196 // This method returns the next 32 bit word
197 // inside the raw data payload.
198 // The method is supposed to be endian (platform)
200 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
203 word |= fData[fPosition++];
204 word |= fData[fPosition++] << 8;
205 word |= fData[fPosition++] << 16;
206 word |= fData[fPosition++] << 24;
211 //_____________________________________________________________________________
212 UShort_t AliVZERORawStream::GetNextShort()
214 // This method returns the next 16 bit word
215 // inside the raw data payload.
216 // The method is supposed to be endian (platform)
218 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
221 word |= fData[fPosition++];
222 word |= fData[fPosition++] << 8;