1 /**************************************************************************
2 * Copyright(c) 1998-2003, 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 **************************************************************************/
17 Revision 0.01 2004/6/11 A.De Caro, S.B.Sellitto, R.Silvestri
18 First implementation: global methods RawDataTOF
23 // This class contains the methods to create the Raw Data files
24 // for the TOF detector starting from the Digits.
25 // In this preliminary implementation, we defined the structure
26 // of the ALICE-TOF raw data starting from the current format
27 // for the TOF digits and the TOF raw data.
31 #include <Riostream.h>
32 #include <TClonesArray.h>
36 #include "AliTOFGeometry.h"
37 #include "AliTOFdigit.h"
38 #include "AliTOFDDLRawData.h"
39 #include "AliRawDataHeader.h"
41 ClassImp(AliTOFDDLRawData)
43 //----------------------------------------------------------------------------------------
44 AliTOFDDLRawData::AliTOFDDLRawData()
51 //----------------------------------------------------------------------------------------
53 AliTOFDDLRawData::AliTOFDDLRawData(const AliTOFDDLRawData &source) :
56 this->fIndex=source.fIndex;
57 this->fVerbose=source.fVerbose;
61 //---------------------------------------------------------------------------------------
63 AliTOFDDLRawData& AliTOFDDLRawData::operator=(const AliTOFDDLRawData &source){
65 this->fIndex=source.fIndex;
66 this->fVerbose=source.fVerbose;
70 //---------------------------------------------------------------------------------------
72 void AliTOFDDLRawData::GetDigits(TClonesArray *TOFdigits,Int_t nDDL,UInt_t *buf)
74 //This method packs the TOF digits in a proper 32 bits structure
75 Int_t iDDL=(Int_t)((nDDL/4.-(Int_t)(nDDL/4.))*4);
76 Int_t iSector=(Int_t)(nDDL/4.);
91 Int_t ndigits = TOFdigits->GetEntries();
96 Error("GetDigits", "No found TOF digits\n");
100 if (fVerbose==2) ftxt.open("TOFdigits.txt",ios::app);
101 for (Int_t digit=0;digit<ndigits;digit++) {
102 digs = (AliTOFdigit*)TOFdigits->UncheckedAt(digit);
103 sector=digs->GetSector(); // Sector Number (0-17)
104 plate=digs->GetPlate(); // Plate Number (0-4)
105 strip=digs->GetStrip(); // Strip Number (0-14/18/19)
106 padx=digs->GetPadx(); // Pad Number in x direction (0-47)
107 padz=digs->GetPadz(); // Pad Number in z direction (0-1)
108 eureka=digs->GetTotPad(); // Global Pad Number inside a Sector
109 totCharge = (Int_t)digs->GetAdc();
110 timeOfFlight = (Int_t)digs->GetTdc();
118 istriPlate = AliTOFGeometry::NStripC();
121 istriPlate = AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB();
124 istriPlate = AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA();
127 istriPlate = AliTOFGeometry::NStripC()+2*AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA();
131 eureka=2*padx+padz+AliTOFGeometry::NpadXStrip()*(strip+istriPlate);
133 if (eureka!=digs->GetTotPad()) printf(" eureka = %d AND digs->GetTotPad() = %d",eureka,digs->GetTotPad());
135 if (sector!=iSector || (Int_t)((Float_t)eureka/AliTOF::NPadXTRM()/AliTOF::NTRM())!=iDDL) continue;
137 if (fVerbose==2) ftxt <<" Sector: "<<sector<<" plate: "<<plate<<" strip "<<strip<<" padx "<<padx<<" padz "<<padz<<" eureka "<<eureka<<endl;
139 iTRM = (Int_t)((Float_t)eureka/AliTOF::NPadXTRM() - AliTOF::NTRM()*iDDL);
141 iTDC = (Int_t)(AliTOF::NTdc()*
143 (Float_t)eureka/AliTOF::NPadXTRM() -
144 (Int_t)((Float_t)eureka/AliTOF::NPadXTRM())
148 iCH = (Int_t)(AliTOF::NCh() *
150 (Float_t)eureka/AliTOF::NPadXTRM()*AliTOF::NTdc() - (Int_t)((Float_t)eureka/AliTOF::NPadXTRM()*AliTOF::NTdc()) -
151 (Int_t)((Float_t)eureka/AliTOF::NPadXTRM()*AliTOF::NTdc() - (Int_t)((Float_t)eureka/AliTOF::NPadXTRM()*AliTOF::NTdc()))
155 if (fVerbose==2) ftxt << "DDL: "<<iDDL<<" Sector: "<<sector<<" TRM: "<<iTRM<<" TDC: "<<iTDC<<" Channel: "<<iCH<<" totCharge: "<<totCharge<<" tof: "<<timeOfFlight<<endl;
160 PackWord(baseWord,word, 0, 3); // TRM ID
162 PackWord(baseWord,word, 4, 8); // TDC ID
164 PackWord(baseWord,word, 9,11); // CH ID
167 if (totCharge<0) word=TMath::Abs(totCharge);
169 PackWord(baseWord,word,12,31); // Charge (TOT)
172 buf[fIndex]=baseWord;
177 PackWord(baseWord,word,0, 7); // Error flag
179 PackWord(baseWord,word,8,31); // time-of-flight
182 buf[fIndex]=baseWord;
188 if (fVerbose==2) ftxt.close();
194 //-------------------------------------------------------------------------------------
196 void AliTOFDDLRawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
198 //This method packs a word into the Baseword buffer starting form the "StartBit"
199 //and tacking StopBit-StartBit+1 bits
200 UInt_t dummyWord,offSet;
203 //The BaseWord is being filled with 1 from StartBit to StopBit
204 length=StopBit-StartBit+1;
205 sum=(UInt_t)TMath::Power(2,length)-1;
208 Error("PackWord", "Word to be filled is not within desired length\n"
209 "Word:%d Start bit:%d Stop Bit:%d",Word,StartBit,StopBit);
214 BaseWord=BaseWord|offSet;
216 //The Word to be filled is shifted to the position StartBit
217 //and the remaining Left and Right bits are filled with 1
218 sum=(UInt_t)TMath::Power(2,StartBit)-1;
219 dummyWord=0xFFFFFFFF<<length;
221 dummyWord<<=StartBit;
223 BaseWord=BaseWord&dummyWord;
228 //------------------------------------------------------------------------------------------------
230 void AliTOFDDLRawData::UnpackWord(UInt_t PackedWord, Int_t StartBit, Int_t StopBit, UInt_t &Word)
232 //This method unpacks a words of StopBit-StartBit+1 bits starting from "StopBits"
235 length=StopBit-StartBit+1;
236 offSet=(UInt_t)TMath::Power(2,length)-1;
238 Word=PackedWord&offSet;
243 //---------------------------------------------------------------------------------------
245 Int_t AliTOFDDLRawData::RawDataTOF(TBranch* branch){
246 //This method creates the Raw data files for TOF detector
247 const Int_t kSize=5000; //2*AliTOFGeometry::NpadXSector()
248 //max number of digits per DDL file times 2
255 TClonesArray*& digits = * (TClonesArray**) branch->GetAddress();
257 ofstream outfile; // logical name of the output file
258 AliRawDataHeader header;
260 //loop over TOF DDL files
261 for(Int_t i=0;i<72;i++){
262 sprintf(fileName,"TOF_%d.ddl",i); //The name of the output file
264 outfile.open(fileName,ios::binary);
266 outfile.open(fileName);
268 //write Dummy DATA HEADER
269 UInt_t dataHeaderPosition=outfile.tellp();
270 outfile.write((char*)(&header),sizeof(header));
274 PackWord(baseWord,word,0, 31); // Number of DDL file
277 buf[fIndex]=baseWord;
281 //For each DDL file, buf contains the array of data words in Binary format
282 //fIndex gives the number of 32 bits words in the buffer for each DDL file
283 GetDigits(digits,i,buf);
284 outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
286 for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0;
289 //Write REAL DATA HEADER
290 UInt_t currentFilePosition=outfile.tellp();
291 outfile.seekp(dataHeaderPosition);
292 header.fSize=currentFilePosition-dataHeaderPosition;
293 header.SetAttribute(0); // valid data
294 outfile.write((char*)(&header),sizeof(header));
302 //-----------------------------------------------------------------------------------------
304 void AliTOFDDLRawData::WriteChipHeader(Int_t ChipAddr,Int_t EventCnt,UInt_t &BaseWord)
306 //This method writes a chip header
308 PackWord(BaseWord,ChipAddr,0,3);
309 PackWord(BaseWord,EventCnt,4,10);
310 PackWord(BaseWord,0x7,11,13);
311 PackWord(BaseWord,0x1,14,15);
313 }//end WriteChipHeader
315 //----------------------------------------------------------------------------------------
317 void AliTOFDDLRawData::ReadChipHeader(Int_t &ChipAddr,Int_t &EventCnt,UInt_t BaseWord)
319 //This method reads a chip header
321 UnpackWord(BaseWord,0,3,temp);
322 ChipAddr=(Int_t)temp;
323 UnpackWord(BaseWord,4,10,temp);
324 EventCnt=(Int_t)temp;
326 Info("ReadChipHeader", "Chip:&d Half Stave module:%d",ChipAddr,EventCnt);
328 }//end ReadChipHeader
330 //----------------------------------------------------------------------------------------
332 void AliTOFDDLRawData::WriteChipTrailer(UInt_t *buf,Int_t ChipHitCount,UInt_t &BaseWord)
334 //This method writes a chip trailer
336 if((ChipHitCount%2)!=0){
337 PackWord(BaseWord,0xFEDC,0,15);
339 PackWord(BaseWord,ChipHitCount,16,28);
340 PackWord(BaseWord,0x0,30,31);
342 buf[fIndex]=BaseWord;
345 }//end WriteChipTrailer
347 //------------------------------------------------------------------------------------------
349 void AliTOFDDLRawData::ReadChipTrailer(Int_t &ChipHitCount,UInt_t BaseWord)
351 //This method reads a chip trailer
353 UnpackWord(BaseWord,16,28,temp);
354 ChipHitCount=(Int_t)temp;
356 }//end ReadChipTrailer
358 //------------------------------------------------------------------------------------------