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