]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/RAWDatasim/AliAltroBufferV3.cxx
ANALYSIS module
[u/mrichter/AliRoot.git] / RAW / RAWDatasim / AliAltroBufferV3.cxx
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 ClassImp(AliAltroBufferV3)
27
28 //_____________________________________________________________________________
29 AliAltroBufferV3::AliAltroBufferV3(const char* fileName, AliAltroMapping *mapping):
30 AliAltroBuffer(fileName,mapping),
31   fN(0),
32   fFECERRA(0),  
33   fFECERRB(0),  
34   fERRREG2(0),  
35   fERRREG3(0),  
36   fActiveFECsA(0xffff),
37   fActiveFECsB(0xffff),
38   fALTROCFG1(0),        
39   fALTROCFG2(0),        
40   fTSample(0),  
41   fL1Phase(0)
42 {
43   // Constructor
44   memset(fArray, 0, kMaxWords*sizeof(UShort_t));
45 }
46
47 //_____________________________________________________________________________
48 AliAltroBufferV3::~AliAltroBufferV3()
49 {
50 // destructor
51 }
52
53 //_____________________________________________________________________________
54 AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source):
55   AliAltroBuffer(source),
56   fN(source.fN),
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)
67 {
68 // Copy Constructor
69
70   Fatal("AliAltroBufferV3", "copy constructor not implemented");
71 }
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   Fatal("operator =", "assignment operator not implemented");
91   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   if ((val > 0x3FF) || (val < 0)) {
100     Error("FillBuffer", "Value out of range (10 bits): %d", val);
101     val = 0x3FF;
102   }
103
104   if (fN >= (kMaxWords-1)) {
105     Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!");
106     return;
107   }
108
109   fArray[fN++] = val;
110 }
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   UInt_t temp = hwAddress & 0xFFF;
118   temp |= ((wordsNumber & 0x3FF) << 16);
119   temp |= (0x1U << 30);
120
121   fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
122
123   ReverseAndWrite();
124 }
125
126 //_____________________________________________________________________________
127 UInt_t AliAltroBufferV3::SetField(UInt_t& input, UShort_t start, UInt_t mask, UInt_t val) const
128 {
129   UInt_t out = (mask << start);
130   UInt_t fld = (val << start) & out;
131   input &= ~out;
132   input |= fld;
133   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   UInt_t temp = 0;
142   Int_t shift = 20;
143   for(Int_t i = (fN-1); i >= 0; i--) {
144     temp |= (fArray[i] << shift);
145     shift -= 10;
146     if (shift < 0) {
147       fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
148       temp = 0;
149       shift = 20;
150     }
151   }
152
153   if (shift != 20) {
154     fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
155   }
156
157   fN = 0;
158 }
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   UInt_t currentFilePos = fFile->Tellp();
171   UInt_t size = currentFilePos-fDataHeaderPos;
172   size -= sizeof(AliRawDataHeaderV3);
173   size /= 4;
174   
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));
177     return 2;
178   }
179
180   // Now add the the RCU trailer tag
181   size |= (1U << 31);
182   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   UInt_t buffer;
188
189   buffer  = (0x1U << 26);
190   buffer |= (0x1U << 31);
191   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
192
193   buffer =  (fERRREG2 & 0x3FFFFFF);
194   buffer |= (0x2U << 26);
195   buffer |= (0x1U << 31);
196   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
197   
198   buffer =  (fERRREG3 & 0x3FFFFFF);
199   buffer |= (0x3U << 26);
200   buffer |= (0x1U << 31);
201   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
202
203   buffer  = (fActiveFECsA & 0x3FFFFFF);
204   buffer |= (0x4U << 26);
205   buffer |= (0x1U << 31);
206   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); 
207
208   buffer  = (fActiveFECsB & 0x3FFFFFF);
209   buffer |= (0x5U << 26);
210   buffer |= (0x1U << 31);
211   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
212
213   buffer  = (fALTROCFG1 & 0x3FFFFFF);
214   buffer |= (0x6U << 26);
215   buffer |= (0x1U << 31);
216   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
217   
218   buffer  = (fALTROCFG2 & 0x3FFFFFF);
219   buffer |= (0x7U << 26);
220   buffer |= (0x1U << 31);
221   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
222   
223   //  Now the RCU identifier and size of the trailer
224   buffer = (9 & 0x7F);
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));
230
231   return 2;
232 }