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 // Interface to the Altro format
17 // to read and write digits
18 // To be used in Alice Data Challenges
19 // and in the compression of the RAW data
21 #include "AliAltroBufferV3.h"
22 #include "AliRawDataHeaderSim.h"
24 #include "AliFstream.h"
26 ClassImp(AliAltroBufferV3)
28 //_____________________________________________________________________________
29 AliAltroBufferV3::AliAltroBufferV3(const char* fileName, AliAltroMapping *mapping):
30 AliAltroBuffer(fileName,mapping),
44 memset(fArray, 0, kMaxWords*sizeof(UShort_t));
47 //_____________________________________________________________________________
48 AliAltroBufferV3::~AliAltroBufferV3()
53 //_____________________________________________________________________________
54 AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source):
55 AliAltroBuffer(source),
57 fFECERRA(source.fFECERRA),
58 fFECERRB(source.fFECERRB),
59 fERRREG2(source.fERRREG2),
60 fERRREG3(source.fERRREG3),
61 fActiveFECsA(source.fActiveFECsA),
62 fActiveFECsB(source.fActiveFECsB),
63 fALTROCFG1(source.fALTROCFG1),
64 fALTROCFG2(source.fALTROCFG2),
65 fTSample(source.fTSample),
66 fL1Phase(source.fL1Phase)
70 Fatal("AliAltroBufferV3", "copy constructor not implemented");
73 //_____________________________________________________________________________
74 AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& /*source*/)
78 fFECERRA = source.fFECERRA;
79 fFECERRB = source.fFECERRB;
80 fERRREG2 = source.fERRREG2;
81 fERRREG3 = source.fERRREG3;
82 fActiveFECsA = source.fActiveFECsA;
83 fActiveFECsB = source.fActiveFECsB;
84 fALTROCFG1 = source.fALTROCFG1;
85 fALTROCFG2 = source.fALTROCFG2;
86 fTSample = source.fTSample;
87 fL1Phase = source.fL1Phase;
90 Fatal("operator =", "assignment operator not implemented");
94 //_____________________________________________________________________________
95 void AliAltroBufferV3::FillBuffer(Int_t val)
97 //Fills the Buffer with 16 ten bits words and write into a file
99 if ((val > 0x3FF) || (val < 0)) {
100 Error("FillBuffer", "Value out of range (10 bits): %d", val);
104 if (fN >= (kMaxWords-1)) {
105 Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!");
112 //_____________________________________________________________________________
113 void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress)
115 //Writes a trailer (header) of 32 bits using
116 //a given hardware adress
117 UInt_t temp = hwAddress & 0xFFF;
118 temp |= ((wordsNumber & 0x3FF) << 16);
119 temp |= (0x1U << 30);
121 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
126 //_____________________________________________________________________________
127 UInt_t AliAltroBufferV3::SetField(UInt_t& input, UShort_t start, UInt_t mask, UInt_t val) const
129 UInt_t out = (mask << start);
130 UInt_t fld = (val << start) & out;
136 //_____________________________________________________________________________
137 void AliAltroBufferV3::ReverseAndWrite()
139 // Reverse the altro data order and
140 // write the buffer to the file
143 for(Int_t i = (fN-1); i >= 0; i--) {
144 temp |= (fArray[i] << shift);
147 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
154 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
160 //_____________________________________________________________________________
161 UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
163 // Writes the RCU trailer
164 // rcuId the is serial number of the corresponding
165 // RCU. The basic format of the trailer can be
166 // found in the RCU manual.
167 // This method should be called at the end of
170 UInt_t currentFilePos = fFile->Tellp();
171 UInt_t size = currentFilePos-fDataHeaderPos;
172 size -= sizeof(AliRawDataHeader);
175 if (size > 0x3FFFFFF) {
176 AliFatal(Form("The current raw data payload size of %d is bigger than the max possible one ! Can not write the RCU trailer !",size));
180 // Now add the the RCU trailer tag
182 fFile->WriteBuffer((char *)(&size),sizeof(UInt_t));
184 // Now several well defined fields contained
186 // For details check the RCU manual
189 buffer = (0x1U << 26);
190 buffer |= (0x1U << 31);
191 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
193 buffer = (fERRREG2 & 0x3FFFFFF);
194 buffer |= (0x2U << 26);
195 buffer |= (0x1U << 31);
196 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
198 buffer = (fERRREG3 & 0x3FFFFFF);
199 buffer |= (0x3U << 26);
200 buffer |= (0x1U << 31);
201 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
203 buffer = (fActiveFECsA & 0x3FFFFFF);
204 buffer |= (0x4U << 26);
205 buffer |= (0x1U << 31);
206 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
208 buffer = (fActiveFECsB & 0x3FFFFFF);
209 buffer |= (0x5U << 26);
210 buffer |= (0x1U << 31);
211 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
213 buffer = (fALTROCFG1 & 0x3FFFFFF);
214 buffer |= (0x6U << 26);
215 buffer |= (0x1U << 31);
216 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
218 buffer = (fALTROCFG2 & 0x3FFFFFF);
219 buffer |= (0x7U << 26);
220 buffer |= (0x1U << 31);
221 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
223 // Now the RCU identifier and size of the trailer
225 buffer |= ((rcuId & 0x1FF) << 7);
226 buffer |= (0x2U << 16);
227 buffer |= (0x8U << 26);
228 buffer |= (0x3U << 30);
229 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));