]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliAltroBufferV3.cxx
make scan of dEdx blocks consistent, there is only one block
[u/mrichter/AliRoot.git] / RAW / AliAltroBufferV3.cxx
CommitLineData
5ca4e0a0 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
26ClassImp(AliAltroBufferV3)
27
28//_____________________________________________________________________________
29AliAltroBufferV3::AliAltroBufferV3(const char* fileName, AliAltroMapping *mapping):
30AliAltroBuffer(fileName,mapping),
31 fN(0)
32{
33 // Constructor
93d2d7c4 34 memset(fArray, 0, kMaxWords*sizeof(UShort_t));
5ca4e0a0 35}
36
37//_____________________________________________________________________________
38AliAltroBufferV3::~AliAltroBufferV3()
39{
40// destructor
5ca4e0a0 41}
42
43//_____________________________________________________________________________
44AliAltroBufferV3::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//_____________________________________________________________________________
54AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& /*source*/)
55{
56//Assigment operator
57
58 Fatal("operator =", "assignment operator not implemented");
59 return *this;
60}
61
62//_____________________________________________________________________________
63void 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//_____________________________________________________________________________
81void 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;
69763d52 86 temp |= ((wordsNumber & 0x3FF) << 16);
aea0bb6b 87 temp |= (0x1U << 30);
5ca4e0a0 88
89 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
90
91 ReverseAndWrite();
92}
93
94//_____________________________________________________________________________
95void 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;
69763d52 101 for(Int_t i = (fN-1); i >= 0; i--) {
5ca4e0a0 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//_____________________________________________________________________________
b73dbf18 119UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
5ca4e0a0 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);
b73dbf18 131 size /= 4;
5ca4e0a0 132
b73dbf18 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;
5ca4e0a0 136 }
137
b73dbf18 138 // Now add the the RCU trailer tag
aea0bb6b 139 size |= (1U << 31);
5ca4e0a0 140 fFile->WriteBuffer((char *)(&size),sizeof(UInt_t));
141
b73dbf18 142 // Now several well defined fields contained
143 // in the trailer
144 // For details check the RCU manual
145 UInt_t buffer;
146
aea0bb6b 147 buffer = (0x1U << 26);
148 buffer |= (0x1U << 31);
b73dbf18 149 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
150
aea0bb6b 151 buffer = (0x2U << 26);
152 buffer |= (0x1U << 31);
b73dbf18 153 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
154
aea0bb6b 155 buffer = (0x3U << 26);
156 buffer |= (0x1U << 31);
b73dbf18 157 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
158
159 buffer = 0x3FFFFFF;
aea0bb6b 160 buffer |= (0x4U << 26);
161 buffer |= (0x1U << 31);
b73dbf18 162 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
163 buffer = 0x3FFFFFF;
aea0bb6b 164 buffer |= (0x5U << 26);
165 buffer |= (0x1U << 31);
b73dbf18 166 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
167
aea0bb6b 168 buffer = (0x6U << 26);
169 buffer |= (0x1U << 31);
b73dbf18 170 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
171
aea0bb6b 172 buffer = (0x7U << 26);
173 buffer |= (0x1U << 31);
b73dbf18 174 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
5ca4e0a0 175
176 // Now the RCU identifier and size of the trailer
b73dbf18 177 buffer = (9 & 0x7F);
5ca4e0a0 178 buffer |= ((rcuId & 0x1FF) << 7);
aea0bb6b 179 buffer |= (0x2U << 16);
180 buffer |= (0x8U << 26);
181 buffer |= (0x3U << 30);
5ca4e0a0 182 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
183
b73dbf18 184 return 2;
5ca4e0a0 185}