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),
34 memset(fArray, 0, kMaxWords*sizeof(UShort_t));
37 //_____________________________________________________________________________
38 AliAltroBufferV3::~AliAltroBufferV3()
43 //_____________________________________________________________________________
44 AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source):
45 AliAltroBuffer(source),
50 Fatal("AliAltroBufferV3", "copy constructor not implemented");
53 //_____________________________________________________________________________
54 AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& /*source*/)
58 Fatal("operator =", "assignment operator not implemented");
62 //_____________________________________________________________________________
63 void AliAltroBufferV3::FillBuffer(Int_t val)
65 //Fills the Buffer with 16 ten bits words and write into a file
67 if ((val > 0x3FF) || (val < 0)) {
68 Error("FillBuffer", "Value out of range (10 bits): %d", val);
72 if (fN >= (kMaxWords-1)) {
73 Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!");
80 //_____________________________________________________________________________
81 void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress)
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);
89 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
94 //_____________________________________________________________________________
95 void AliAltroBufferV3::ReverseAndWrite()
97 // Reverse the altro data order and
98 // write the buffer to the file
101 for(Int_t i = (fN-1); i >= 0; i--) {
102 temp |= (fArray[i] << shift);
105 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
112 fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
118 //_____________________________________________________________________________
119 UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
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
128 UInt_t currentFilePos = fFile->Tellp();
129 UInt_t size = currentFilePos-fDataHeaderPos;
130 size -= sizeof(AliRawDataHeader);
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));
138 // Now add the the RCU trailer tag
140 fFile->WriteBuffer((char *)(&size),sizeof(UInt_t));
142 // Now several well defined fields contained
144 // For details check the RCU manual
147 buffer = (0x1U << 26);
148 buffer |= (0x1U << 31);
149 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
151 buffer = (0x2U << 26);
152 buffer |= (0x1U << 31);
153 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
155 buffer = (0x3U << 26);
156 buffer |= (0x1U << 31);
157 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
160 buffer |= (0x4U << 26);
161 buffer |= (0x1U << 31);
162 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
164 buffer |= (0x5U << 26);
165 buffer |= (0x1U << 31);
166 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
168 buffer = (0x6U << 26);
169 buffer |= (0x1U << 31);
170 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
172 buffer = (0x7U << 26);
173 buffer |= (0x1U << 31);
174 fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
176 // Now the RCU identifier and size of the trailer
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));