]>
Commit | Line | Data |
---|---|---|
2e9f335b | 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 | **************************************************************************/ | |
9f992f70 | 15 | |
30c1018e | 16 | /* $Id$ */ |
a79660fb | 17 | |
9f992f70 | 18 | |
a79660fb | 19 | //This class contains all the necessary methods to create the Raw Data |
20 | //files (slides) for the ITS data challenges for: | |
21 | //SPD | |
22 | //SDD | |
23 | //SSD | |
2e9f335b | 24 | |
25 | #include <stdlib.h> | |
5dfa68c5 | 26 | //#include <Riostream.h> |
2e9f335b | 27 | #include <TClonesArray.h> |
28 | #include <TTree.h> | |
7d62fb64 | 29 | #include "AliITSdigit.h" |
2e9f335b | 30 | #include "AliITSDDLRawData.h" |
f7ee745b | 31 | #include "AliRawDataHeaderSim.h" |
0421c3d1 | 32 | #include "AliITSRawStreamSPD.h" |
33 | #include "AliITSRawStreamSDD.h" | |
979b5a5f | 34 | #include "AliITSDDLModuleMapSDD.h" |
0421c3d1 | 35 | #include "AliITSRawStreamSSD.h" |
3f917533 | 36 | #include "AliITSIntMap.h" |
113c12f1 | 37 | #include "AliBitPacking.h" |
362c9d61 | 38 | #include "AliDAQ.h" |
08f92f14 | 39 | #include "AliFstream.h" |
ad7f2bfa | 40 | #include "AliITSFOSignalsSPD.h" |
2e9f335b | 41 | |
42 | ClassImp(AliITSDDLRawData) | |
43 | ||
44 | //////////////////////////////////////////////////////////////////////////////////////// | |
e56160b8 | 45 | AliITSDDLRawData::AliITSDDLRawData(): |
46 | fVerbose(0), | |
47 | fIndex(-1), | |
ad1b4ad1 | 48 | fHalfStaveModule(-1), |
d9ed1779 | 49 | fSDDRawFormat(7){ |
a79660fb | 50 | //Default constructor |
e56160b8 | 51 | |
2e9f335b | 52 | } |
53 | ||
54 | //////////////////////////////////////////////////////////////////////////////////////// | |
55 | ||
ac74f489 | 56 | AliITSDDLRawData::AliITSDDLRawData(const AliITSDDLRawData &source) : |
e56160b8 | 57 | TObject(source), |
58 | fVerbose(source.fVerbose), | |
59 | fIndex(source.fIndex), | |
ad1b4ad1 | 60 | fHalfStaveModule(source.fHalfStaveModule), |
d9ed1779 | 61 | fSDDRawFormat(source.fSDDRawFormat){ |
a79660fb | 62 | //Copy Constructor |
2e9f335b | 63 | } |
64 | ||
65 | //////////////////////////////////////////////////////////////////////////////////////// | |
66 | ||
67 | AliITSDDLRawData& AliITSDDLRawData::operator=(const AliITSDDLRawData &source){ | |
68 | //Assigment operator | |
9d1af0a7 | 69 | if(this==&source) return *this; |
fa358bbd | 70 | fIndex=source.fIndex; |
71 | fHalfStaveModule=source.fHalfStaveModule; | |
72 | fVerbose=source.fVerbose; | |
73 | fSDDRawFormat=source.fSDDRawFormat; | |
2e9f335b | 74 | return *this; |
75 | } | |
76 | ||
77 | //////////////////////////////////////////////////////////////////////////////////////// | |
78 | //STRIP | |
79 | // | |
80 | ||
0b3c7dfc | 81 | void AliITSDDLRawData::GetDigitsSSD(TClonesArray *ITSdigits,Int_t mod,Int_t modR,Int_t ddl,UInt_t *buf){ |
a79660fb | 82 | //This method packs the SSD digits in a proper 32 bits structure |
532a132e | 83 | // Revised by Enrico Fragiacomo |
2e9f335b | 84 | Int_t ix; |
85 | Int_t iz; | |
86 | Int_t is; | |
0b3c7dfc | 87 | UInt_t word; |
88 | UInt_t baseWord; | |
2e9f335b | 89 | Int_t ndigits = ITSdigits->GetEntries(); |
90 | AliITSdigit *digs; | |
9f992f70 | 91 | ofstream ftxt; |
2e9f335b | 92 | if(ndigits){ |
9f992f70 | 93 | if (fVerbose==2){ |
94 | ftxt.open("SSDdigits.txt",ios::app); | |
95 | } | |
2e9f335b | 96 | for (Int_t digit=0;digit<ndigits;digit++) { |
97 | digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit); | |
532a132e | 98 | iz=digs->GetCoord1(); // If iz==0, O side and if iz=1 N side |
99 | ix=digs->GetCoord2(); // Strip Number | |
7f1a504b | 100 | is=digs->GetCompressedSignal(); // ADC Signal |
2e9f335b | 101 | // cout<<" Module:"<<mod-500<<" N/P side:"<<iz<<" Strip Number:"<<ix<<" Amplidute:"<<is-1<<endl; |
f957a032 | 102 | if(is<0) is = 0; |
103 | if(is>4095) is = 4095; | |
9f992f70 | 104 | if (fVerbose==2) |
105 | ftxt<<"DDL:"<<ddl<<" Mod: "<<modR<<" N/P: "<<iz<<" Strip: "<<ix<<" Value: "<<is-1<<endl; | |
532a132e | 106 | |
a79660fb | 107 | baseWord=0; |
532a132e | 108 | |
109 | word=is; | |
110 | AliBitPacking::PackWord(word,baseWord,0,11);//ADC data | |
111 | ||
112 | word = (iz==0) ? ix : 1535-ix ; // on N-side 1535-768 -> 0-767 | |
113 | AliBitPacking::PackWord(word,baseWord,12,22);//Strip Number | |
114 | ||
115 | word = mod%12; // ADC-number (12 ADCs per AD module) | |
116 | word += ( word<6 ) ? 0 : 2; // ADC range 0-5 and 8-13 | |
117 | AliBitPacking::PackWord(word,baseWord,24,27);//ADC Channel | |
118 | ||
119 | word = mod/12+1; // AD-number (AD module index ranges 1-9) | |
120 | AliBitPacking::PackWord(word,baseWord,28,31);//AD slot | |
2e9f335b | 121 | fIndex++; |
a79660fb | 122 | buf[fIndex]=baseWord; |
2e9f335b | 123 | }//end for |
124 | }//end if | |
9f992f70 | 125 | if (fVerbose==2) |
126 | ftxt.close(); | |
2e9f335b | 127 | return; |
128 | }//end GetDigitsSSD | |
129 | ||
130 | //////////////////////////////////////////////////////////////////////////////////////// | |
131 | //Silicon Drift Detector | |
132 | // | |
133 | ||
ad1b4ad1 | 134 | void AliITSDDLRawData::GetDigitsSDDCompressed(TClonesArray *ITSdigits, Int_t mod, UInt_t *buf){ |
135 | //This method packs the SDD digits in the compressed format (32 bit per digit) | |
136 | // see AliITSRawStreamSDDCompressed for details on the dta format | |
137 | ||
138 | UInt_t dataWord=0; | |
139 | Int_t ndigits = ITSdigits->GetEntries(); | |
140 | AliITSdigit *digs; | |
141 | if(ndigits){ | |
142 | for (Int_t digit=0;digit<ndigits;digit++) { | |
143 | digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit); | |
144 | Int_t iz=digs->GetCoord1(); // Anode | |
145 | Int_t ix=digs->GetCoord2(); // Time | |
6297cc01 | 146 | Int_t is=digs->GetCompressedSignal(); // ADC Signal - 8 bit |
ad1b4ad1 | 147 | dataWord=mod<<27; |
148 | Int_t sid=0; | |
149 | if(iz>=256){ | |
150 | sid=1; | |
151 | iz-=256; | |
152 | } | |
153 | dataWord+=sid<<26; | |
154 | dataWord+=iz<<18; | |
155 | dataWord+=ix<<10; | |
d9ed1779 | 156 | UInt_t adcEncoded=0; |
157 | Int_t shift=0; | |
158 | if(is < 8) shift=2; | |
159 | else if(is<16) shift=3; | |
160 | else if(is<32) shift=4; | |
161 | else if(is<64) shift=5; | |
162 | else if(is<128) shift=6; | |
163 | else shift=7; | |
164 | adcEncoded=shift+((is-(1<<shift))<<3); | |
165 | dataWord+=adcEncoded; | |
ad1b4ad1 | 166 | fIndex++; |
167 | buf[fIndex]=dataWord; | |
168 | } | |
169 | } | |
3ee08066 | 170 | UInt_t finalWord=UInt_t(15)<<28; |
ad1b4ad1 | 171 | finalWord+=mod; |
172 | fIndex++; | |
173 | buf[fIndex]=finalWord; | |
174 | } | |
175 | ||
176 | //______________________________________________________________________ | |
177 | ||
0b3c7dfc | 178 | void AliITSDDLRawData::GetDigitsSDD(TClonesArray *ITSdigits,Int_t mod,Int_t modR,Int_t ddl,UInt_t *buf){ |
a97b3678 | 179 | //This method packs the SDD digits in a proper 32 bits structure |
2e9f335b | 180 | Int_t ix; |
181 | Int_t iz; | |
182 | Int_t is; | |
a97b3678 | 183 | UInt_t word=0; |
184 | UInt_t baseWord=0; | |
2e9f335b | 185 | Int_t ndigits = ITSdigits->GetEntries(); |
186 | AliITSdigit *digs; | |
9f992f70 | 187 | ofstream ftxt; |
a97b3678 | 188 | Int_t digarr[512][256]; |
189 | for(Int_t i=0;i<512;i++){ | |
190 | for(Int_t j=0;j<256;j++){ | |
191 | digarr[i][j]=0; | |
192 | } | |
193 | } | |
194 | //word to select the 12 carlos for the 12 modules | |
14dceddf | 195 | UInt_t carlosid=0x30000000+mod; |
a97b3678 | 196 | |
197 | fIndex++; | |
198 | buf[fIndex]=carlosid; | |
199 | Int_t first=0; | |
200 | Int_t last=0; | |
201 | Int_t diff=0; | |
202 | Int_t nbit=0; | |
203 | UInt_t word2=0; | |
204 | Bool_t flag = kFALSE; | |
205 | baseWord=0; | |
206 | Int_t bitinfo1[4] = {3,8,3,7}; //vector with info on bit for timebin info | |
207 | Int_t wordinfo1[4]= {0,0,0,0}; //vector with word info for timebin info | |
208 | Int_t bitinfo2[2] = {3,18}; //vector with info on bit for EOR (end of row) info | |
209 | Int_t wordinfo2[3]= {1,65593}; //vector with word info for anode info | |
210 | ||
211 | /* for time bin info: word n bits meaning | |
212 | 0 3 next info is timebin | |
213 | 8 3 next word is 8 bit long | |
214 | tb value 8 timebin value | |
215 | n (2->7) 3 next info is n bit long | |
216 | signal n signal value | |
217 | ||
218 | for anode info: 1 3 next 18 bits are for EOR | |
219 | increments the anode value | |
220 | ||
221 | EOR 18 error codes + other info | |
222 | */ | |
223 | ||
2e9f335b | 224 | if(ndigits){ |
9f992f70 | 225 | if (fVerbose==2) |
226 | ftxt.open("SDDdigits.txt",ios::app); | |
2e9f335b | 227 | for (Int_t digit=0;digit<ndigits;digit++) { |
228 | digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit); | |
ecee53fc | 229 | iz=digs->GetCoord1(); // Anode |
230 | ix=digs->GetCoord2(); // Time | |
7f1a504b | 231 | is=digs->GetCompressedSignal(); // ADC Signal |
a97b3678 | 232 | digarr[iz][ix]=is; |
14dceddf | 233 | if (fVerbose==2) |
9f992f70 | 234 | ftxt<<"DDL:"<<ddl<<" MID:"<<modR<<" An:"<<iz<<" T:"<<ix<<" A:"<<is<<endl; |
0421c3d1 | 235 | if (is>255){Error("GetDigitsSDD", "bits words is needed)!!!");} |
a97b3678 | 236 | } |
2e9f335b | 237 | |
a97b3678 | 238 | for(Int_t anode=0;anode<512;anode++){ |
14dceddf | 239 | if(flag){ |
a97b3678 | 240 | last = first+diff-1; |
241 | AliBitPacking::PackWord(word2,baseWord,first,last); | |
242 | flag = kFALSE; | |
243 | first = last+1; | |
244 | diff=0; | |
245 | } | |
a97b3678 | 246 | if(anode == 256){ |
247 | last = 0; | |
248 | first = 0; | |
249 | flag = kFALSE; | |
250 | diff = 0; | |
251 | word2=0; | |
a97b3678 | 252 | } |
253 | ||
254 | for(Int_t tb=0;tb<256;tb++){ | |
255 | if(digarr[anode][tb]!=0){ | |
256 | if(flag){ | |
257 | last = first+diff-1; | |
258 | AliBitPacking::PackWord(word2,baseWord,first,last); | |
259 | flag = kFALSE; | |
260 | first = last+1; | |
261 | diff=0; | |
262 | } | |
263 | wordinfo1[1] = tb; | |
264 | //non lossy compression as it is done in Carlos | |
265 | //(data are already 10to8bit compressed by AMBRA | |
266 | ||
267 | /* if value < 8 value = value - (1 << 2) (word is 2 bit long) | |
268 | if value < 16 value = value - (1 << 3) (word is 3 bit long) | |
269 | if value < 32 value = value - (1 << 4) (word is 4 bit long) | |
270 | if value < 64 value = value - (1 << 5) (word is 5 bit long) | |
271 | if value <128 value = value - (1 << 6) (word is 6 bit long) | |
272 | if value >=128value = value - (1 << 7) (word is 7 bit long) | |
273 | ||
274 | */ | |
ad7f2bfa | 275 | //if(digarr[anode][tb]<4) continue; // not write <4 cnts above tL |
a97b3678 | 276 | if(digarr[anode][tb]<8){ |
277 | bitinfo1[3] = 2; | |
278 | wordinfo1[2] = 2; | |
279 | wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]); | |
280 | } | |
281 | if(digarr[anode][tb]>=8 && digarr[anode][tb]<16){ | |
282 | bitinfo1[3] = 3; | |
283 | wordinfo1[2] = 3; | |
284 | wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]); | |
285 | } | |
286 | if(digarr[anode][tb]>=16 && digarr[anode][tb]<32){ | |
287 | bitinfo1[3] = 4; | |
288 | wordinfo1[2] = 4; | |
289 | wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]); | |
290 | } | |
291 | if(digarr[anode][tb]>=32 && digarr[anode][tb]<64){ | |
292 | bitinfo1[3] = 5; | |
293 | wordinfo1[2] = 5; | |
294 | wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]); | |
295 | } | |
296 | if(digarr[anode][tb]>=64 && digarr[anode][tb]<128){ | |
297 | bitinfo1[3] = 6; | |
298 | wordinfo1[2] = 6; | |
299 | wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]); | |
300 | } | |
301 | if(digarr[anode][tb]>=128){ | |
302 | bitinfo1[3] = 7; | |
303 | wordinfo1[2] = 7; | |
304 | wordinfo1[3] = digarr[anode][tb]-(1 << bitinfo1[3]); | |
305 | } | |
306 | ||
307 | for(Int_t ie=0;ie<4;ie++){ | |
308 | ||
309 | if(flag){ | |
310 | last = first+diff-1; | |
311 | AliBitPacking::PackWord(word2,baseWord,first,last); | |
312 | flag = kFALSE; | |
313 | first = last+1; | |
314 | diff=0; | |
315 | } | |
316 | last = first+bitinfo1[ie]-1; | |
317 | if(first < 30 && last < 30){ | |
318 | AliBitPacking::PackWord(wordinfo1[ie],baseWord,first,last); | |
319 | first = last+1; | |
320 | } | |
321 | else{ | |
322 | if(first<=29){ | |
323 | UInt_t w = AliBitPacking::UnpackWord(wordinfo1[ie],0,29-first); | |
324 | AliBitPacking::PackWord(w,baseWord,first,29); | |
325 | Int_t lb = 29-first+1; | |
326 | diff = bitinfo1[ie]-lb; | |
327 | word2 = AliBitPacking::UnpackWord(wordinfo1[ie],lb,lb+diff-1); | |
328 | flag = kTRUE; | |
329 | if(anode<256) word = 2;//channel 0 of carlos | |
330 | else word = 3; //channel 1 of carlos | |
331 | AliBitPacking::PackWord(word,baseWord,30,31); | |
332 | fIndex++; | |
333 | buf[fIndex]=baseWord; | |
334 | first=0; | |
335 | last = 0; | |
336 | baseWord=0; | |
337 | word = 0; | |
338 | } | |
339 | else{ | |
340 | word2 = wordinfo1[ie]; | |
341 | diff = bitinfo1[ie]; | |
342 | flag = kTRUE; | |
343 | if(anode<256) word = 2; //channel 0 of carlos | |
344 | else word = 3; //channel 1 of carlos | |
345 | AliBitPacking::PackWord(word,baseWord,30,31); | |
346 | fIndex++; | |
347 | buf[fIndex]=baseWord; | |
348 | first=0; | |
349 | last=0; | |
350 | baseWord=0; | |
351 | word = 0; | |
352 | } | |
353 | } | |
354 | } | |
355 | ||
356 | }//END IF | |
357 | ||
358 | }//end loop on tb | |
359 | ||
360 | for(Int_t i=0;i<2;i++){ | |
361 | if(flag){ | |
362 | last = first+diff-1; | |
363 | AliBitPacking::PackWord(word2,baseWord,first,last); | |
364 | flag = kFALSE; | |
365 | first = last+1; | |
366 | diff=0; | |
367 | } | |
368 | ||
369 | word = wordinfo2[i]; | |
370 | nbit = bitinfo2[i]; | |
371 | last = first+nbit-1; | |
372 | if(first < 30 && last < 30){ | |
373 | AliBitPacking::PackWord(word,baseWord,first,last); //3 bit code =1 -> next 18 bits for EOR | |
374 | first = last+1; | |
375 | } | |
376 | ||
377 | else{ | |
378 | if(first<=29){ | |
379 | UInt_t w = AliBitPacking::UnpackWord(word,0,29-first); | |
380 | AliBitPacking::PackWord(w,baseWord,first,29); | |
381 | Int_t lb = 29-first+1; | |
382 | diff = nbit-lb; | |
383 | word2 = AliBitPacking::UnpackWord(word,lb,lb+diff-1); | |
384 | flag = kTRUE; | |
385 | if(anode<256) word = 2; | |
386 | else word = 3; | |
387 | AliBitPacking::PackWord(word,baseWord,30,31); | |
388 | fIndex++; | |
389 | buf[fIndex]=baseWord; | |
390 | first=0; | |
391 | last = 0; | |
392 | baseWord=0; | |
393 | if(anode==255){ | |
394 | flag=kFALSE; | |
395 | word2=0; | |
396 | } | |
397 | } | |
398 | else{ | |
399 | word2 = word; | |
400 | diff = nbit; | |
401 | flag = kTRUE; | |
402 | if(anode<256) word = 2; | |
403 | else word = 3; | |
404 | AliBitPacking::PackWord(word,baseWord,30,31); | |
405 | fIndex++; | |
406 | buf[fIndex]=baseWord; | |
407 | first=0; | |
408 | last=0; | |
409 | baseWord=0; | |
410 | if(anode==255){ | |
411 | flag=kFALSE; | |
412 | word2=0; | |
413 | } | |
414 | } | |
415 | } | |
416 | } | |
417 | } //end for | |
418 | ||
419 | } | |
9f992f70 | 420 | if(fVerbose==2) |
421 | ftxt.close(); | |
2e9f335b | 422 | return; |
423 | }//end GetDigitsSDD | |
424 | ||
425 | //////////////////////////////////////////////////////////////////////////////////////// | |
426 | //PIXEL | |
427 | // | |
428 | ||
ad7f2bfa | 429 | void AliITSDDLRawData::GetDigitsSPD(TClonesArray *ITSdigits,Int_t mod,Int_t ddl, UInt_t *buf, AliITSFOSignalsSPD* foSignals){ |
9f992f70 | 430 | //This method packs the SPD digits in a proper 32 structure |
431 | //Since data is zero suppressed,the coordinates for the chip having zero digits | |
432 | //doesn't get listed in the galice.root file. However the SPD format requires | |
433 | //the empty chip to be written with chip header and chip trailer. | |
3f917533 | 434 | |
435 | Int_t chipLow = AliITSRawStreamSPD::GetOnlineChipFromOffline(mod,0); | |
436 | Int_t chipHigh = AliITSRawStreamSPD::GetOnlineChipFromOffline(mod,159); | |
a1317fda | 437 | |
3f917533 | 438 | if (chipLow>chipHigh) {chipLow -= 4; chipHigh += 4;} |
ad7f2bfa | 439 | UInt_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(mod); |
3f917533 | 440 | UInt_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(mod); |
441 | ||
442 | // create int map to later hold all digits sorted | |
443 | AliITSIntMap* digMap = new AliITSIntMap(); | |
444 | ||
0b3c7dfc | 445 | UInt_t baseWord=0; |
ad7f2bfa | 446 | |
2e9f335b | 447 | Int_t ndigits = ITSdigits->GetEntries(); //number of digits in the current module |
448 | //cout<<" Number of digits in the current module:"<<ndigits<<" module:"<<mod<<endl; | |
3f917533 | 449 | |
ad7f2bfa | 450 | // _______________________________________________________________________ |
451 | // Preprocess the digits - sort them in integer map (Henrik Tydesjo) | |
452 | // Needed to have exact same order as in real raw data | |
2e9f335b | 453 | AliITSdigit *digs; |
ad7f2bfa | 454 | ofstream ftxt; |
455 | if (ndigits) { | |
2e9f335b | 456 | //loop over digits |
ad7f2bfa | 457 | if (fVerbose==2) ftxt.open("SPDdigits.txt",ios::app); |
458 | for (Int_t digit=0; digit<ndigits; digit++) { | |
459 | digs = (AliITSdigit*) ITSdigits->UncheckedAt(digit); | |
2e9f335b | 460 | /*--------------------------------------------------------------------------- |
461 | * Each module contains 5 read out chips of 256 rows and 32 columns. | |
3f917533 | 462 | * So, the cell number in Z direction varies from 0 to 159. |
2e9f335b | 463 | * ---------------------------------------------------------------------*/ |
3f917533 | 464 | Int_t iz=digs->GetCoord1(); // Cell number in Z direction |
465 | Int_t ix=digs->GetCoord2(); // Cell number in X direction | |
466 | ||
ad7f2bfa | 467 | if(fVerbose==2) ftxt<<"DDL:"<<ddl<<" Mod:"<<mod<<" Row:"<<ix<<" Col:"<<iz<<endl; |
468 | UInt_t dummyDDL, dummyHS, chip, col, row; | |
3f917533 | 469 | AliITSRawStreamSPD::OfflineToOnline(mod,iz,ix,dummyDDL,dummyHS,chip,col,row); |
470 | ||
471 | // insert digit into map... | |
472 | // (reverse order of cols and rows as in real raw data) | |
a1317fda | 473 | digMap->Insert(chip*256*32+(31-col)*256+(255-row),row); |
3f917533 | 474 | } |
475 | } | |
476 | ||
ad7f2bfa | 477 | // _______________________________________________________________________ |
478 | // Procedure for writing raw data (Henrik Tydesjo) | |
479 | // Reimplemented because of unreadability (5 Mar 2009) | |
480 | // Now also with fast-or signals | |
481 | Int_t previousChip = chipLow-1; | |
482 | Int_t chip = chipLow-1; | |
483 | UInt_t chipHitCount = 0; | |
484 | ||
485 | ||
3f917533 | 486 | UInt_t nrHits = digMap->GetNrEntries(); |
ad7f2bfa | 487 | for (UInt_t nHit=0; nHit<nrHits; nHit++) { |
488 | ||
489 | Int_t key = digMap->GetKeyIndex(nHit); | |
490 | chip = key/(256*32); | |
491 | Int_t col = 31 - (key%(256*32))/256; | |
492 | Int_t row = digMap->GetValIndex(nHit); | |
493 | ||
494 | // add trailer for previous chip (if there was one...) | |
495 | if (chip>previousChip && previousChip>chipLow-1) { | |
496 | WriteChipTrailer(buf, chipHitCount, foSignals->GetSignal(eq,hs,previousChip), baseWord); | |
497 | } | |
498 | ||
499 | // add headers/trailers for chips without hits (if any) | |
500 | for (Int_t ch=previousChip+1; ch<chip; ch++) { | |
501 | WriteChipHeader(ch, hs, baseWord); | |
502 | WriteChipTrailer(buf, 0, foSignals->GetSignal(eq,hs,ch), baseWord); | |
503 | } | |
504 | ||
505 | // if new chip, add header | |
506 | if (chip>previousChip) { | |
507 | WriteChipHeader(chip, hs, baseWord); | |
508 | chipHitCount = 0; | |
509 | previousChip = chip; | |
510 | } | |
511 | ||
512 | chipHitCount++; | |
513 | ||
514 | // add pixel hit | |
515 | WriteHit(buf,row,col,baseWord); | |
516 | ||
517 | } | |
518 | ||
519 | // add trailer for last chip (if there was one...) | |
520 | if (chip>chipLow-1) { | |
521 | WriteChipTrailer(buf, chipHitCount, foSignals->GetSignal(eq,hs,chip), baseWord); | |
522 | } | |
523 | ||
524 | // add REMAINING headers/trailers for chips without hits (if any) | |
525 | for (Int_t ch=chip+1; ch<=chipHigh; ch++) { | |
526 | WriteChipHeader(ch, hs, baseWord); | |
527 | WriteChipTrailer(buf, 0, foSignals->GetSignal(eq,hs,ch), baseWord); | |
528 | } | |
529 | // _______________________________________________________________________ | |
530 | ||
3f917533 | 531 | |
532 | delete digMap; | |
533 | ||
9f992f70 | 534 | if(fVerbose==2) |
535 | ftxt.close(); | |
2e9f335b | 536 | return; |
537 | }//end GetDigitsSPD | |
538 | ||
2e9f335b | 539 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
540 | ||
ad7f2bfa | 541 | Int_t AliITSDDLRawData::RawDataSPD(TBranch* branch, AliITSFOSignalsSPD* foSignals){ |
a79660fb | 542 | //This method creates the Raw data files for SPD detectors |
a79660fb | 543 | const Int_t kSize=21000; //256*32*5=40960 max number of digits per module |
0b3c7dfc | 544 | UInt_t buf[kSize]; //One buffer cell can contain 2 digits |
2e9f335b | 545 | fIndex=-1; |
2e9f335b | 546 | |
0421c3d1 | 547 | TClonesArray*& digits = * (TClonesArray**) branch->GetAddress(); |
2c4e6a6a | 548 | TString fileName; |
08f92f14 | 549 | AliFstream* outfile; // logical name of the output file |
f7ee745b | 550 | AliRawDataHeaderSim header; |
0421c3d1 | 551 | |
552 | //loop over DDLs | |
8f02666b | 553 | for(Int_t ddl=0;ddl<AliDAQ::NumberOfDdls("ITSSPD");ddl++){ |
2c4e6a6a | 554 | fileName.Form("%s",AliDAQ::DdlFileName("ITSSPD",ddl)); //The name of the output file. |
555 | outfile = new AliFstream(fileName.Data()); | |
0421c3d1 | 556 | //write Dummy DATA HEADER |
08f92f14 | 557 | UInt_t dataHeaderPosition=outfile->Tellp(); |
558 | outfile->WriteBuffer((char*)(&header),sizeof(header)); | |
2e9f335b | 559 | //Loops over Modules of a particular DDL |
0421c3d1 | 560 | for (Int_t mod=0; mod<AliITSRawStreamSPD::kModulesPerDDL; mod++){ |
8f02666b | 561 | Int_t moduleNumber = AliITSRawStreamSPD::GetModuleNumber(ddl, mod); |
0421c3d1 | 562 | digits->Clear(); |
563 | branch->GetEvent(moduleNumber); | |
2e9f335b | 564 | //For each Module, buf contains the array of data words in Binary format |
565 | //fIndex gives the number of 32 bits words in the buffer for each module | |
ad7f2bfa | 566 | GetDigitsSPD(digits, moduleNumber, ddl, buf, foSignals); |
08f92f14 | 567 | outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t))); |
2e9f335b | 568 | for(Int_t i=0;i<(fIndex+1);i++){ |
569 | buf[i]=0; | |
570 | }//end for | |
571 | fIndex=-1; | |
572 | }//end for | |
573 | ||
0421c3d1 | 574 | //Write REAL DATA HEADER |
08f92f14 | 575 | UInt_t currentFilePosition=outfile->Tellp(); |
576 | outfile->Seekp(dataHeaderPosition); | |
0421c3d1 | 577 | header.fSize=currentFilePosition-dataHeaderPosition; |
08f92f14 | 578 | outfile->WriteBuffer((char*)(&header),sizeof(header)); |
579 | delete outfile; | |
2e9f335b | 580 | }//end for |
0421c3d1 | 581 | |
2e9f335b | 582 | return 0; |
583 | } | |
584 | ||
585 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
586 | ||
0421c3d1 | 587 | Int_t AliITSDDLRawData::RawDataSSD(TBranch* branch){ |
a97b3678 | 588 | |
532a132e | 589 | //This method creates the Raw data files for SSD detectors |
a79660fb | 590 | const Int_t kSize=1536;//768*2 Number of stripe * number of sides(N and P) |
0b3c7dfc | 591 | UInt_t buf[kSize]; |
2e9f335b | 592 | fIndex=-1; |
0421c3d1 | 593 | |
594 | TClonesArray*& digits = * (TClonesArray**) branch->GetAddress(); | |
2c4e6a6a | 595 | TString fileName; |
08f92f14 | 596 | AliFstream* outfile; // logical name of the output file |
f7ee745b | 597 | AliRawDataHeaderSim header; |
2e9f335b | 598 | |
0421c3d1 | 599 | //loop over DDLs |
362c9d61 | 600 | for(Int_t i=0;i<AliDAQ::NumberOfDdls("ITSSSD");i++){ |
2c4e6a6a | 601 | fileName.Form("%s",AliDAQ::DdlFileName("ITSSSD",i)); //The name of the output file. |
602 | outfile = new AliFstream(fileName.Data()); | |
0421c3d1 | 603 | //write Dummy DATA HEADER |
08f92f14 | 604 | UInt_t dataHeaderPosition=outfile->Tellp(); |
605 | outfile->WriteBuffer((char*)(&header),sizeof(header)); | |
2e9f335b | 606 | |
607 | //Loops over Modules of a particular DDL | |
0421c3d1 | 608 | for (Int_t mod=0; mod<AliITSRawStreamSSD::kModulesPerDDL; mod++){ |
609 | Int_t moduleNumber = AliITSRawStreamSSD::GetModuleNumber(i, mod); | |
610 | if(moduleNumber!=-1){ | |
611 | digits->Clear(); | |
612 | branch->GetEvent(moduleNumber); | |
2e9f335b | 613 | //For each Module, buf contains the array of data words in Binary format |
614 | //fIndex gives the number of 32 bits words in the buffer for each module | |
0421c3d1 | 615 | GetDigitsSSD(digits,mod,moduleNumber,i,buf); |
08f92f14 | 616 | outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t))); |
2e9f335b | 617 | fIndex=-1; |
618 | }//end if | |
619 | }//end for | |
0421c3d1 | 620 | |
621 | //Write REAL DATA HEADER | |
08f92f14 | 622 | UInt_t currentFilePosition=outfile->Tellp(); |
623 | outfile->Seekp(dataHeaderPosition); | |
0421c3d1 | 624 | header.fSize=currentFilePosition-dataHeaderPosition; |
625 | header.SetAttribute(0); // valid data | |
08f92f14 | 626 | outfile->WriteBuffer((char*)(&header),sizeof(header)); |
627 | delete outfile; | |
2e9f335b | 628 | }//end for |
0421c3d1 | 629 | |
2e9f335b | 630 | return 0; |
631 | } | |
632 | ||
633 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
634 | ||
979b5a5f | 635 | Int_t AliITSDDLRawData::RawDataSDD(TBranch* branch, AliITSDDLModuleMapSDD* ddlsdd){ |
a79660fb | 636 | //This method creates the Raw data files for SDD detectors |
a79660fb | 637 | const Int_t kSize=131072; //256*512 |
0b3c7dfc | 638 | UInt_t buf[kSize]; |
2e9f335b | 639 | fIndex=-1; |
2e9f335b | 640 | |
0421c3d1 | 641 | TClonesArray*& digits = * (TClonesArray**) branch->GetAddress(); |
2c4e6a6a | 642 | TString fileName; |
08f92f14 | 643 | AliFstream* outfile; // logical name of the output file |
f7ee745b | 644 | AliRawDataHeaderSim header; |
d9ed1779 | 645 | |
646 | if(fSDDRawFormat!=0){ | |
647 | for(Int_t ibit=0; ibit<8; ibit++) header.SetAttribute(ibit); | |
648 | }else{ | |
649 | for(Int_t ibit=0; ibit<5; ibit++) header.SetAttribute(ibit); | |
650 | for(Int_t ibit=5; ibit<8; ibit++) header.ResetAttribute(ibit); | |
651 | } | |
fa358bbd | 652 | UInt_t skippedword=0; |
653 | UInt_t carlosFooterWord=0; | |
654 | UInt_t fifoFooterWord=0; | |
655 | UInt_t jitterWord=0; | |
5dfa68c5 | 656 | Bool_t retcode; |
657 | retcode = AliBitPacking::PackWord(0x3FFFFFFF,carlosFooterWord,0,31); | |
658 | retcode = AliBitPacking::PackWord(0x3F1F1F1F,fifoFooterWord,0,31); | |
d9ed1779 | 659 | if(fSDDRawFormat!=0) retcode = AliBitPacking::PackWord(0x7F000000,jitterWord,0,31); |
de075dae | 660 | else retcode = AliBitPacking::PackWord(0x80000000,jitterWord,0,31); |
661 | ||
0421c3d1 | 662 | //loop over DDLs |
362c9d61 | 663 | for(Int_t i=0;i<AliDAQ::NumberOfDdls("ITSSDD");i++){ |
2c4e6a6a | 664 | fileName.Form("%s",AliDAQ::DdlFileName("ITSSDD",i)); //The name of the output file. |
665 | outfile = new AliFstream(fileName.Data()); | |
0421c3d1 | 666 | //write Dummy DATA HEADER |
08f92f14 | 667 | UInt_t dataHeaderPosition=outfile->Tellp(); |
668 | outfile->WriteBuffer((char*)(&header),sizeof(header)); | |
0421c3d1 | 669 | |
5dfa68c5 | 670 | |
8345a1cf | 671 | //first 1 "dummy" word to be skipped |
d9ed1779 | 672 | if(fSDDRawFormat!=0){ |
ad1b4ad1 | 673 | retcode = AliBitPacking::PackWord(0xFFFFFFFF,skippedword,0,31); |
674 | outfile->WriteBuffer((char*)(&skippedword),sizeof(skippedword)); | |
675 | } | |
8345a1cf | 676 | |
2e9f335b | 677 | //Loops over Modules of a particular DDL |
0421c3d1 | 678 | for (Int_t mod=0; mod<AliITSRawStreamSDD::kModulesPerDDL; mod++){ |
979b5a5f | 679 | Int_t moduleNumber = ddlsdd->GetModuleNumber(i, mod); |
0421c3d1 | 680 | if(moduleNumber!=-1){ |
681 | digits->Clear(); | |
682 | branch->GetEvent(moduleNumber); | |
a97b3678 | 683 | |
2e9f335b | 684 | //For each Module, buf contains the array of data words in Binary format |
685 | //fIndex gives the number of 32 bits words in the buffer for each module | |
a79660fb | 686 | // cout<<"MODULE NUMBER:"<<mapSDD[i][mod]<<endl; |
d9ed1779 | 687 | if(fSDDRawFormat==0){ |
ad1b4ad1 | 688 | GetDigitsSDDCompressed(digits,mod,buf); |
689 | outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t))); | |
690 | }else{ | |
691 | GetDigitsSDD(digits,mod,moduleNumber,i,buf); | |
692 | outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t))); | |
693 | for(Int_t iw=0;iw<3;iw++) outfile->WriteBuffer((char*)(&carlosFooterWord),sizeof(carlosFooterWord)); | |
694 | } | |
2e9f335b | 695 | fIndex=-1; |
696 | }//end if | |
697 | }//end for | |
5dfa68c5 | 698 | // 12 words with FIFO footers (=4 FIFO x 3 3F1F1F1F words per DDL) |
d9ed1779 | 699 | if(fSDDRawFormat!=0){ |
ad1b4ad1 | 700 | for(Int_t iw=0;iw<12;iw++) outfile->WriteBuffer((char*)(&fifoFooterWord),sizeof(fifoFooterWord)); |
ad1b4ad1 | 701 | } |
de075dae | 702 | outfile->WriteBuffer((char*)(&jitterWord),sizeof(jitterWord)); |
0421c3d1 | 703 | //Write REAL DATA HEADER |
08f92f14 | 704 | UInt_t currentFilePosition=outfile->Tellp(); |
705 | outfile->Seekp(dataHeaderPosition); | |
0421c3d1 | 706 | header.fSize=currentFilePosition-dataHeaderPosition; |
707 | header.SetAttribute(0); // valid data | |
08f92f14 | 708 | outfile->WriteBuffer((char*)(&header),sizeof(header)); |
709 | delete outfile; | |
2e9f335b | 710 | }//end for |
0421c3d1 | 711 | |
2e9f335b | 712 | return 0; |
713 | } | |
714 | ||
715 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
716 | ||
a643f6be | 717 | void AliITSDDLRawData::WriteChipHeader(Int_t ChipAddr,Int_t halfStave,UInt_t &BaseWord){ |
a79660fb | 718 | //This method writes a chip header |
a643f6be | 719 | //cout<<"Chip: "<<ChipAddr<<" Half Stave module:"<<halfStave<<endl; |
2e9f335b | 720 | BaseWord=0; |
a643f6be | 721 | AliBitPacking::PackWord(ChipAddr,BaseWord,16,19); |
722 | // At the moment the event count is always 0 (bits 20-26) | |
723 | AliBitPacking::PackWord(0,BaseWord,20,26); | |
724 | AliBitPacking::PackWord(halfStave,BaseWord,27,29); | |
725 | AliBitPacking::PackWord(0x1,BaseWord,30,31); | |
2e9f335b | 726 | return; |
727 | }//end WriteChipHeader | |
728 | ||
729 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
730 | ||
ad7f2bfa | 731 | void AliITSDDLRawData::WriteChipTrailer(UInt_t *buf, Int_t ChipHitCount, Bool_t foBit, UInt_t &BaseWord){ |
a79660fb | 732 | //This method writes a chip trailer |
2e9f335b | 733 | //pixel fill word |
734 | if((ChipHitCount%2)!=0){ | |
a643f6be | 735 | AliBitPacking::PackWord(0xC000,BaseWord,16,31); |
2e9f335b | 736 | } |
ad7f2bfa | 737 | AliBitPacking::PackWord(ChipHitCount,BaseWord,0,11); |
738 | AliBitPacking::PackWord(0x0,BaseWord,12,12); | |
739 | AliBitPacking::PackWord(foBit,BaseWord,13,13); | |
a643f6be | 740 | AliBitPacking::PackWord(0x0,BaseWord,14,15); |
2e9f335b | 741 | fIndex++; |
742 | buf[fIndex]=BaseWord; | |
743 | BaseWord=0; | |
744 | return; | |
745 | }//end WriteChipTrailer | |
746 | ||
747 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
748 | ||
0b3c7dfc | 749 | void AliITSDDLRawData::WriteHit(UInt_t *buf,Int_t RowAddr,Int_t HitAddr,UInt_t &BaseWord){ |
a79660fb | 750 | //This method writs an hit |
2e9f335b | 751 | if(!BaseWord){ |
113c12f1 | 752 | AliBitPacking::PackWord(HitAddr,BaseWord,16,20); |
753 | AliBitPacking::PackWord(RowAddr,BaseWord,21,28); | |
754 | AliBitPacking::PackWord(2,BaseWord,30,31); | |
a643f6be | 755 | }//end if |
756 | else{ | |
757 | AliBitPacking::PackWord(HitAddr,BaseWord,0,4); | |
758 | AliBitPacking::PackWord(RowAddr,BaseWord,5,12); | |
759 | AliBitPacking::PackWord(2,BaseWord,14,15); | |
2e9f335b | 760 | fIndex++; |
761 | buf[fIndex]=BaseWord; | |
762 | BaseWord=0; | |
763 | }//end else | |
764 | return; | |
765 | }//end WriteHit | |
f957a032 | 766 |