]>
Commit | Line | Data |
---|---|---|
e4da63c2 | 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 | /* $Id$ */ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // START raw data conversion class // | |
21 | // // | |
22 | /////////////////////////////////////////////////////////////////////////////// | |
23 | ||
24 | #include <Riostream.h> | |
25 | ||
26 | #include "AliSTART.h" | |
27 | #include "AliSTARTRawData.h" | |
28 | #include "AliSTARTdigit.h" | |
29 | #include "AliSTARTLoader.h" | |
30 | ||
31 | #include <AliLoader.h> | |
32 | #include <AliRunLoader.h> | |
33 | ||
19edf72f | 34 | #include "AliRawDataHeader.h" |
e4da63c2 | 35 | |
36 | ClassImp(AliSTARTRawData) | |
37 | ||
38 | //_____________________________________________________________________________ | |
39 | AliSTARTRawData::AliSTARTRawData():TObject() | |
40 | { | |
41 | ||
42 | ||
43 | fIndex=-1; | |
44 | fDigits = NULL; | |
45 | ||
46 | ftimeTDC = new TArrayI(24); | |
47 | fADC = new TArrayI(24); | |
48 | ||
49 | this->Dump(); | |
50 | ||
51 | } | |
52 | ||
53 | //_____________________________________________________________________________ | |
54 | AliSTARTRawData::AliSTARTRawData(const AliSTARTRawData &r):TObject() | |
55 | { | |
56 | // | |
57 | // AliSTARTrawData copy constructor | |
58 | // | |
59 | ||
60 | ((AliSTARTRawData &) r).Copy(*this); | |
61 | ||
62 | } | |
63 | ||
64 | //_____________________________________________________________________________ | |
65 | AliSTARTRawData::~AliSTARTRawData() | |
66 | { | |
67 | // | |
68 | // Destructor | |
69 | // | |
70 | ||
71 | if (fDigits) { | |
72 | delete fDigits; | |
73 | fDigits = NULL; | |
74 | delete ftimeTDC; | |
75 | delete fADC; | |
76 | } | |
77 | ||
78 | } | |
79 | ||
80 | //_____________________________________________________________________________ | |
81 | AliSTARTRawData &AliSTARTRawData::operator=(const AliSTARTRawData &r) | |
82 | { | |
83 | // | |
84 | // Assignment operator | |
85 | // | |
86 | ||
87 | if (this != &r) ((AliSTARTRawData &) r).Copy(*this); | |
88 | return *this; | |
89 | ||
90 | } | |
91 | ||
92 | //_____________________________________________________________________________ | |
93 | void AliSTARTRawData::GetDigits(AliSTARTdigit *fDigits, UInt_t *buf) | |
94 | { | |
95 | ||
96 | //This method packs the START digits in a proper 32 bits structure | |
97 | ||
98 | //read START digits and fill TDC and ADC arrays | |
99 | ||
100 | cout<<"GetDigits(AliSTARTdigit *fDigits, UInt_t *buf) "<<endl; | |
101 | UInt_t word; | |
102 | UInt_t baseWord=0; | |
103 | Int_t error=0; | |
104 | ||
105 | fDigits->Print(); | |
106 | ||
107 | // Get the digits array | |
108 | ||
109 | fDigits->GetTime(*ftimeTDC); | |
110 | fDigits->GetADC(*fADC); | |
111 | fBestTimeRight=fDigits->GetBestTimeRight(); | |
112 | fBestTimeLeft=fDigits->GetBestTimeLeft(); | |
113 | fMeanTime = fDigits-> GetMeanTime(); | |
114 | ||
115 | ||
116 | // Loop through all PMT | |
117 | ||
118 | ||
119 | for (Int_t det = 0; det < 24; det++) { | |
120 | Int_t time=ftimeTDC->At(det); | |
121 | Int_t ADC=fADC->At(det); | |
122 | printf(" right det %x time %x ADC %x \n",det,time,ADC); | |
123 | //conver ADC to time (preliminary algorithm) | |
124 | ||
125 | ||
126 | // DDL 1 0-5 -#PMT, 6-31 - empty | |
127 | ||
128 | word=det;; | |
129 | PackWord(baseWord,word, 0, 5); | |
130 | fIndex++; | |
131 | buf[fIndex]=baseWord; | |
132 | ||
133 | word=0; | |
134 | baseWord=0; | |
135 | ||
136 | //TDC | |
137 | word=error; | |
138 | PackWord(baseWord,word,0, 7); // Error flag | |
139 | word=time; | |
140 | PackWord(baseWord,word,8,31); // time-of-flight | |
141 | fIndex++; | |
142 | buf[fIndex]=baseWord; | |
143 | word=0; | |
144 | baseWord=0; | |
145 | ||
146 | // DDL2 2 0-5 -#PMT, 6-31 - empty | |
147 | word=det;; | |
148 | PackWord(baseWord,word, 0, 5); // number of PMT on the right side | |
149 | fIndex++; | |
150 | buf[fIndex]=baseWord; | |
151 | word=0; | |
152 | baseWord=0; | |
153 | ||
154 | // amplified TDC | |
155 | word=error; | |
156 | PackWord(baseWord,word,0, 7); // Error flag | |
157 | word=time; | |
158 | PackWord(baseWord,word,8,31); // time-of-flight | |
159 | fIndex++; | |
160 | buf[fIndex]=baseWord; | |
161 | word=0; | |
162 | baseWord=0; | |
163 | ||
164 | // DDL 3 | |
165 | word=det;; | |
166 | PackWord(baseWord,word, 0, 5); // number of PMT on the right side | |
167 | fIndex++; | |
168 | buf[fIndex]=baseWord; | |
169 | word=0; | |
170 | baseWord=0; | |
171 | ||
172 | // ADC -> TDC | |
173 | word=error; | |
174 | PackWord(baseWord,word,0, 7); // Error flag | |
175 | word=ADC; | |
176 | PackWord(baseWord,word,8,31); // time-of-flight | |
177 | fIndex++; | |
178 | buf[fIndex]=baseWord; | |
179 | ||
180 | //Amplified ADC -> TDC | |
181 | word=0; | |
182 | baseWord=0; | |
183 | ||
184 | word=det;; | |
185 | PackWord(baseWord,word, 0, 5); // number of PMT on the right side | |
186 | fIndex++; | |
187 | buf[fIndex]=baseWord; | |
188 | baseWord=0; | |
189 | word=error; | |
190 | PackWord(baseWord,word,0, 7); // Error flag | |
191 | word=ADC; | |
192 | PackWord(baseWord,word,8,31); // time-of-flight | |
193 | fIndex++; | |
194 | buf[fIndex]=baseWord; | |
195 | word=0; | |
196 | baseWord=0; | |
197 | ||
198 | ||
199 | } | |
200 | /* | |
201 | //timemean | |
202 | fIndex++; | |
203 | buf[fIndex]=baseWord; | |
204 | word=25; | |
205 | PackWord(baseWord,word, 0, 5); // number of PMT on the right side | |
206 | word=fMeanTime; | |
207 | PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin | |
208 | printf("meantime buf[%i]=%x\n",fIndex,buf[fIndex]); | |
209 | ||
210 | fIndex++; | |
211 | buf[fIndex]=baseWord; | |
212 | ||
213 | baseWord=0; | |
214 | ||
215 | word=error; | |
216 | PackWord(baseWord,word,0, 7); // Error flag | |
217 | word=fMeanTime; | |
218 | PackWord(baseWord,word,8,31); // time-of-flight | |
219 | ||
220 | fIndex++; | |
221 | buf[fIndex]=baseWord; | |
222 | ||
223 | printf("meantime buf[%i]=%x\n",fIndex,buf[fIndex]); | |
224 | ||
225 | ||
226 | // besttime right & left | |
227 | fIndex++; | |
228 | cout<<" left "<<fBestTimeLeft<<" right "<<fBestTimeRight<<endl; | |
229 | buf[fIndex]=baseWord; | |
230 | word=26; | |
231 | PackWord(baseWord,word, 0, 5); // number of PMT on the right side | |
232 | word=fBestTimeRight; | |
233 | PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin | |
234 | printf("best buf[%i]=%x\n",fIndex,buf[fIndex]); | |
235 | ||
236 | fIndex++; | |
237 | buf[fIndex]=baseWord; | |
238 | ||
239 | baseWord=0; | |
240 | ||
241 | word=error; | |
242 | PackWord(baseWord,word,0, 7); // Error flag | |
243 | word=fBestTimeRight; | |
244 | PackWord(baseWord,word,8,31); // time-of-flight | |
245 | ||
246 | fIndex++; | |
247 | buf[fIndex]=baseWord; | |
248 | ||
249 | printf("4 right buf[%i]=%x\n",fIndex,buf[fIndex]); | |
250 | ||
251 | word=27; | |
252 | PackWord(baseWord,word, 0, 5); // number of PMT on the right side | |
253 | word=fBestTimeLeft; | |
254 | PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin | |
255 | printf("5 left buf[%i]=%x\n",fIndex,buf[fIndex]); | |
256 | ||
257 | fIndex++; | |
258 | buf[fIndex]=baseWord; | |
259 | ||
260 | baseWord=0; | |
261 | ||
262 | word=error; | |
263 | PackWord(baseWord,word,0, 7); // Error flag | |
264 | word=fBestTimeLeft; | |
265 | PackWord(baseWord,word,8,31); // time-of-flight | |
266 | ||
267 | fIndex++; | |
268 | buf[fIndex]=baseWord; | |
269 | ||
270 | printf("5 left buf[%i]=%x\n",fIndex,buf[fIndex]); | |
271 | */ | |
272 | word=0; | |
273 | baseWord=0; | |
274 | ||
275 | } | |
276 | ||
277 | //------------------------------------------------------------------------------------- | |
278 | ||
279 | void AliSTARTRawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit) | |
280 | { | |
281 | //This method packs a word into the Baseword buffer starting form the "StartBit" | |
282 | //and tacking StopBit-StartBit+1 bits | |
283 | UInt_t dummyWord,offSet; | |
284 | Int_t length; | |
285 | UInt_t sum; | |
286 | //The BaseWord is being filled with 1 from StartBit to StopBit | |
287 | length=StopBit-StartBit+1; | |
288 | sum=(UInt_t)TMath::Power(2,length)-1; | |
289 | ||
290 | if(Word > sum){ | |
291 | Error("PackWord", "Word to be filled is not within desired length\n" | |
292 | "Word:%d Start bit:%d Stop Bit:%d",Word,StartBit,StopBit); | |
293 | return; | |
294 | } | |
295 | offSet=sum; | |
296 | offSet<<=StartBit; | |
297 | BaseWord=BaseWord|offSet; | |
298 | ||
299 | //The Word to be filled is shifted to the position StartBit | |
300 | //and the remaining Left and Right bits are filled with 1 | |
301 | sum=(UInt_t)TMath::Power(2,StartBit)-1; | |
302 | dummyWord=0xFFFFFFFF<<length; | |
303 | dummyWord +=Word; | |
304 | dummyWord<<=StartBit; | |
305 | dummyWord+=sum; | |
306 | BaseWord=BaseWord&dummyWord; | |
307 | ||
308 | return; | |
309 | } | |
310 | //--------------------------------------------------------------------------------------- | |
311 | ||
312 | Int_t AliSTARTRawData::RawDataSTART(AliSTARTdigit *fDigits){ | |
313 | ||
314 | //This method creates the Raw data files for TOF detector | |
315 | const Int_t kSize=512; //2*AliTOFGeometry::NpadXSector() | |
316 | //max number of digits per DDL file times 2 | |
317 | UInt_t buf[kSize]; | |
318 | UInt_t baseWord; | |
319 | UInt_t word; | |
320 | ||
321 | fIndex=-1; | |
322 | ||
323 | char fileName[15]; | |
324 | ofstream outfile; // logical name of the output file | |
325 | AliRawDataHeader header; | |
326 | cout<<" AliRawDataHeader header; start "<<endl; | |
327 | //loop over TOF DDL files | |
328 | sprintf(fileName,"START_0xd00.ddl"); //The name of the output file | |
329 | #ifndef __DECCXX | |
330 | outfile.open(fileName,ios::binary); | |
331 | #else | |
332 | outfile.open(fileName); | |
333 | #endif | |
334 | //write Dummy DATA HEADER | |
335 | UInt_t dataHeaderPosition=outfile.tellp(); | |
336 | outfile.write((char*)(&header),sizeof(header)); | |
337 | ||
338 | baseWord=0; | |
339 | word=0; | |
340 | PackWord(baseWord,word,0, 31); // Number of DDL file | |
341 | ||
342 | fIndex++; | |
343 | buf[fIndex]=baseWord; | |
344 | ||
345 | // branch->GetEvent(); | |
346 | ||
347 | //For each DDL file, buf contains the array of data words in Binary format | |
348 | //fIndex gives the number of 32 bits words in the buffer for each DDL file | |
349 | cout<<" AliSTARTRawData::RawDataSTART "<<fDigits<<endl; | |
350 | ||
351 | GetDigits(fDigits,buf); | |
352 | cout<<"REAL DATA "<<fIndex<<endl; | |
353 | outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t))); | |
354 | for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0; | |
355 | fIndex=-1; | |
356 | ||
357 | //Write REAL DATA HEADER | |
358 | UInt_t currentFilePosition=outfile.tellp(); | |
359 | outfile.seekp(dataHeaderPosition); | |
360 | header.fSize=currentFilePosition-dataHeaderPosition; | |
361 | header.SetAttribute(0); // valid data | |
362 | outfile.write((char*)(&header),sizeof(header)); | |
363 | outfile.close(); | |
364 | ||
365 | //end for | |
366 | ||
367 | return 0; | |
368 | ||
369 | } |