AliSTARTRawData.cxx AliSTARTRawData.h Coding Convemtion Violetions fixed according...
[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"
db173afc 29#include <TTree.h>
19edf72f 30#include "AliRawDataHeader.h"
e4da63c2 31
32ClassImp(AliSTARTRawData)
33
34//_____________________________________________________________________________
35AliSTARTRawData::AliSTARTRawData():TObject()
36{
06fb27f4 37 /*
38- 48 channels (2 words each as in TOF DDL) for :
39word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
40and the same but for amplified signal. Now I wrote the same time because
41CDF are not ready and differences didn't measured yet.
42
43- 96 channel for amplitude: very preliminary, QTC features are not
44known now, preliminary i put as T1 time signal for this PMT in first
45channel and T1+A in second, where A=Log(Amplitude);
46and the same for amplified but A=Log(10*Amplitude).
47
48- T0-A and T0-C 2 channels
49- T0A-T0C vertex information
50- Time Meaner where T0C TOF increase to the T0A TOF distance
51- 6 multiplicity signals the same way as amplitude and with the same
52uncertances
53 */
e4da63c2 54
55 fIndex=-1;
56 fDigits = NULL;
db173afc 57
06fb27f4 58 fTimeTDC = new TArrayI(24);
db173afc 59 fADC = new TArrayI(24);
06fb27f4 60 fTimeTDCAmp = new TArrayI(24);
db173afc 61 fADCAmp = new TArrayI(24);
62 fSumMult = new TArrayI(6);
63 // this->Dump();
e4da63c2 64
65}
66
67//_____________________________________________________________________________
68AliSTARTRawData::AliSTARTRawData(const AliSTARTRawData &r):TObject()
69{
70 //
71 // AliSTARTrawData copy constructor
72 //
73
74 ((AliSTARTRawData &) r).Copy(*this);
75
76}
77
78//_____________________________________________________________________________
79AliSTARTRawData::~AliSTARTRawData()
80{
81 //
82 // Destructor
83 //
e4da63c2 84 if (fDigits) {
85 delete fDigits;
86 fDigits = NULL;
e4da63c2 87 }
06fb27f4 88 delete fTimeTDC;
db173afc 89 delete fADC;
06fb27f4 90 delete fTimeTDCAmp;
db173afc 91 delete fADCAmp;
92 delete fSumMult;
e4da63c2 93}
94
95//_____________________________________________________________________________
96AliSTARTRawData &AliSTARTRawData::operator=(const AliSTARTRawData &r)
97{
98 //
99 // Assignment operator
100 //
101
102 if (this != &r) ((AliSTARTRawData &) r).Copy(*this);
103 return *this;
104
105}
106
107//_____________________________________________________________________________
108void AliSTARTRawData::GetDigits(AliSTARTdigit *fDigits, UInt_t *buf)
109{
110
111 //This method packs the START digits in a proper 32 bits structure
112
113 //read START digits and fill TDC and ADC arrays
114
db173afc 115
e4da63c2 116 UInt_t word;
117 UInt_t baseWord=0;
118 Int_t error=0;
db173afc 119 // Get the digits array
e4da63c2 120
06fb27f4 121 fDigits->GetTime(*fTimeTDC);
db173afc 122 fDigits->GetADC(*fADC);
06fb27f4 123 fDigits->GetTimeAmp(*fTimeTDCAmp);
db173afc 124 fDigits->GetADCAmp(*fADCAmp);
125 fDigits->GetSumMult(*fSumMult);
e4da63c2 126
127 // Loop through all PMT
128
e4da63c2 129 for (Int_t det = 0; det < 24; det++) {
06fb27f4 130 Int_t time=fTimeTDC->At(det);
db173afc 131 Int_t qtc=fADC->At(det);
06fb27f4 132 Int_t timeAmp=fTimeTDCAmp->At(det);
db173afc 133 Int_t qtcAmp=fADCAmp->At(det);
e4da63c2 134
db173afc 135 //conver ADC to time (preliminary algorithm)
e4da63c2 136
137 // DDL 1 0-5 -#PMT, 6-31 - empty
138
139 word=det;;
140 PackWord(baseWord,word, 0, 5);
141 fIndex++;
142 buf[fIndex]=baseWord;
143
144 word=0;
145 baseWord=0;
146
db173afc 147 //TDC
e4da63c2 148 word=error;
149 PackWord(baseWord,word,0, 7); // Error flag
150 word=time;
151 PackWord(baseWord,word,8,31); // time-of-flight
152 fIndex++;
153 buf[fIndex]=baseWord;
db173afc 154
e4da63c2 155 word=0;
156 baseWord=0;
157
158 // DDL2 2 0-5 -#PMT, 6-31 - empty
159 word=det;;
160 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
161 fIndex++;
162 buf[fIndex]=baseWord;
163 word=0;
164 baseWord=0;
165
166 // amplified TDC
167 word=error;
168 PackWord(baseWord,word,0, 7); // Error flag
db173afc 169 word=timeAmp;
e4da63c2 170 PackWord(baseWord,word,8,31); // time-of-flight
171 fIndex++;
172 buf[fIndex]=baseWord;
db173afc 173
e4da63c2 174 word=0;
175 baseWord=0;
176
177 // DDL 3
178 word=det;;
179 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
180 fIndex++;
181 buf[fIndex]=baseWord;
182 word=0;
183 baseWord=0;
184
185 // ADC -> TDC
186 word=error;
187 PackWord(baseWord,word,0, 7); // Error flag
db173afc 188 word=time;
e4da63c2 189 PackWord(baseWord,word,8,31); // time-of-flight
190 fIndex++;
191 buf[fIndex]=baseWord;
192
db173afc 193
194 // ADC -> TDC :QTC
e4da63c2 195 word=0;
196 baseWord=0;
197
198 word=det;;
199 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
200 fIndex++;
201 buf[fIndex]=baseWord;
202 baseWord=0;
203 word=error;
204 PackWord(baseWord,word,0, 7); // Error flag
db173afc 205 word=time+qtc;
e4da63c2 206 PackWord(baseWord,word,8,31); // time-of-flight
207 fIndex++;
208 buf[fIndex]=baseWord;
db173afc 209
e4da63c2 210 word=0;
211 baseWord=0;
212
db173afc 213 // DDL 4 amplified QTC charge * 10
214 word=det;;
215 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
216 fIndex++;
217 buf[fIndex]=baseWord;
218 word=0;
219 baseWord=0;
e4da63c2 220
db173afc 221 // ADC -> TDC
222 word=error;
223 PackWord(baseWord,word,0, 7); // Error flag
224 word=timeAmp;
225 PackWord(baseWord,word,8,31); // time-of-flight
226 fIndex++;
227 buf[fIndex]=baseWord;
228
229 //Amplified ADC -> TDC
230 word=0;
231 baseWord=0;
232
233 word=det;;
234 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
235 fIndex++;
236 buf[fIndex]=baseWord;
237 baseWord=0;
238 word=error;
239 PackWord(baseWord,word,0, 7); // Error flag
240 word=time+qtcAmp;
241 PackWord(baseWord,word,8,31); // time-of-flight
242 fIndex++;
243 buf[fIndex]=baseWord;
244
245 word=0;
246 baseWord=0;
e4da63c2 247 }
db173afc 248
249
250 word=0;
251 baseWord=0;
e4da63c2 252 fIndex++;
e4da63c2 253 word=25;
254 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
db173afc 255 word=fDigits->MeanTime();
e4da63c2 256 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
e4da63c2 257 buf[fIndex]=baseWord;
db173afc 258
e4da63c2 259 baseWord=0;
e4da63c2 260 word=error;
261 PackWord(baseWord,word,0, 7); // Error flag
db173afc 262 word=fDigits->MeanTime();
e4da63c2 263 PackWord(baseWord,word,8,31); // time-of-flight
e4da63c2 264 fIndex++;
265 buf[fIndex]=baseWord;
e4da63c2 266
db173afc 267
268
e4da63c2 269 // besttime right & left
db173afc 270 // fIndex++;
271 // buf[fIndex]=baseWord;
e4da63c2 272 word=26;
273 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
db173afc 274 word=fDigits->BestTimeRight();
e4da63c2 275 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
e4da63c2 276 fIndex++;
277 buf[fIndex]=baseWord;
db173afc 278
e4da63c2 279 baseWord=0;
e4da63c2 280 word=error;
281 PackWord(baseWord,word,0, 7); // Error flag
db173afc 282 word=fDigits->BestTimeRight();
e4da63c2 283 PackWord(baseWord,word,8,31); // time-of-flight
e4da63c2 284 fIndex++;
285 buf[fIndex]=baseWord;
db173afc 286
e4da63c2 287 word=27;
288 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
db173afc 289 word=fDigits->BestTimeLeft();
e4da63c2 290 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
e4da63c2 291 fIndex++;
292 buf[fIndex]=baseWord;
db173afc 293
e4da63c2 294 baseWord=0;
db173afc 295
e4da63c2 296 word=error;
297 PackWord(baseWord,word,0, 7); // Error flag
db173afc 298 word=fDigits->BestTimeLeft();
e4da63c2 299 PackWord(baseWord,word,8,31); // time-of-flight
e4da63c2 300 fIndex++;
301 buf[fIndex]=baseWord;
db173afc 302
303 // time difference
304 word=28;
305 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
306 word=fDigits->TimeDiff();
307 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
308 fIndex++;
309 buf[fIndex]=baseWord;
310
e4da63c2 311 baseWord=0;
db173afc 312
313 word=error;
314 PackWord(baseWord,word,0, 7); // Error flag
315 word=fDigits->TimeDiff();
316 PackWord(baseWord,word,8,31); // time-of-flight
317 fIndex++;
318 buf[fIndex]=baseWord;
319
320 // multiplicity
321
322 for (Int_t i=0; i<6; i++)
323 {
324 Int_t mult=fSumMult->At(i);
325 word=29+i;
326 PackWord(baseWord,word, 0, 5);
327 word=mult;
328 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
329 fIndex++;
330 buf[fIndex]=baseWord;
331
332 baseWord=0;
333 word=error;
334 PackWord(baseWord,word,0, 7); // Error flag
335 word=mult;
336 PackWord(baseWord,word,8,31); // time QTC
337 fIndex++;
338 buf[fIndex]=baseWord;
339 }
340 cout<<endl;
e4da63c2 341}
342
343//-------------------------------------------------------------------------------------
344
345void AliSTARTRawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
346{
347 //This method packs a word into the Baseword buffer starting form the "StartBit"
348 //and tacking StopBit-StartBit+1 bits
349 UInt_t dummyWord,offSet;
350 Int_t length;
351 UInt_t sum;
352 //The BaseWord is being filled with 1 from StartBit to StopBit
353 length=StopBit-StartBit+1;
354 sum=(UInt_t)TMath::Power(2,length)-1;
355
356 if(Word > sum){
357 Error("PackWord", "Word to be filled is not within desired length\n"
358 "Word:%d Start bit:%d Stop Bit:%d",Word,StartBit,StopBit);
359 return;
360 }
361 offSet=sum;
362 offSet<<=StartBit;
363 BaseWord=BaseWord|offSet;
364
365 //The Word to be filled is shifted to the position StartBit
366 //and the remaining Left and Right bits are filled with 1
367 sum=(UInt_t)TMath::Power(2,StartBit)-1;
368 dummyWord=0xFFFFFFFF<<length;
369 dummyWord +=Word;
370 dummyWord<<=StartBit;
371 dummyWord+=sum;
372 BaseWord=BaseWord&dummyWord;
373
374 return;
375}
376//---------------------------------------------------------------------------------------
377
06fb27f4 378Int_t AliSTARTRawData::RawDataSTART(AliSTARTdigit *fDigits)
379{
380 //This method creates the Raw data files for START detector
381
382
e4da63c2 383 const Int_t kSize=512; //2*AliTOFGeometry::NpadXSector()
384 //max number of digits per DDL file times 2
385 UInt_t buf[kSize];
386 UInt_t baseWord;
387 UInt_t word;
388
389 fIndex=-1;
390
391 char fileName[15];
392 ofstream outfile; // logical name of the output file
393 AliRawDataHeader header;
e4da63c2 394 //loop over TOF DDL files
db173afc 395 sprintf(fileName,"START_%d.ddl", 0xd00);
396 // sprintf(fileName,"START_0xd00.ddl"); //The name of the output file
e4da63c2 397#ifndef __DECCXX
398 outfile.open(fileName,ios::binary);
399#else
400 outfile.open(fileName);
401#endif
402 //write Dummy DATA HEADER
403 UInt_t dataHeaderPosition=outfile.tellp();
404 outfile.write((char*)(&header),sizeof(header));
405
406 baseWord=0;
407 word=0;
408 PackWord(baseWord,word,0, 31); // Number of DDL file
409
410 fIndex++;
411 buf[fIndex]=baseWord;
e4da63c2 412 GetDigits(fDigits,buf);
db173afc 413
414 outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
e4da63c2 415 for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0;
db173afc 416 fIndex=-1;
e4da63c2 417
418 //Write REAL DATA HEADER
419 UInt_t currentFilePosition=outfile.tellp();
420 outfile.seekp(dataHeaderPosition);
421 header.fSize=currentFilePosition-dataHeaderPosition;
422 header.SetAttribute(0); // valid data
423 outfile.write((char*)(&header),sizeof(header));
424 outfile.close();
425
426 //end for
427
428 return 0;
429
430}