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