]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliAltroBufferV3.cxx
Coverity fix
[u/mrichter/AliRoot.git] / RAW / 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 {
33   // Constructor
34   memset(fArray, 0, kMaxWords*sizeof(UShort_t));
35 }
36
37 //_____________________________________________________________________________
38 AliAltroBufferV3::~AliAltroBufferV3()
39 {
40 // destructor
41 }
42
43 //_____________________________________________________________________________
44 AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source):
45   AliAltroBuffer(source),
46   fN(source.fN)
47 {
48 // Copy Constructor
49
50   Fatal("AliAltroBufferV3", "copy constructor not implemented");
51 }
52
53 //_____________________________________________________________________________
54 AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& /*source*/)
55 {
56 //Assigment operator
57
58   Fatal("operator =", "assignment operator not implemented");
59   return *this;
60 }
61
62 //_____________________________________________________________________________
63 void AliAltroBufferV3::FillBuffer(Int_t val)
64 {
65 //Fills the Buffer with 16 ten bits words and write into a file 
66
67   if ((val > 0x3FF) || (val < 0)) {
68     Error("FillBuffer", "Value out of range (10 bits): %d", val);
69     val = 0x3FF;
70   }
71
72   if (fN >= (kMaxWords-1)) {
73     Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!");
74     return;
75   }
76
77   fArray[fN++] = val;
78 }
79
80 //_____________________________________________________________________________
81 void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress)
82 {
83   //Writes a trailer (header) of 32 bits using
84   //a given hardware adress
85   UInt_t temp = hwAddress & 0xFFF;
86   temp |= ((wordsNumber & 0x3FF) << 16);
87   temp |= (0x1U << 30);
88
89   fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
90
91   ReverseAndWrite();
92 }
93
94 //_____________________________________________________________________________
95 void AliAltroBufferV3::ReverseAndWrite()
96 {
97   // Reverse the altro data order and
98   // write the buffer to the file
99   UInt_t temp = 0;
100   Int_t shift = 20;
101   for(Int_t i = (fN-1); i >= 0; i--) {
102     temp |= (fArray[i] << shift);
103     shift -= 10;
104     if (shift < 0) {
105       fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
106       temp = 0;
107       shift = 20;
108     }
109   }
110
111   if (shift != 20) {
112     fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
113   }
114
115   fN = 0;
116 }
117
118 //_____________________________________________________________________________
119 UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
120 {
121   // Writes the RCU trailer
122   // rcuId the is serial number of the corresponding
123   // RCU. The basic format of the trailer can be
124   // found in the RCU manual.
125   // This method should be called at the end of
126   // raw data writing.
127
128   UInt_t currentFilePos = fFile->Tellp();
129   UInt_t size = currentFilePos-fDataHeaderPos;
130   size -= sizeof(AliRawDataHeader);
131   size /= 4;
132   
133   if (size > 0x3FFFFFF) {
134     AliFatal(Form("The current raw data payload size of %d is bigger than the max possible one ! Can not write the RCU trailer !",size));
135     return 2;
136   }
137
138   // Now add the the RCU trailer tag
139   size |= (1U << 31);
140   fFile->WriteBuffer((char *)(&size),sizeof(UInt_t));
141
142   // Now several well defined fields contained
143   // in the trailer
144   // For details check the RCU manual
145   UInt_t buffer;
146
147   buffer  = (0x1U << 26);
148   buffer |= (0x1U << 31);
149   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
150   
151   buffer  = (0x2U << 26);
152   buffer |= (0x1U << 31);
153   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
154   
155   buffer  = (0x3U << 26);
156   buffer |= (0x1U << 31);
157   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
158
159   buffer  = 0x3FFFFFF;
160   buffer |= (0x4U << 26);
161   buffer |= (0x1U << 31);
162   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
163   buffer  = 0x3FFFFFF;
164   buffer |= (0x5U << 26);
165   buffer |= (0x1U << 31);
166   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
167
168   buffer  = (0x6U << 26);
169   buffer |= (0x1U << 31);
170   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
171   
172   buffer  = (0x7U << 26);
173   buffer |= (0x1U << 31);
174   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
175   
176   //  Now the RCU identifier and size of the trailer
177   buffer = (9 & 0x7F);
178   buffer |= ((rcuId & 0x1FF) << 7);
179   buffer |= (0x2U << 16);
180   buffer |= (0x8U << 26);
181   buffer |= (0x3U << 30);
182   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
183
184   return 2;
185 }