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.02 2005/7/25 A.De Caro
18 Update number of bits allocated for time-of-flight
19 and 'charge' measurements
21 Revision 0.01 2004/6/11 A.De Caro, S.B.Sellitto, R.Silvestri
22 First implementation: global methods RawDataTOF
26 //////////////////////////////////////////////////////////////////
28 // This class contains the methods to create the Raw Data files
29 // for the TOF detector starting from the Digits.
30 // In this preliminary implementation, we defined the structure
31 // of the ALICE-TOF raw data starting from the current format
32 // for the TOF digits and the TOF raw data.
34 //////////////////////////////////////////////////////////////////
37 #include <Riostream.h>
38 #include <TClonesArray.h>
43 #include "AliRawDataHeader.h"
44 #include "AliBitPacking.h"
46 #include "AliTOFGeometry.h"
47 #include "AliTOFGeometryV4.h"
48 #include "AliTOFGeometryV5.h"
49 #include "AliTOFdigit.h"
50 #include "AliTOFRawStream.h"
51 #include "AliTOFDDLRawData.h"
53 ClassImp(AliTOFDDLRawData)
55 //----------------------------------------------------------------------------------------
56 AliTOFDDLRawData::AliTOFDDLRawData()
64 //----------------------------------------------------------------------------------------
65 AliTOFDDLRawData::AliTOFDDLRawData(AliTOFGeometry *tofGeom)
70 fTOFgeometry = tofGeom;
73 //----------------------------------------------------------------------------------------
75 AliTOFDDLRawData::AliTOFDDLRawData(const AliTOFDDLRawData &source) :
78 this->fIndex=source.fIndex;
79 this->fVerbose=source.fVerbose;
80 this->fTOFgeometry=source.fTOFgeometry;
84 //---------------------------------------------------------------------------------------
86 AliTOFDDLRawData& AliTOFDDLRawData::operator=(const AliTOFDDLRawData &source){
88 this->fIndex=source.fIndex;
89 this->fVerbose=source.fVerbose;
90 this->fTOFgeometry=source.fTOFgeometry;
94 //---------------------------------------------------------------------------------------
96 void AliTOFDDLRawData::GetDigits(TClonesArray *TOFdigits,Int_t nDDL,UInt_t *buf)
99 //This method packs the TOF digits in a proper 32 bits structure
101 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
102 Int_t iSector = (Int_t)((Float_t)nDDL/AliTOFGeometry::NDDL());
117 Int_t ndigits = TOFdigits->GetEntries();
122 AliError("No found TOF digits");
126 if (fVerbose==2) ftxt.open("TOFdigits.txt",ios::app);
128 for (Int_t digit=0;digit<ndigits;digit++) {
129 digs = (AliTOFdigit*)TOFdigits->UncheckedAt(digit);
130 sector = digs->GetSector(); // Sector Number (0-17)
131 plate = digs->GetPlate(); // Plate Number (0-4)
132 strip = digs->GetStrip(); // Strip Number (0-14/18/19)
133 padx = digs->GetPadx(); // Pad Number in x direction (0-47)
134 padz = digs->GetPadz(); // Pad Number in z direction (0-1)
135 eureka = digs->GetTotPad(fTOFgeometry); // Global Pad Number inside a Sector
136 totCharge = (Int_t)digs->GetAdc();
137 timeOfFlight = (Int_t)digs->GetTdc();
139 if (sector!=iSector || (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()/AliTOFGeometry::NTRM())!=iDDL) continue;
141 if (fVerbose==2) ftxt << " Sector: " << sector << " Plate: " << plate << " Strip: " << strip << " PadZ: " << padz << " PadX: " << padx << " totPadNumber " << eureka << endl;
143 iTRM = (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()) - iDDL*AliTOFGeometry::NTRM();
146 iTDC = (Int_t)((Float_t)eureka/AliTOFGeometry::NCh()) - (iDDL*AliTOFGeometry::NTRM() + iTRM) * AliTOFGeometry::NTdc();
148 iTDC = (Int_t)(AliTOFGeometry::NTdc()*
150 (Float_t)eureka/AliTOFGeometry::NPadXTRM() -
151 (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM())
156 iCH = eureka - ((iDDL*AliTOFGeometry::NTRM() + iTRM) * AliTOFGeometry::NTdc() + iTDC) * AliTOFGeometry::NCh();
158 iCH = (Int_t)(AliTOFGeometry::NCh() *
160 (Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc() - (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc()) -
161 (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc() - (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc()))
166 if (fVerbose==2) ftxt << "DDL: "<<nDDL<<" TRM: "<<iTRM<<" TDC: "<<iTDC<<" Channel: "<<iCH<<" totCharge: "<<totCharge<<" tof: "<<timeOfFlight<<endl;
168 AliDebug(2,Form("%2i %2i %2i %2i %2i %2i %2i %2i %2i %7i %8i",nDDL,iTRM,iTDC,iCH,sector,plate,strip,padz,padx,totCharge,timeOfFlight));
173 AliBitPacking::PackWord(word,baseWord, 0, 3); // TRM ID
175 AliBitPacking::PackWord(word,baseWord, 4, 8); // TDC ID
177 AliBitPacking::PackWord(word,baseWord, 9,11); // CH ID
180 if (totCharge<0) word=TMath::Abs(totCharge);
182 AliBitPacking::PackWord(word,baseWord,12,31); // Charge (TOT) // v0.01
183 //AliBitPacking::PackWord(word,baseWord,12,19); // Charge (TOT) // v0.02
184 //AliBitPacking::PackWord(0,baseWord,20,31); // v0.02
187 buf[fIndex]=baseWord;
192 AliBitPacking::PackWord(word,baseWord,0, 7); // Error flag
194 AliBitPacking::PackWord(word,baseWord,8,31); // time-of-flight // v0.01
195 //AliBitPacking::PackWord(word,baseWord,8,19); // time-of-flight // v0.02
196 //AliBitPacking::PackWord(0,baseWord,20,30); // v0.02
197 //AliBitPacking::PackWord(1,baseWord,31,31); // v0.02
200 buf[fIndex]=baseWord;
206 if (fVerbose==2) ftxt.close();
212 //---------------------------------------------------------------------------------------
214 Int_t AliTOFDDLRawData::RawDataTOF(TBranch* branch){
216 // This method creates the Raw data files for TOF detector
219 const Int_t kSize = 5000; //max number of digits per DDL file times 2
222 //UInt_t baseWord; // v0.01
223 //UInt_t word; // v0.01
227 TClonesArray*& digits = * (TClonesArray**) branch->GetAddress();
229 ofstream outfile; // logical name of the output file
230 AliRawDataHeader header;
231 UInt_t sizeRawData = 0;
233 //loop over TOF DDL files
234 for(Int_t i = 0; i<AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors(); i++){
236 sprintf(fileName,"TOF_%d.ddl",i+AliTOFRawStream::kDDLOffset); //The name of the output file
238 outfile.open(fileName,ios::binary);
240 outfile.open(fileName);
243 //write Dummy DATA HEADER
244 UInt_t dataHeaderPosition=outfile.tellp();
245 outfile.write((char*)(&header),sizeof(header));
251 //AliBitPacking::PackWord(word,baseWord,0, 31); // Number of DDL file
252 AliBitPacking::PackWord(word,baseWord,0, 6); // Number of DDL file
253 AliBitPacking::PackWord(0,baseWord,7,31);
256 buf[fIndex]=baseWord;
261 //For each DDL file, buf contains the array of data words in Binary format
262 //fIndex gives the number of 32 bits words in the buffer for each DDL file
263 GetDigits(digits,i,buf);
264 outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
266 for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0;
269 //Write REAL DATA HEADER
270 UInt_t currentFilePosition=outfile.tellp();
271 sizeRawData = currentFilePosition - dataHeaderPosition - sizeof(header);
272 header.fSize=currentFilePosition-dataHeaderPosition;
273 header.SetAttribute(0); // valid data
274 outfile.seekp(dataHeaderPosition);
275 outfile.write((char*)(&header),sizeof(header));
276 outfile.seekp(currentFilePosition);
285 //---------------------------------------------------------------------------