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