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"
35 #include "AliRawData.h"
37 ClassImp(AliSTARTRawData)
39 //_____________________________________________________________________________
40 AliSTARTRawData::AliSTARTRawData():TObject()
47 ftimeTDC = new TArrayI(24);
48 fADC = new TArrayI(24);
54 //_____________________________________________________________________________
55 AliSTARTRawData::AliSTARTRawData(const AliSTARTRawData &r):TObject()
58 // AliSTARTrawData copy constructor
61 ((AliSTARTRawData &) r).Copy(*this);
65 //_____________________________________________________________________________
66 AliSTARTRawData::~AliSTARTRawData()
81 //_____________________________________________________________________________
82 AliSTARTRawData &AliSTARTRawData::operator=(const AliSTARTRawData &r)
85 // Assignment operator
88 if (this != &r) ((AliSTARTRawData &) r).Copy(*this);
93 //_____________________________________________________________________________
94 void AliSTARTRawData::GetDigits(AliSTARTdigit *fDigits, UInt_t *buf)
97 //This method packs the START digits in a proper 32 bits structure
99 //read START digits and fill TDC and ADC arrays
101 cout<<"GetDigits(AliSTARTdigit *fDigits, UInt_t *buf) "<<endl;
108 // Get the digits array
110 fDigits->GetTime(*ftimeTDC);
111 fDigits->GetADC(*fADC);
112 fBestTimeRight=fDigits->GetBestTimeRight();
113 fBestTimeLeft=fDigits->GetBestTimeLeft();
114 fMeanTime = fDigits-> GetMeanTime();
117 // Loop through all PMT
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)
127 // DDL 1 0-5 -#PMT, 6-31 - empty
130 PackWord(baseWord,word, 0, 5);
132 buf[fIndex]=baseWord;
139 PackWord(baseWord,word,0, 7); // Error flag
141 PackWord(baseWord,word,8,31); // time-of-flight
143 buf[fIndex]=baseWord;
147 // DDL2 2 0-5 -#PMT, 6-31 - empty
149 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
151 buf[fIndex]=baseWord;
157 PackWord(baseWord,word,0, 7); // Error flag
159 PackWord(baseWord,word,8,31); // time-of-flight
161 buf[fIndex]=baseWord;
167 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
169 buf[fIndex]=baseWord;
175 PackWord(baseWord,word,0, 7); // Error flag
177 PackWord(baseWord,word,8,31); // time-of-flight
179 buf[fIndex]=baseWord;
181 //Amplified ADC -> TDC
186 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
188 buf[fIndex]=baseWord;
191 PackWord(baseWord,word,0, 7); // Error flag
193 PackWord(baseWord,word,8,31); // time-of-flight
195 buf[fIndex]=baseWord;
204 buf[fIndex]=baseWord;
206 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
208 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
209 printf("meantime buf[%i]=%x\n",fIndex,buf[fIndex]);
212 buf[fIndex]=baseWord;
217 PackWord(baseWord,word,0, 7); // Error flag
219 PackWord(baseWord,word,8,31); // time-of-flight
222 buf[fIndex]=baseWord;
224 printf("meantime buf[%i]=%x\n",fIndex,buf[fIndex]);
227 // besttime right & left
229 cout<<" left "<<fBestTimeLeft<<" right "<<fBestTimeRight<<endl;
230 buf[fIndex]=baseWord;
232 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
234 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
235 printf("best buf[%i]=%x\n",fIndex,buf[fIndex]);
238 buf[fIndex]=baseWord;
243 PackWord(baseWord,word,0, 7); // Error flag
245 PackWord(baseWord,word,8,31); // time-of-flight
248 buf[fIndex]=baseWord;
250 printf("4 right buf[%i]=%x\n",fIndex,buf[fIndex]);
253 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
255 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
256 printf("5 left buf[%i]=%x\n",fIndex,buf[fIndex]);
259 buf[fIndex]=baseWord;
264 PackWord(baseWord,word,0, 7); // Error flag
266 PackWord(baseWord,word,8,31); // time-of-flight
269 buf[fIndex]=baseWord;
271 printf("5 left buf[%i]=%x\n",fIndex,buf[fIndex]);
278 //-------------------------------------------------------------------------------------
280 void AliSTARTRawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
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;
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;
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);
298 BaseWord=BaseWord|offSet;
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;
305 dummyWord<<=StartBit;
307 BaseWord=BaseWord&dummyWord;
311 //---------------------------------------------------------------------------------------
313 Int_t AliSTARTRawData::RawDataSTART(AliSTARTdigit *fDigits){
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
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
331 outfile.open(fileName,ios::binary);
333 outfile.open(fileName);
335 //write Dummy DATA HEADER
336 UInt_t dataHeaderPosition=outfile.tellp();
337 outfile.write((char*)(&header),sizeof(header));
341 PackWord(baseWord,word,0, 31); // Number of DDL file
344 buf[fIndex]=baseWord;
346 // branch->GetEvent();
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;
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;
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));