Line data Source code
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 : // 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
20 :
21 : #include "AliAltroBufferV3.h"
22 : #include "AliRawDataHeaderSim.h"
23 : #include "AliLog.h"
24 : #include "AliFstream.h"
25 :
26 122 : ClassImp(AliAltroBufferV3)
27 :
28 : //_____________________________________________________________________________
29 : AliAltroBufferV3::AliAltroBufferV3(const char* fileName, AliAltroMapping *mapping):
30 794 : AliAltroBuffer(fileName,mapping),
31 794 : fN(0),
32 794 : fFECERRA(0),
33 794 : fFECERRB(0),
34 794 : fERRREG2(0),
35 794 : fERRREG3(0),
36 794 : fActiveFECsA(0xffff),
37 794 : fActiveFECsB(0xffff),
38 794 : fALTROCFG1(0),
39 794 : fALTROCFG2(0),
40 794 : fTSample(0),
41 794 : fL1Phase(0)
42 3970 : {
43 : // Constructor
44 794 : memset(fArray, 0, kMaxWords*sizeof(UShort_t));
45 1588 : }
46 :
47 : //_____________________________________________________________________________
48 : AliAltroBufferV3::~AliAltroBufferV3()
49 3176 : {
50 : // destructor
51 3176 : }
52 :
53 : //_____________________________________________________________________________
54 : AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source):
55 0 : AliAltroBuffer(source),
56 0 : fN(source.fN),
57 0 : fFECERRA(source.fFECERRA),
58 0 : fFECERRB(source.fFECERRB),
59 0 : fERRREG2(source.fERRREG2),
60 0 : fERRREG3(source.fERRREG3),
61 0 : fActiveFECsA(source.fActiveFECsA),
62 0 : fActiveFECsB(source.fActiveFECsB),
63 0 : fALTROCFG1(source.fALTROCFG1),
64 0 : fALTROCFG2(source.fALTROCFG2),
65 0 : fTSample(source.fTSample),
66 0 : fL1Phase(source.fL1Phase)
67 0 : {
68 : // Copy Constructor
69 :
70 0 : Fatal("AliAltroBufferV3", "copy constructor not implemented");
71 0 : }
72 :
73 : //_____________________________________________________________________________
74 : AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& /*source*/)
75 : {
76 : //Assigment operator
77 : #if 0
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;
88 : #endif
89 :
90 0 : Fatal("operator =", "assignment operator not implemented");
91 0 : return *this;
92 : }
93 :
94 : //_____________________________________________________________________________
95 : void AliAltroBufferV3::FillBuffer(Int_t val)
96 : {
97 : //Fills the Buffer with 16 ten bits words and write into a file
98 :
99 3050616 : if ((val > 0x3FF) || (val < 0)) {
100 0 : Error("FillBuffer", "Value out of range (10 bits): %d", val);
101 : val = 0x3FF;
102 0 : }
103 :
104 1525308 : if (fN >= (kMaxWords-1)) {
105 0 : Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!");
106 0 : return;
107 : }
108 :
109 1525308 : fArray[fN++] = val;
110 3050616 : }
111 :
112 : //_____________________________________________________________________________
113 : void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress)
114 : {
115 : //Writes a trailer (header) of 32 bits using
116 : //a given hardware adress
117 97902 : UInt_t temp = hwAddress & 0xFFF;
118 48951 : temp |= ((wordsNumber & 0x3FF) << 16);
119 48951 : temp |= (0x1U << 30);
120 :
121 48951 : fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
122 :
123 48951 : ReverseAndWrite();
124 48951 : }
125 :
126 : //_____________________________________________________________________________
127 : UInt_t AliAltroBufferV3::SetField(UInt_t& input, UShort_t start, UInt_t mask, UInt_t val) const
128 : {
129 96 : UInt_t out = (mask << start);
130 48 : UInt_t fld = (val << start) & out;
131 48 : input &= ~out;
132 48 : input |= fld;
133 48 : return input;
134 : }
135 :
136 : //_____________________________________________________________________________
137 : void AliAltroBufferV3::ReverseAndWrite()
138 : {
139 : // Reverse the altro data order and
140 : // write the buffer to the file
141 97902 : UInt_t temp = 0;
142 : Int_t shift = 20;
143 3148518 : for(Int_t i = (fN-1); i >= 0; i--) {
144 1525308 : temp |= (fArray[i] << shift);
145 1525308 : shift -= 10;
146 1525308 : if (shift < 0) {
147 490746 : fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
148 490746 : temp = 0;
149 : shift = 20;
150 490746 : }
151 : }
152 :
153 48951 : if (shift != 20) {
154 36976 : fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
155 36976 : }
156 :
157 48951 : fN = 0;
158 48951 : }
159 :
160 : //_____________________________________________________________________________
161 : UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
162 : {
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
168 : // raw data writing.
169 :
170 1612 : UInt_t currentFilePos = fFile->Tellp();
171 806 : UInt_t size = currentFilePos-fDataHeaderPos;
172 806 : size -= sizeof(AliRawDataHeaderV3);
173 806 : size /= 4;
174 :
175 806 : if (size > 0x3FFFFFF) {
176 0 : AliFatal(Form("The current raw data payload size of %d is bigger than the max possible one ! Can not write the RCU trailer !",size));
177 0 : return 2;
178 : }
179 :
180 : // Now add the the RCU trailer tag
181 806 : size |= (1U << 31);
182 806 : fFile->WriteBuffer((char *)(&size),sizeof(UInt_t));
183 :
184 : // Now several well defined fields contained
185 : // in the trailer
186 : // For details check the RCU manual
187 806 : UInt_t buffer;
188 :
189 : buffer = (0x1U << 26);
190 806 : buffer |= (0x1U << 31);
191 806 : fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
192 :
193 806 : buffer = (fERRREG2 & 0x3FFFFFF);
194 806 : buffer |= (0x2U << 26);
195 806 : buffer |= (0x1U << 31);
196 806 : fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
197 :
198 806 : buffer = (fERRREG3 & 0x3FFFFFF);
199 806 : buffer |= (0x3U << 26);
200 806 : buffer |= (0x1U << 31);
201 806 : fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
202 :
203 806 : buffer = (fActiveFECsA & 0x3FFFFFF);
204 806 : buffer |= (0x4U << 26);
205 806 : buffer |= (0x1U << 31);
206 806 : fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
207 :
208 806 : buffer = (fActiveFECsB & 0x3FFFFFF);
209 806 : buffer |= (0x5U << 26);
210 806 : buffer |= (0x1U << 31);
211 806 : fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
212 :
213 806 : buffer = (fALTROCFG1 & 0x3FFFFFF);
214 806 : buffer |= (0x6U << 26);
215 806 : buffer |= (0x1U << 31);
216 806 : fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
217 :
218 806 : buffer = (fALTROCFG2 & 0x3FFFFFF);
219 806 : buffer |= (0x7U << 26);
220 806 : buffer |= (0x1U << 31);
221 806 : fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
222 :
223 : // Now the RCU identifier and size of the trailer
224 : buffer = (9 & 0x7F);
225 806 : buffer |= ((rcuId & 0x1FF) << 7);
226 806 : buffer |= (0x2U << 16);
227 806 : buffer |= (0x8U << 26);
228 806 : buffer |= (0x3U << 30);
229 806 : fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
230 :
231 : return 2;
232 1612 : }
|