]>
Commit | Line | Data |
---|---|---|
7e6dce66 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | /* | |
571dda3d | 17 | Revision 0.02 2005/7/25 A.De Caro |
18 | Update number of bits allocated for time-of-flight | |
19 | and 'charge' measurements | |
20 | ||
7e6dce66 | 21 | Revision 0.01 2004/6/11 A.De Caro, S.B.Sellitto, R.Silvestri |
22 | First implementation: global methods RawDataTOF | |
23 | GetDigits | |
7e6dce66 | 24 | */ |
571dda3d | 25 | |
26 | ////////////////////////////////////////////////////////////////// | |
7e6dce66 | 27 | // |
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. | |
33 | // | |
571dda3d | 34 | ////////////////////////////////////////////////////////////////// |
7e6dce66 | 35 | |
36 | #include <stdlib.h> | |
37 | #include <Riostream.h> | |
38 | #include <TClonesArray.h> | |
39 | #include <TTree.h> | |
40 | #include <TMath.h> | |
d076c8d5 | 41 | #include "AliLog.h" |
43f77f2d | 42 | |
571dda3d | 43 | #include "AliRawDataHeader.h" |
44 | #include "AliBitPacking.h" | |
45 | ||
7e6dce66 | 46 | #include "AliTOFGeometry.h" |
d3c7bfac | 47 | #include "AliTOFGeometryV4.h" |
48 | #include "AliTOFGeometryV5.h" | |
7e6dce66 | 49 | #include "AliTOFdigit.h" |
571dda3d | 50 | #include "AliTOFRawStream.h" |
7e6dce66 | 51 | #include "AliTOFDDLRawData.h" |
7e6dce66 | 52 | |
53 | ClassImp(AliTOFDDLRawData) | |
54 | ||
55 | //---------------------------------------------------------------------------------------- | |
56 | AliTOFDDLRawData::AliTOFDDLRawData() | |
57 | { | |
58 | //Default constructor | |
59 | fIndex=-1; | |
60 | fVerbose=0; | |
d3c7bfac | 61 | fTOFgeometry = 0; |
62 | } | |
63 | ||
64 | //---------------------------------------------------------------------------------------- | |
65 | AliTOFDDLRawData::AliTOFDDLRawData(AliTOFGeometry *tofGeom) | |
66 | { | |
67 | //Constructor | |
68 | fIndex=-1; | |
69 | fVerbose=0; | |
70 | fTOFgeometry = tofGeom; | |
7e6dce66 | 71 | } |
72 | ||
73 | //---------------------------------------------------------------------------------------- | |
74 | ||
75 | AliTOFDDLRawData::AliTOFDDLRawData(const AliTOFDDLRawData &source) : | |
76 | TObject(source){ | |
77 | //Copy Constructor | |
78 | this->fIndex=source.fIndex; | |
79 | this->fVerbose=source.fVerbose; | |
d3c7bfac | 80 | this->fTOFgeometry=source.fTOFgeometry; |
7e6dce66 | 81 | return; |
82 | } | |
83 | ||
84 | //--------------------------------------------------------------------------------------- | |
85 | ||
86 | AliTOFDDLRawData& AliTOFDDLRawData::operator=(const AliTOFDDLRawData &source){ | |
87 | //Assigment operator | |
88 | this->fIndex=source.fIndex; | |
89 | this->fVerbose=source.fVerbose; | |
d3c7bfac | 90 | this->fTOFgeometry=source.fTOFgeometry; |
7e6dce66 | 91 | return *this; |
92 | } | |
93 | ||
94 | //--------------------------------------------------------------------------------------- | |
95 | ||
96 | void AliTOFDDLRawData::GetDigits(TClonesArray *TOFdigits,Int_t nDDL,UInt_t *buf) | |
97 | { | |
571dda3d | 98 | |
7e6dce66 | 99 | //This method packs the TOF digits in a proper 32 bits structure |
571dda3d | 100 | |
d3c7bfac | 101 | Int_t iDDL = nDDL%AliTOFGeometry::NDDL(); |
571dda3d | 102 | Int_t iSector = (Int_t)((Float_t)nDDL/AliTOFGeometry::NDDL()); |
103 | Int_t iTRM = 0; | |
104 | Int_t iTDC = 0; | |
105 | Int_t iCH =-1; | |
7e6dce66 | 106 | Int_t sector; |
107 | Int_t plate; | |
108 | Int_t strip; | |
109 | Int_t padx; | |
110 | Int_t padz; | |
111 | Int_t totCharge; | |
112 | Int_t timeOfFlight; | |
113 | Int_t error=0; | |
114 | Int_t eureka; | |
115 | UInt_t word; | |
116 | UInt_t baseWord; | |
117 | Int_t ndigits = TOFdigits->GetEntries(); | |
118 | AliTOFdigit *digs; | |
119 | ofstream ftxt; | |
120 | if(!ndigits) | |
121 | { | |
d076c8d5 | 122 | AliError("No found TOF digits"); |
7e6dce66 | 123 | return; |
124 | } | |
125 | ||
126 | if (fVerbose==2) ftxt.open("TOFdigits.txt",ios::app); | |
571dda3d | 127 | |
7e6dce66 | 128 | for (Int_t digit=0;digit<ndigits;digit++) { |
129 | digs = (AliTOFdigit*)TOFdigits->UncheckedAt(digit); | |
571dda3d | 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) | |
d3c7bfac | 135 | eureka = digs->GetTotPad(fTOFgeometry); // Global Pad Number inside a Sector |
05a2f84a | 136 | // totCharge = (Int_t)digs->GetAdc(); //Use realistic ToT, for Standard production with no miscalibration/Slewing it == fAdC in digit (see AliTOFDigitizer) |
137 | totCharge = (Int_t)digs->GetToT(); | |
7e6dce66 | 138 | timeOfFlight = (Int_t)digs->GetTdc(); |
571dda3d | 139 | |
43f77f2d | 140 | if (sector!=iSector || (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()/AliTOFGeometry::NTRM())!=iDDL) continue; |
7e6dce66 | 141 | |
571dda3d | 142 | if (fVerbose==2) ftxt << " Sector: " << sector << " Plate: " << plate << " Strip: " << strip << " PadZ: " << padz << " PadX: " << padx << " totPadNumber " << eureka << endl; |
7e6dce66 | 143 | |
571dda3d | 144 | iTRM = (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()) - iDDL*AliTOFGeometry::NTRM(); |
145 | ||
7e6dce66 | 146 | |
571dda3d | 147 | iTDC = (Int_t)((Float_t)eureka/AliTOFGeometry::NCh()) - (iDDL*AliTOFGeometry::NTRM() + iTRM) * AliTOFGeometry::NTdc(); |
148 | /* | |
43f77f2d | 149 | iTDC = (Int_t)(AliTOFGeometry::NTdc()* |
7e6dce66 | 150 | ( |
43f77f2d | 151 | (Float_t)eureka/AliTOFGeometry::NPadXTRM() - |
152 | (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()) | |
7e6dce66 | 153 | ) |
154 | ); | |
571dda3d | 155 | */ |
156 | ||
157 | iCH = eureka - ((iDDL*AliTOFGeometry::NTRM() + iTRM) * AliTOFGeometry::NTdc() + iTDC) * AliTOFGeometry::NCh(); | |
158 | /* | |
43f77f2d | 159 | iCH = (Int_t)(AliTOFGeometry::NCh() * |
7e6dce66 | 160 | ( |
43f77f2d | 161 | (Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc() - (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc()) - |
162 | (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc() - (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc())) | |
7e6dce66 | 163 | ) |
164 | ); | |
571dda3d | 165 | */ |
166 | ||
167 | if (fVerbose==2) ftxt << "DDL: "<<nDDL<<" TRM: "<<iTRM<<" TDC: "<<iTDC<<" Channel: "<<iCH<<" totCharge: "<<totCharge<<" tof: "<<timeOfFlight<<endl; | |
168 | ||
571dda3d | 169 | 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)); |
7e6dce66 | 170 | |
171 | baseWord=0; | |
172 | ||
173 | word=iTRM; | |
344f25d2 | 174 | AliBitPacking::PackWord(word,baseWord, 0, 3); // TRM ID |
7e6dce66 | 175 | word=iTDC; |
344f25d2 | 176 | AliBitPacking::PackWord(word,baseWord, 4, 8); // TDC ID |
7e6dce66 | 177 | word=iCH; |
344f25d2 | 178 | AliBitPacking::PackWord(word,baseWord, 9,11); // CH ID |
7e6dce66 | 179 | |
180 | // temporary control | |
181 | if (totCharge<0) word=TMath::Abs(totCharge); | |
182 | else word=totCharge; | |
571dda3d | 183 | AliBitPacking::PackWord(word,baseWord,12,31); // Charge (TOT) // v0.01 |
184 | //AliBitPacking::PackWord(word,baseWord,12,19); // Charge (TOT) // v0.02 | |
185 | //AliBitPacking::PackWord(0,baseWord,20,31); // v0.02 | |
186 | ||
7e6dce66 | 187 | fIndex++; |
188 | buf[fIndex]=baseWord; | |
189 | ||
190 | baseWord=0; | |
191 | ||
192 | word=error; | |
344f25d2 | 193 | AliBitPacking::PackWord(word,baseWord,0, 7); // Error flag |
7e6dce66 | 194 | word=timeOfFlight; |
571dda3d | 195 | AliBitPacking::PackWord(word,baseWord,8,31); // time-of-flight // v0.01 |
196 | //AliBitPacking::PackWord(word,baseWord,8,19); // time-of-flight // v0.02 | |
197 | //AliBitPacking::PackWord(0,baseWord,20,30); // v0.02 | |
198 | //AliBitPacking::PackWord(1,baseWord,31,31); // v0.02 | |
7e6dce66 | 199 | |
200 | fIndex++; | |
201 | buf[fIndex]=baseWord; | |
202 | word=0; | |
203 | baseWord=0; | |
204 | ||
205 | }//end for | |
206 | ||
207 | if (fVerbose==2) ftxt.close(); | |
208 | ||
209 | return; | |
210 | ||
211 | }//end GetDigits | |
212 | ||
7e6dce66 | 213 | //--------------------------------------------------------------------------------------- |
214 | ||
215 | Int_t AliTOFDDLRawData::RawDataTOF(TBranch* branch){ | |
571dda3d | 216 | // |
217 | // This method creates the Raw data files for TOF detector | |
218 | // | |
219 | ||
220 | const Int_t kSize = 5000; //max number of digits per DDL file times 2 | |
221 | ||
7e6dce66 | 222 | UInt_t buf[kSize]; |
571dda3d | 223 | //UInt_t baseWord; // v0.01 |
224 | //UInt_t word; // v0.01 | |
7e6dce66 | 225 | |
226 | fIndex=-1; | |
227 | ||
228 | TClonesArray*& digits = * (TClonesArray**) branch->GetAddress(); | |
229 | char fileName[15]; | |
230 | ofstream outfile; // logical name of the output file | |
231 | AliRawDataHeader header; | |
571dda3d | 232 | UInt_t sizeRawData = 0; |
7e6dce66 | 233 | |
234 | //loop over TOF DDL files | |
571dda3d | 235 | for(Int_t i = 0; i<AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors(); i++){ |
236 | ||
237 | sprintf(fileName,"TOF_%d.ddl",i+AliTOFRawStream::kDDLOffset); //The name of the output file | |
7e6dce66 | 238 | #ifndef __DECCXX |
239 | outfile.open(fileName,ios::binary); | |
240 | #else | |
241 | outfile.open(fileName); | |
242 | #endif | |
571dda3d | 243 | |
7e6dce66 | 244 | //write Dummy DATA HEADER |
245 | UInt_t dataHeaderPosition=outfile.tellp(); | |
246 | outfile.write((char*)(&header),sizeof(header)); | |
247 | ||
571dda3d | 248 | /* |
249 | // v0.01 | |
7e6dce66 | 250 | baseWord=0; |
251 | word=i; | |
571dda3d | 252 | //AliBitPacking::PackWord(word,baseWord,0, 31); // Number of DDL file |
253 | AliBitPacking::PackWord(word,baseWord,0, 6); // Number of DDL file | |
254 | AliBitPacking::PackWord(0,baseWord,7,31); | |
7e6dce66 | 255 | |
256 | fIndex++; | |
257 | buf[fIndex]=baseWord; | |
571dda3d | 258 | */ |
7e6dce66 | 259 | |
260 | branch->GetEvent(); | |
261 | ||
262 | //For each DDL file, buf contains the array of data words in Binary format | |
263 | //fIndex gives the number of 32 bits words in the buffer for each DDL file | |
264 | GetDigits(digits,i,buf); | |
265 | outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t))); | |
266 | ||
267 | for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0; | |
268 | fIndex=-1; | |
269 | ||
270 | //Write REAL DATA HEADER | |
271 | UInt_t currentFilePosition=outfile.tellp(); | |
571dda3d | 272 | sizeRawData = currentFilePosition - dataHeaderPosition - sizeof(header); |
7e6dce66 | 273 | header.fSize=currentFilePosition-dataHeaderPosition; |
274 | header.SetAttribute(0); // valid data | |
571dda3d | 275 | outfile.seekp(dataHeaderPosition); |
7e6dce66 | 276 | outfile.write((char*)(&header),sizeof(header)); |
571dda3d | 277 | outfile.seekp(currentFilePosition); |
278 | ||
7e6dce66 | 279 | outfile.close(); |
280 | ||
281 | }//end for | |
282 | ||
283 | return 0; | |
284 | } | |
285 | ||
571dda3d | 286 | //--------------------------------------------------------------------------- |