]>
Commit | Line | Data |
---|---|---|
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 | ||
26 | ClassImp(AliAltroBufferV3) | |
27 | ||
28 | //_____________________________________________________________________________ | |
29 | AliAltroBufferV3::AliAltroBufferV3(const char* fileName, AliAltroMapping *mapping): | |
30 | AliAltroBuffer(fileName,mapping), | |
31 | fN(0) | |
32 | { | |
33 | // Constructor | |
34 | } | |
35 | ||
36 | //_____________________________________________________________________________ | |
37 | AliAltroBufferV3::~AliAltroBufferV3() | |
38 | { | |
39 | // destructor | |
5ca4e0a0 | 40 | } |
41 | ||
42 | //_____________________________________________________________________________ | |
43 | AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source): | |
44 | AliAltroBuffer(source), | |
45 | fN(source.fN) | |
46 | { | |
47 | // Copy Constructor | |
48 | ||
49 | Fatal("AliAltroBufferV3", "copy constructor not implemented"); | |
50 | } | |
51 | ||
52 | //_____________________________________________________________________________ | |
53 | AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& /*source*/) | |
54 | { | |
55 | //Assigment operator | |
56 | ||
57 | Fatal("operator =", "assignment operator not implemented"); | |
58 | return *this; | |
59 | } | |
60 | ||
61 | //_____________________________________________________________________________ | |
62 | void AliAltroBufferV3::FillBuffer(Int_t val) | |
63 | { | |
64 | //Fills the Buffer with 16 ten bits words and write into a file | |
65 | ||
66 | if ((val > 0x3FF) || (val < 0)) { | |
67 | Error("FillBuffer", "Value out of range (10 bits): %d", val); | |
68 | val = 0x3FF; | |
69 | } | |
70 | ||
71 | if (fN >= (kMaxWords-1)) { | |
72 | Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!"); | |
73 | return; | |
74 | } | |
75 | ||
76 | fArray[fN++] = val; | |
77 | } | |
78 | ||
79 | //_____________________________________________________________________________ | |
80 | void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress) | |
81 | { | |
82 | //Writes a trailer (header) of 32 bits using | |
83 | //a given hardware adress | |
84 | UInt_t temp = hwAddress & 0xFFF; | |
69763d52 | 85 | temp |= ((wordsNumber & 0x3FF) << 16); |
5ca4e0a0 | 86 | temp |= (0x1 << 30); |
87 | ||
88 | fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t)); | |
89 | ||
90 | ReverseAndWrite(); | |
91 | } | |
92 | ||
93 | //_____________________________________________________________________________ | |
94 | void AliAltroBufferV3::ReverseAndWrite() | |
95 | { | |
96 | // Reverse the altro data order and | |
97 | // write the buffer to the file | |
98 | UInt_t temp = 0; | |
99 | Int_t shift = 20; | |
69763d52 | 100 | for(Int_t i = (fN-1); i >= 0; i--) { |
5ca4e0a0 | 101 | temp |= (fArray[i] << shift); |
102 | shift -= 10; | |
103 | if (shift < 0) { | |
104 | fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t)); | |
105 | temp = 0; | |
106 | shift = 20; | |
107 | } | |
108 | } | |
109 | ||
110 | if (shift != 20) { | |
111 | fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t)); | |
112 | } | |
113 | ||
114 | fN = 0; | |
115 | } | |
116 | ||
117 | //_____________________________________________________________________________ | |
b73dbf18 | 118 | UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId) |
5ca4e0a0 | 119 | { |
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 | |
125 | // raw data writing. | |
126 | ||
127 | UInt_t currentFilePos = fFile->Tellp(); | |
128 | UInt_t size = currentFilePos-fDataHeaderPos; | |
129 | size -= sizeof(AliRawDataHeader); | |
b73dbf18 | 130 | size /= 4; |
5ca4e0a0 | 131 | |
b73dbf18 | 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)); | |
134 | return 2; | |
5ca4e0a0 | 135 | } |
136 | ||
b73dbf18 | 137 | // Now add the the RCU trailer tag |
138 | size |= (1 << 31); | |
5ca4e0a0 | 139 | fFile->WriteBuffer((char *)(&size),sizeof(UInt_t)); |
140 | ||
b73dbf18 | 141 | // Now several well defined fields contained |
142 | // in the trailer | |
143 | // For details check the RCU manual | |
144 | UInt_t buffer; | |
145 | ||
146 | buffer = (0x1 << 26); | |
147 | buffer |= (0x1 << 31); | |
148 | fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); | |
149 | ||
150 | buffer = (0x2 << 26); | |
151 | buffer |= (0x1 << 31); | |
152 | fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); | |
153 | ||
154 | buffer = (0x3 << 26); | |
155 | buffer |= (0x1 << 31); | |
156 | fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); | |
157 | ||
158 | buffer = 0x3FFFFFF; | |
159 | buffer |= (0x4 << 26); | |
160 | buffer |= (0x1 << 31); | |
161 | fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); | |
162 | buffer = 0x3FFFFFF; | |
163 | buffer |= (0x5 << 26); | |
164 | buffer |= (0x1 << 31); | |
165 | fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); | |
166 | ||
167 | buffer = (0x6 << 26); | |
168 | buffer |= (0x1 << 31); | |
169 | fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); | |
170 | ||
171 | buffer = (0x7 << 26); | |
172 | buffer |= (0x1 << 31); | |
173 | fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); | |
5ca4e0a0 | 174 | |
175 | // Now the RCU identifier and size of the trailer | |
b73dbf18 | 176 | buffer = (9 & 0x7F); |
5ca4e0a0 | 177 | buffer |= ((rcuId & 0x1FF) << 7); |
b73dbf18 | 178 | buffer |= (0x2 << 16); |
179 | buffer |= (0x8 << 26); | |
180 | buffer |= (0x3 << 30); | |
5ca4e0a0 | 181 | fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t)); |
182 | ||
b73dbf18 | 183 | return 2; |
5ca4e0a0 | 184 | } |