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>
33 #include <TClonesArray.h>
35 #include "AliRawDataHeader.h"
37 ClassImp(AliSTARTRawData)
39 //_____________________________________________________________________________
40 AliSTARTRawData::AliSTARTRawData():TObject()
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);
56 //_____________________________________________________________________________
57 AliSTARTRawData::AliSTARTRawData(const AliSTARTRawData &r):TObject()
60 // AliSTARTrawData copy constructor
63 ((AliSTARTRawData &) r).Copy(*this);
67 //_____________________________________________________________________________
68 AliSTARTRawData::~AliSTARTRawData()
84 //_____________________________________________________________________________
85 AliSTARTRawData &AliSTARTRawData::operator=(const AliSTARTRawData &r)
88 // Assignment operator
91 if (this != &r) ((AliSTARTRawData &) r).Copy(*this);
96 //_____________________________________________________________________________
97 void AliSTARTRawData::GetDigits(AliSTARTdigit *fDigits, UInt_t *buf)
100 //This method packs the START digits in a proper 32 bits structure
102 //read START digits and fill TDC and ADC arrays
108 // Get the digits array
110 fDigits->GetTime(*ftimeTDC);
111 fDigits->GetADC(*fADC);
112 fDigits->GetTimeAmp(*ftimeTDCAmp);
113 fDigits->GetADCAmp(*fADCAmp);
114 fDigits->GetSumMult(*fSumMult);
116 // Loop through all PMT
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);
124 //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;
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;
168 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
170 buf[fIndex]=baseWord;
176 PackWord(baseWord,word,0, 7); // Error flag
178 PackWord(baseWord,word,8,31); // time-of-flight
180 buf[fIndex]=baseWord;
188 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
190 buf[fIndex]=baseWord;
193 PackWord(baseWord,word,0, 7); // Error flag
195 PackWord(baseWord,word,8,31); // time-of-flight
197 buf[fIndex]=baseWord;
202 // DDL 4 amplified QTC charge * 10
204 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
206 buf[fIndex]=baseWord;
212 PackWord(baseWord,word,0, 7); // Error flag
214 PackWord(baseWord,word,8,31); // time-of-flight
216 buf[fIndex]=baseWord;
218 //Amplified ADC -> TDC
223 PackWord(baseWord,word, 0, 5); // number of PMT on the right side
225 buf[fIndex]=baseWord;
228 PackWord(baseWord,word,0, 7); // Error flag
230 PackWord(baseWord,word,8,31); // time-of-flight
232 buf[fIndex]=baseWord;
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;
250 PackWord(baseWord,word,0, 7); // Error flag
251 word=fDigits->MeanTime();
252 PackWord(baseWord,word,8,31); // time-of-flight
254 buf[fIndex]=baseWord;
258 // besttime right & left
260 // buf[fIndex]=baseWord;
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
266 buf[fIndex]=baseWord;
270 PackWord(baseWord,word,0, 7); // Error flag
271 word=fDigits->BestTimeRight();
272 PackWord(baseWord,word,8,31); // time-of-flight
274 buf[fIndex]=baseWord;
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
281 buf[fIndex]=baseWord;
286 PackWord(baseWord,word,0, 7); // Error flag
287 word=fDigits->BestTimeLeft();
288 PackWord(baseWord,word,8,31); // time-of-flight
290 buf[fIndex]=baseWord;
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
298 buf[fIndex]=baseWord;
303 PackWord(baseWord,word,0, 7); // Error flag
304 word=fDigits->TimeDiff();
305 PackWord(baseWord,word,8,31); // time-of-flight
307 buf[fIndex]=baseWord;
311 for (Int_t i=0; i<6; i++)
313 Int_t mult=fSumMult->At(i);
315 PackWord(baseWord,word, 0, 5);
317 PackWord(baseWord,word, 6, 31); // TDC on the right side from Marin
319 buf[fIndex]=baseWord;
323 PackWord(baseWord,word,0, 7); // Error flag
325 PackWord(baseWord,word,8,31); // time QTC
327 buf[fIndex]=baseWord;
332 //-------------------------------------------------------------------------------------
334 void AliSTARTRawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
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;
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;
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);
352 BaseWord=BaseWord|offSet;
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;
359 dummyWord<<=StartBit;
361 BaseWord=BaseWord&dummyWord;
365 //---------------------------------------------------------------------------------------
367 Int_t AliSTARTRawData::RawDataSTART(AliSTARTdigit *fDigits){
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
377 // TClonesArray*& digits = * (TClonesArray**) branch->GetAddress();
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
386 outfile.open(fileName,ios::binary);
388 outfile.open(fileName);
390 //write Dummy DATA HEADER
391 UInt_t dataHeaderPosition=outfile.tellp();
392 outfile.write((char*)(&header),sizeof(header));
396 PackWord(baseWord,word,0, 31); // Number of DDL file
399 buf[fIndex]=baseWord;
400 GetDigits(fDigits,buf);
402 outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
403 for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0;
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));