1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // START raw data conversion class //
22 ///////////////////////////////////////////////////////////////////////////////
24 #include <Riostream.h>
27 #include "AliSTARTRawData.h"
28 #include "AliSTARTdigit.h"
29 #include "AliSTARTLoader.h"
31 #include <AliLoader.h>
32 #include <AliRunLoader.h>
34 #include "AliRawDataHeader.h"
36 ClassImp(AliSTARTRawData)
38 //_____________________________________________________________________________
39 AliSTARTRawData::AliSTARTRawData():TObject()
46 ftimeTDC = new TArrayI(24);
47 fADC = new TArrayI(24);
53 //_____________________________________________________________________________
54 AliSTARTRawData::AliSTARTRawData(const AliSTARTRawData &r):TObject()
57 // AliSTARTrawData copy constructor
60 ((AliSTARTRawData &) r).Copy(*this);
64 //_____________________________________________________________________________
65 AliSTARTRawData::~AliSTARTRawData()
80 //_____________________________________________________________________________
81 AliSTARTRawData &AliSTARTRawData::operator=(const AliSTARTRawData &r)
84 // Assignment operator
87 if (this != &r) ((AliSTARTRawData &) r).Copy(*this);
92 //_____________________________________________________________________________
93 void AliSTARTRawData::GetDigits(AliSTARTdigit *fDigits, UInt_t *buf)
96 //This method packs the START digits in a proper 32 bits structure
98 //read START digits and fill TDC and ADC arrays
100 cout<<"GetDigits(AliSTARTdigit *fDigits, UInt_t *buf) "<<endl;
107 // Get the digits array
109 fDigits->GetTime(*ftimeTDC);
110 fDigits->GetADC(*fADC);
111 fBestTimeRight=fDigits->GetBestTimeRight();
112 fBestTimeLeft=fDigits->GetBestTimeLeft();
113 fMeanTime = fDigits-> GetMeanTime();
116 // Loop through all PMT
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)
126 // DDL 1 0-5 -#PMT, 6-31 - empty
129 PackWord(baseWord,word, 0, 5);
131 buf[fIndex]=baseWord;
138 PackWord(baseWord,word,0, 7); // Error flag
140 PackWord(baseWord,word,8,31); // time-of-flight
142 buf[fIndex]=baseWord;
146 // DDL2 2 0-5 -#PMT, 6-31 - empty
148 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
150 buf[fIndex]=baseWord;
156 PackWord(baseWord,word,0, 7); // Error flag
158 PackWord(baseWord,word,8,31); // time-of-flight
160 buf[fIndex]=baseWord;
166 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
168 buf[fIndex]=baseWord;
174 PackWord(baseWord,word,0, 7); // Error flag
176 PackWord(baseWord,word,8,31); // time-of-flight
178 buf[fIndex]=baseWord;
180 //Amplified ADC -> TDC
185 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
187 buf[fIndex]=baseWord;
190 PackWord(baseWord,word,0, 7); // Error flag
192 PackWord(baseWord,word,8,31); // time-of-flight
194 buf[fIndex]=baseWord;
203 buf[fIndex]=baseWord;
205 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
207 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
208 printf("meantime buf[%i]=%x\n",fIndex,buf[fIndex]);
211 buf[fIndex]=baseWord;
216 PackWord(baseWord,word,0, 7); // Error flag
218 PackWord(baseWord,word,8,31); // time-of-flight
221 buf[fIndex]=baseWord;
223 printf("meantime buf[%i]=%x\n",fIndex,buf[fIndex]);
226 // besttime right & left
228 cout<<" left "<<fBestTimeLeft<<" right "<<fBestTimeRight<<endl;
229 buf[fIndex]=baseWord;
231 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
233 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
234 printf("best buf[%i]=%x\n",fIndex,buf[fIndex]);
237 buf[fIndex]=baseWord;
242 PackWord(baseWord,word,0, 7); // Error flag
244 PackWord(baseWord,word,8,31); // time-of-flight
247 buf[fIndex]=baseWord;
249 printf("4 right buf[%i]=%x\n",fIndex,buf[fIndex]);
252 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
254 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
255 printf("5 left buf[%i]=%x\n",fIndex,buf[fIndex]);
258 buf[fIndex]=baseWord;
263 PackWord(baseWord,word,0, 7); // Error flag
265 PackWord(baseWord,word,8,31); // time-of-flight
268 buf[fIndex]=baseWord;
270 printf("5 left buf[%i]=%x\n",fIndex,buf[fIndex]);
277 //-------------------------------------------------------------------------------------
279 void AliSTARTRawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
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;
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;
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);
297 BaseWord=BaseWord|offSet;
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;
304 dummyWord<<=StartBit;
306 BaseWord=BaseWord&dummyWord;
310 //---------------------------------------------------------------------------------------
312 Int_t AliSTARTRawData::RawDataSTART(AliSTARTdigit *fDigits){
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
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
330 outfile.open(fileName,ios::binary);
332 outfile.open(fileName);
334 //write Dummy DATA HEADER
335 UInt_t dataHeaderPosition=outfile.tellp();
336 outfile.write((char*)(&header),sizeof(header));
340 PackWord(baseWord,word,0, 31); // Number of DDL file
343 buf[fIndex]=baseWord;
345 // branch->GetEvent();
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;
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;
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));