]>
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 | /* | |
17 | Revision 0.01 2004/6/11 A.De Caro, S.B.Sellitto, R.Silvestri | |
18 | First implementation: global methods RawDataTOF | |
19 | GetDigits | |
7e6dce66 | 20 | */ |
21 | // | |
22 | // This class contains the methods to create the Raw Data files | |
23 | // for the TOF detector starting from the Digits. | |
24 | // In this preliminary implementation, we defined the structure | |
25 | // of the ALICE-TOF raw data starting from the current format | |
26 | // for the TOF digits and the TOF raw data. | |
27 | // | |
28 | ||
29 | #include <stdlib.h> | |
30 | #include <Riostream.h> | |
31 | #include <TClonesArray.h> | |
32 | #include <TTree.h> | |
33 | #include <TMath.h> | |
34 | #include "AliTOF.h" | |
35 | #include "AliTOFGeometry.h" | |
36 | #include "AliTOFdigit.h" | |
37 | #include "AliTOFDDLRawData.h" | |
38 | #include "AliRawDataHeader.h" | |
344f25d2 | 39 | #include "AliBitPacking.h" |
7e6dce66 | 40 | |
41 | ClassImp(AliTOFDDLRawData) | |
42 | ||
43 | //---------------------------------------------------------------------------------------- | |
44 | AliTOFDDLRawData::AliTOFDDLRawData() | |
45 | { | |
46 | //Default constructor | |
47 | fIndex=-1; | |
48 | fVerbose=0; | |
49 | } | |
50 | ||
51 | //---------------------------------------------------------------------------------------- | |
52 | ||
53 | AliTOFDDLRawData::AliTOFDDLRawData(const AliTOFDDLRawData &source) : | |
54 | TObject(source){ | |
55 | //Copy Constructor | |
56 | this->fIndex=source.fIndex; | |
57 | this->fVerbose=source.fVerbose; | |
58 | return; | |
59 | } | |
60 | ||
61 | //--------------------------------------------------------------------------------------- | |
62 | ||
63 | AliTOFDDLRawData& AliTOFDDLRawData::operator=(const AliTOFDDLRawData &source){ | |
64 | //Assigment operator | |
65 | this->fIndex=source.fIndex; | |
66 | this->fVerbose=source.fVerbose; | |
67 | return *this; | |
68 | } | |
69 | ||
70 | //--------------------------------------------------------------------------------------- | |
71 | ||
72 | void AliTOFDDLRawData::GetDigits(TClonesArray *TOFdigits,Int_t nDDL,UInt_t *buf) | |
73 | { | |
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.); | |
77 | Int_t iTRM=0; | |
78 | Int_t iTDC=0; | |
79 | Int_t iCH=-1; | |
80 | Int_t sector; | |
81 | Int_t plate; | |
82 | Int_t strip; | |
83 | Int_t padx; | |
84 | Int_t padz; | |
85 | Int_t totCharge; | |
86 | Int_t timeOfFlight; | |
87 | Int_t error=0; | |
88 | Int_t eureka; | |
89 | UInt_t word; | |
90 | UInt_t baseWord; | |
91 | Int_t ndigits = TOFdigits->GetEntries(); | |
92 | AliTOFdigit *digs; | |
93 | ofstream ftxt; | |
94 | if(!ndigits) | |
95 | { | |
96 | Error("GetDigits", "No found TOF digits\n"); | |
97 | return; | |
98 | } | |
99 | ||
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(); | |
111 | /* | |
112 | Int_t istriPlate=0; | |
113 | switch (plate) | |
114 | { | |
115 | case 0: | |
116 | break; | |
117 | case 1: | |
118 | istriPlate = AliTOFGeometry::NStripC(); | |
119 | break; | |
120 | case 2: | |
121 | istriPlate = AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB(); | |
122 | break; | |
123 | case 3: | |
124 | istriPlate = AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA(); | |
125 | break; | |
126 | case 4: | |
127 | istriPlate = AliTOFGeometry::NStripC()+2*AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA(); | |
128 | break; | |
129 | } | |
130 | ||
131 | eureka=2*padx+padz+AliTOFGeometry::NpadXStrip()*(strip+istriPlate); | |
132 | ||
133 | if (eureka!=digs->GetTotPad()) printf(" eureka = %d AND digs->GetTotPad() = %d",eureka,digs->GetTotPad()); | |
134 | */ | |
135 | if (sector!=iSector || (Int_t)((Float_t)eureka/AliTOF::NPadXTRM()/AliTOF::NTRM())!=iDDL) continue; | |
136 | ||
137 | if (fVerbose==2) ftxt <<" Sector: "<<sector<<" plate: "<<plate<<" strip "<<strip<<" padx "<<padx<<" padz "<<padz<<" eureka "<<eureka<<endl; | |
138 | ||
139 | iTRM = (Int_t)((Float_t)eureka/AliTOF::NPadXTRM() - AliTOF::NTRM()*iDDL); | |
140 | ||
141 | iTDC = (Int_t)(AliTOF::NTdc()* | |
142 | ( | |
143 | (Float_t)eureka/AliTOF::NPadXTRM() - | |
144 | (Int_t)((Float_t)eureka/AliTOF::NPadXTRM()) | |
145 | ) | |
146 | ); | |
147 | ||
148 | iCH = (Int_t)(AliTOF::NCh() * | |
149 | ( | |
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())) | |
152 | ) | |
153 | ); | |
154 | ||
155 | if (fVerbose==2) ftxt << "DDL: "<<iDDL<<" Sector: "<<sector<<" TRM: "<<iTRM<<" TDC: "<<iTDC<<" Channel: "<<iCH<<" totCharge: "<<totCharge<<" tof: "<<timeOfFlight<<endl; | |
156 | ||
157 | baseWord=0; | |
158 | ||
159 | word=iTRM; | |
344f25d2 | 160 | AliBitPacking::PackWord(word,baseWord, 0, 3); // TRM ID |
7e6dce66 | 161 | word=iTDC; |
344f25d2 | 162 | AliBitPacking::PackWord(word,baseWord, 4, 8); // TDC ID |
7e6dce66 | 163 | word=iCH; |
344f25d2 | 164 | AliBitPacking::PackWord(word,baseWord, 9,11); // CH ID |
7e6dce66 | 165 | |
166 | // temporary control | |
167 | if (totCharge<0) word=TMath::Abs(totCharge); | |
168 | else word=totCharge; | |
344f25d2 | 169 | AliBitPacking::PackWord(word,baseWord,12,31); // Charge (TOT) |
7e6dce66 | 170 | |
171 | fIndex++; | |
172 | buf[fIndex]=baseWord; | |
173 | ||
174 | baseWord=0; | |
175 | ||
176 | word=error; | |
344f25d2 | 177 | AliBitPacking::PackWord(word,baseWord,0, 7); // Error flag |
7e6dce66 | 178 | word=timeOfFlight; |
344f25d2 | 179 | AliBitPacking::PackWord(word,baseWord,8,31); // time-of-flight |
7e6dce66 | 180 | |
181 | fIndex++; | |
182 | buf[fIndex]=baseWord; | |
183 | word=0; | |
184 | baseWord=0; | |
185 | ||
186 | }//end for | |
187 | ||
188 | if (fVerbose==2) ftxt.close(); | |
189 | ||
190 | return; | |
191 | ||
192 | }//end GetDigits | |
193 | ||
7e6dce66 | 194 | //--------------------------------------------------------------------------------------- |
195 | ||
196 | Int_t AliTOFDDLRawData::RawDataTOF(TBranch* branch){ | |
197 | //This method creates the Raw data files for TOF detector | |
198 | const Int_t kSize=5000; //2*AliTOFGeometry::NpadXSector() | |
199 | //max number of digits per DDL file times 2 | |
200 | UInt_t buf[kSize]; | |
201 | UInt_t baseWord; | |
202 | UInt_t word; | |
203 | ||
204 | fIndex=-1; | |
205 | ||
206 | TClonesArray*& digits = * (TClonesArray**) branch->GetAddress(); | |
207 | char fileName[15]; | |
208 | ofstream outfile; // logical name of the output file | |
209 | AliRawDataHeader header; | |
210 | ||
211 | //loop over TOF DDL files | |
212 | for(Int_t i=0;i<72;i++){ | |
3125b792 | 213 | sprintf(fileName,"TOF_%d.ddl",i+kDDLOffset); //The name of the output file |
7e6dce66 | 214 | #ifndef __DECCXX |
215 | outfile.open(fileName,ios::binary); | |
216 | #else | |
217 | outfile.open(fileName); | |
218 | #endif | |
219 | //write Dummy DATA HEADER | |
220 | UInt_t dataHeaderPosition=outfile.tellp(); | |
221 | outfile.write((char*)(&header),sizeof(header)); | |
222 | ||
223 | baseWord=0; | |
224 | word=i; | |
344f25d2 | 225 | AliBitPacking::PackWord(word,baseWord,0, 31); // Number of DDL file |
7e6dce66 | 226 | |
227 | fIndex++; | |
228 | buf[fIndex]=baseWord; | |
229 | ||
230 | branch->GetEvent(); | |
231 | ||
232 | //For each DDL file, buf contains the array of data words in Binary format | |
233 | //fIndex gives the number of 32 bits words in the buffer for each DDL file | |
234 | GetDigits(digits,i,buf); | |
235 | outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t))); | |
236 | ||
237 | for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0; | |
238 | fIndex=-1; | |
239 | ||
240 | //Write REAL DATA HEADER | |
241 | UInt_t currentFilePosition=outfile.tellp(); | |
242 | outfile.seekp(dataHeaderPosition); | |
243 | header.fSize=currentFilePosition-dataHeaderPosition; | |
244 | header.SetAttribute(0); // valid data | |
245 | outfile.write((char*)(&header),sizeof(header)); | |
246 | outfile.close(); | |
247 | ||
248 | }//end for | |
249 | ||
250 | return 0; | |
251 | } | |
252 | ||
253 | //----------------------------------------------------------------------------------------- | |
254 | /* | |
255 | void AliTOFDDLRawData::WriteChipHeader(Int_t ChipAddr,Int_t EventCnt,UInt_t &BaseWord) | |
256 | { | |
257 | //This method writes a chip header | |
258 | BaseWord=0; | |
259 | PackWord(BaseWord,ChipAddr,0,3); | |
260 | PackWord(BaseWord,EventCnt,4,10); | |
261 | PackWord(BaseWord,0x7,11,13); | |
262 | PackWord(BaseWord,0x1,14,15); | |
263 | return; | |
264 | }//end WriteChipHeader | |
265 | */ | |
266 | //---------------------------------------------------------------------------------------- | |
267 | /* | |
268 | void AliTOFDDLRawData::ReadChipHeader(Int_t &ChipAddr,Int_t &EventCnt,UInt_t BaseWord) | |
269 | { | |
270 | //This method reads a chip header | |
271 | UInt_t temp=0; | |
272 | UnpackWord(BaseWord,0,3,temp); | |
273 | ChipAddr=(Int_t)temp; | |
274 | UnpackWord(BaseWord,4,10,temp); | |
275 | EventCnt=(Int_t)temp; | |
276 | if(fVerbose) | |
277 | Info("ReadChipHeader", "Chip:&d Half Stave module:%d",ChipAddr,EventCnt); | |
278 | return; | |
279 | }//end ReadChipHeader | |
280 | */ | |
281 | //---------------------------------------------------------------------------------------- | |
282 | /* | |
283 | void AliTOFDDLRawData::WriteChipTrailer(UInt_t *buf,Int_t ChipHitCount,UInt_t &BaseWord) | |
284 | { | |
285 | //This method writes a chip trailer | |
286 | //pixel fill word | |
287 | if((ChipHitCount%2)!=0){ | |
288 | PackWord(BaseWord,0xFEDC,0,15); | |
289 | } | |
290 | PackWord(BaseWord,ChipHitCount,16,28); | |
291 | PackWord(BaseWord,0x0,30,31); | |
292 | fIndex++; | |
293 | buf[fIndex]=BaseWord; | |
294 | BaseWord=0; | |
295 | return; | |
296 | }//end WriteChipTrailer | |
297 | */ | |
298 | //------------------------------------------------------------------------------------------ | |
299 | /* | |
300 | void AliTOFDDLRawData::ReadChipTrailer(Int_t &ChipHitCount,UInt_t BaseWord) | |
301 | { | |
302 | //This method reads a chip trailer | |
303 | UInt_t temp=0; | |
304 | UnpackWord(BaseWord,16,28,temp); | |
305 | ChipHitCount=(Int_t)temp; | |
306 | return; | |
307 | }//end ReadChipTrailer | |
308 | */ | |
309 | //------------------------------------------------------------------------------------------ |