]> git.uio.no Git - u/mrichter/AliRoot.git/blob - START/AliSTARTRawData.cxx
Library split
[u/mrichter/AliRoot.git] / START / AliSTARTRawData.cxx
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 <TTree.h>
30 #include "AliRawDataHeader.h"
31
32 ClassImp(AliSTARTRawData)
33
34 //_____________________________________________________________________________
35 AliSTARTRawData::AliSTARTRawData():TObject()
36 {
37   /*
38 -  48 channels (2 words each as in TOF DDL) for :
39 word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
40 and the same but for amplified signal. Now I wrote the same time because
41 CDF are not ready and differences didn't measured yet.
42
43 -  96 channel for amplitude: very preliminary, QTC features are not
44 known now, preliminary i put as T1 time signal for this PMT in first
45 channel and T1+A in second, where A=Log(Amplitude);
46 and 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
52 uncertances
53   */
54
55   fIndex=-1;
56   fDigits = NULL;
57
58   fTimeTDC = new TArrayI(24);
59   fADC = new TArrayI(24);
60   fTimeTDCAmp = new TArrayI(24);
61   fADCAmp = new TArrayI(24);
62   fSumMult = new TArrayI(6);
63    //   this->Dump();
64   
65 }
66
67 //_____________________________________________________________________________
68 AliSTARTRawData::AliSTARTRawData(const AliSTARTRawData &r):TObject()
69 {
70   //
71   // AliSTARTrawData copy constructor
72   //
73
74   ((AliSTARTRawData &) r).Copy(*this);
75
76 }
77
78 //_____________________________________________________________________________
79 AliSTARTRawData::~AliSTARTRawData()
80 {
81   //
82   // Destructor
83   //
84   if (fDigits) {
85     delete fDigits;
86     fDigits = NULL;
87   }
88   delete fTimeTDC;
89   delete fADC;
90   delete fTimeTDCAmp;
91   delete fADCAmp;
92   delete fSumMult;
93 }
94
95 //_____________________________________________________________________________
96 AliSTARTRawData &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 //_____________________________________________________________________________
108 void 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
115
116   UInt_t word;
117   UInt_t baseWord=0;
118   Int_t error=0;
119     // Get the digits array
120
121   fDigits->GetTime(*fTimeTDC);
122   fDigits->GetADC(*fADC);
123   fDigits->GetTimeAmp(*fTimeTDCAmp);
124   fDigits->GetADCAmp(*fADCAmp);
125   fDigits->GetSumMult(*fSumMult);
126      
127   // Loop through all PMT
128  
129   for (Int_t det = 0; det < 24; det++) {
130     Int_t time=fTimeTDC->At(det);
131     Int_t qtc=fADC->At(det);
132     Int_t timeAmp=fTimeTDCAmp->At(det);
133     Int_t qtcAmp=fADCAmp->At(det);
134
135     //conver ADC to time (preliminary algorithm)
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
147      //TDC    
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;
154
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
169      word=timeAmp;
170      PackWord(baseWord,word,8,31); // time-of-flight
171      fIndex++;
172      buf[fIndex]=baseWord;
173
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
188      word=time;
189      PackWord(baseWord,word,8,31); // time-of-flight
190      fIndex++;
191      buf[fIndex]=baseWord;
192
193
194      // ADC -> TDC :QTC 
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
205      word=time+qtc;
206      PackWord(baseWord,word,8,31); // time-of-flight
207      fIndex++;
208      buf[fIndex]=baseWord;
209
210      word=0;
211      baseWord=0;
212
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;
220
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;
247  }
248
249
250   word=0;
251   baseWord=0;
252   fIndex++;
253   word=25;
254   PackWord(baseWord,word, 0, 5); // number of PMT on the right side
255   word=fDigits->MeanTime();
256   PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
257   buf[fIndex]=baseWord;
258
259   baseWord=0;
260   word=error;
261   PackWord(baseWord,word,0, 7); // Error flag
262   word=fDigits->MeanTime();
263   PackWord(baseWord,word,8,31); // time-of-flight
264   fIndex++;
265   buf[fIndex]=baseWord;
266
267
268
269   // besttime right & left
270   //  fIndex++;
271   //  buf[fIndex]=baseWord;
272   word=26;
273   PackWord(baseWord,word, 0, 5); // number of PMT on the right side
274   word=fDigits->BestTimeRight();
275   PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
276   fIndex++;
277   buf[fIndex]=baseWord;
278
279   baseWord=0;
280   word=error;
281   PackWord(baseWord,word,0, 7); // Error flag
282   word=fDigits->BestTimeRight();
283   PackWord(baseWord,word,8,31); // time-of-flight
284   fIndex++;
285   buf[fIndex]=baseWord;
286
287   word=27;
288   PackWord(baseWord,word, 0, 5); // number of PMT on the right side
289   word=fDigits->BestTimeLeft();
290   PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
291   fIndex++;
292   buf[fIndex]=baseWord;
293
294   baseWord=0;
295
296   word=error;
297   PackWord(baseWord,word,0, 7); // Error flag
298   word=fDigits->BestTimeLeft();
299   PackWord(baseWord,word,8,31); // time-of-flight
300   fIndex++;
301   buf[fIndex]=baseWord;
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
311   baseWord=0;
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;
341 }
342
343 //-------------------------------------------------------------------------------------
344
345 void 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
378 Int_t AliSTARTRawData::RawDataSTART(AliSTARTdigit *fDigits)
379 {
380    //This method creates the Raw data files for START detector
381
382
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;
394   //loop over TOF DDL files
395   sprintf(fileName,"START_%d.ddl", 0xd00);
396   //   sprintf(fileName,"START_0xd00.ddl"); //The name of the output file
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;
412     GetDigits(fDigits,buf);
413
414     outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
415     for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0;
416     fIndex=-1;
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 }