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),
36 //_____________________________________________________________________________
37 AliAltroBufferV3::~AliAltroBufferV3()
42 //_____________________________________________________________________________
43 AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source):
44 AliAltroBuffer(source),
49 Fatal("AliAltroBufferV3", "copy constructor not implemented");
52 //_____________________________________________________________________________
53 AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& /*source*/)
57 Fatal("operator =", "assignment operator not implemented");
61 //_____________________________________________________________________________
62 void AliAltroBufferV3::FillBuffer(Int_t val)
64 //Fills the Buffer with 16 ten bits words and write into a file
66 if ((val > 0x3FF) || (val < 0)) {
67 Error("FillBuffer", "Value out of range (10 bits): %d", val);
71 if (fN >= (kMaxWords-1)) {
72 Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!");
79 //_____________________________________________________________________________
80 void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress)
82 //Writes a trailer (header) of 32 bits using
83 //a given hardware adress
84 UInt_t temp = hwAddress & 0xFFF;
85 temp |= ((wordsNumber & 0x3FF) << 16);
88 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
93 //_____________________________________________________________________________
94 void AliAltroBufferV3::ReverseAndWrite()
96 // Reverse the altro data order and
97 // write the buffer to the file
100 for(Int_t i = (fN-1); i >= 0; i--) {
101 temp |= (fArray[i] << shift);
104 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
111 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
117 //_____________________________________________________________________________
118 UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
120 // Writes the RCU trailer
121 // rcuId the is serial number of the corresponding
122 // RCU. The basic format of the trailer can be
123 // found in the RCU manual.
124 // This method should be called at the end of
127 UInt_t currentFilePos = fFile->Tellp();
128 UInt_t size = currentFilePos-fDataHeaderPos;
129 size -= sizeof(AliRawDataHeader);
132 if (size > 0x3FFFFFF) {
133 AliFatal(Form("The current raw data payload size of %d is bigger than the max possible one ! Can not write the RCU trailer !",size));
137 // Now add the the RCU trailer tag
139 fFile->WriteBuffer((char *)(&size),sizeof(UInt_t));
141 // Now several well defined fields contained
143 // For details check the RCU manual
146 buffer = (0x1 << 26);
147 buffer |= (0x1 << 31);
148 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
150 buffer = (0x2 << 26);
151 buffer |= (0x1 << 31);
152 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
154 buffer = (0x3 << 26);
155 buffer |= (0x1 << 31);
156 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
159 buffer |= (0x4 << 26);
160 buffer |= (0x1 << 31);
161 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
163 buffer |= (0x5 << 26);
164 buffer |= (0x1 << 31);
165 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
167 buffer = (0x6 << 26);
168 buffer |= (0x1 << 31);
169 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
171 buffer = (0x7 << 26);
172 buffer |= (0x1 << 31);
173 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
175 // Now the RCU identifier and size of the trailer
177 buffer |= ((rcuId & 0x1FF) << 7);
178 buffer |= (0x2 << 16);
179 buffer |= (0x8 << 26);
180 buffer |= (0x3 << 30);
181 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));